Submission #455887


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <bitset>
#include <math.h>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<int,pii> pip;
typedef pair<ll,ll> pll;
typedef pair<ll,pii> plp;
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,n) for(int i=a;i<n;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MAX(x,a) x=max(x,a)
#define MIN(x,a) x=min(x,a)

int N;
int X[20000],Y[20000];
int dp[2001][2];
int tmp[2001][2];

void dpset(int id,int x,int y,int s)
{
	if(x==X[id])MIN(dp[y][0],s);
	if(y==Y[id])MIN(dp[x][1],s);
}

int main()
{
	freopen("hermes.in","r",stdin);
	freopen("hermes.out","w",stdout);
	scanf("%d",&N);
	rep(i,N)scanf("%d%d",&X[i],&Y[i]),X[i]+=1000,Y[i]+=1000;
	rep(i,2001)dp[i][0]=dp[i][1]=tmp[i][0]=tmp[i][1]=1145141919;
	rep(i,2001)
	{
		dp[i][0]=abs(X[0]-1000)+abs(i-1000);
		dp[i][1]=abs(i-1000)+abs(Y[0]-1000);
	}
	repn(i,1,N)
	{
		rep(j,2001)tmp[j][0]=dp[j][0],tmp[j][1]=dp[j][1];
		rep(j,2001)dp[j][0]=dp[j][1]=1145141919;
		rep(j,2001)
		{
			int x=X[i-1],y=j;
			dpset(i,X[i],y,tmp[j][0]+abs(X[i]-x));
			dpset(i,x,Y[i],tmp[j][0]+abs(Y[i]-y));
			
			x=j,y=Y[i-1];
			dpset(i,X[i],y,tmp[j][1]+abs(x-X[i]));
			dpset(i,x,Y[i],tmp[j][1]+abs(y-Y[i]));
		}
	}
	int res=1145141919;
	rep(i,2001)rep(j,2)MIN(res,dp[i][j]);
	printf("%d\n",res);
}

Submission Info

Submission Time
Task 1 - Hermes
User namonakiacc
Language C++ (G++ 4.6.4)
Score 0
Code Size 1732 Byte
Status WA
Exec Time 40 ms
Memory 1136 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:48:32: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:49:34: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:50:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:51:57: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name Set01 Set02 Set03 Set04 Set05 Set06 Set07 Set08 Set09 Set10 Set11 Set12 Set13 Set14 Set15 Set16 Set17 Set18 Set19 Set20
Score / Max Score 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5 0 / 5
Status
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
Set Name Test Cases
Set01 01
Set02 02
Set03 03
Set04 04
Set05 05
Set06 06
Set07 07
Set08 08
Set09 09
Set10 10
Set11 11
Set12 12
Set13 13
Set14 14
Set15 15
Set16 16
Set17 17
Set18 18
Set19 19
Set20 20
Case Name Status Exec Time Memory
01 WA 40 ms 1020 KB
02 WA 32 ms 1024 KB
03 WA 33 ms 1080 KB
04 WA 33 ms 1020 KB
05 WA 33 ms 1024 KB
06 WA 32 ms 1024 KB
07 WA 32 ms 1024 KB
08 WA 32 ms 1028 KB
09 WA 33 ms 1024 KB
10 WA 31 ms 1020 KB
11 WA 32 ms 1020 KB
12 WA 31 ms 1136 KB
13 WA 33 ms 1076 KB
14 WA 32 ms 1020 KB
15 WA 32 ms 1028 KB
16 WA 32 ms 1024 KB
17 WA 33 ms 1024 KB
18 WA 32 ms 1088 KB
19 WA 33 ms 1076 KB
20 WA 33 ms 1076 KB