Submission #455888


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()
{
	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 95
Code Size 1662 Byte
Status TLE
Exec Time 1045 ms
Memory 1276 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:48:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:49: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 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 5 / 5 0 / 5 5 / 5
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
TLE × 1
AC × 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 AC 39 ms 1024 KB
02 AC 36 ms 1088 KB
03 AC 35 ms 1016 KB
04 AC 35 ms 1024 KB
05 AC 35 ms 1020 KB
06 AC 38 ms 1040 KB
07 AC 37 ms 1080 KB
08 AC 36 ms 1020 KB
09 AC 35 ms 1020 KB
10 AC 36 ms 1080 KB
11 AC 40 ms 1020 KB
12 AC 40 ms 1088 KB
13 AC 44 ms 1080 KB
14 AC 44 ms 1020 KB
15 AC 49 ms 1020 KB
16 AC 88 ms 1020 KB
17 AC 580 ms 1148 KB
18 AC 873 ms 1148 KB
19 TLE 1045 ms 1276 KB
20 AC 310 ms 1072 KB