Submission #163511


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#define SIZE 2005
#define MD 1002
#define INF 1000000000

using namespace std;

int dp[SIZE][2];

int main()
{
	int n;
	scanf("%d",&n);
	int nx=MD,ny=MD;
	for(int i=0;i<SIZE;i++)
	{
		dp[i][0]=dp[i][1]=abs(i-MD);
	}
	for(int i=0;i<n;i++)
	{
		int px,py;
		scanf("%d %d",&px,&py);
		px+=MD;py+=MD;
		int rx=INF,ry=INF;
		for(int j=0;j<SIZE;j++)
		{
			rx=min(rx,dp[j][0]+abs(px-j));//dp[x][0]
			ry=min(ry,dp[j][1]+abs(py-j));//dp[y][1]
			dp[j][0]+=abs(py-ny);
			dp[j][1]+=abs(px-nx);
		}
		dp[nx][0]=min(dp[nx][0],ry);
		dp[ny][1]=min(dp[ny][1],rx);
		nx=px,ny=py;
	}
	int ret=INF;
	for(int j=0;j<SIZE;j++)
	{
		ret=min(ret,dp[j][0]);
		ret=min(ret,dp[j][1]);
	}
	printf("%d\n",ret);
	return 0;
}

Submission Info

Submission Time
Task 1 - Hermes
User yutaka1999
Language C++ (G++ 4.6.4)
Score 100
Code Size 838 Byte
Status AC
Exec Time 198 ms
Memory 800 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:26:25: 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 5 / 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
AC × 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 19 ms 796 KB
02 AC 19 ms 792 KB
03 AC 21 ms 800 KB
04 AC 21 ms 720 KB
05 AC 21 ms 792 KB
06 AC 23 ms 672 KB
07 AC 20 ms 792 KB
08 AC 22 ms 672 KB
09 AC 19 ms 796 KB
10 AC 20 ms 800 KB
11 AC 19 ms 792 KB
12 AC 21 ms 792 KB
13 AC 19 ms 796 KB
14 AC 23 ms 796 KB
15 AC 22 ms 800 KB
16 AC 29 ms 796 KB
17 AC 110 ms 660 KB
18 AC 152 ms 796 KB
19 AC 198 ms 716 KB
20 AC 64 ms 720 KB