Submission #181498


Source Code Expand

#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;

int dpx[2005][2],dpy[2005][2];
int n;
int a[20005],b[20005];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
	}
	for(int i=0;i<2005;i++)
	{
		dpx[i][0] = dpy[i][0] = 1e9;
	}
	dpx[1000][0] = dpy[1000][0] = 0;
	int cur = 0,nxt = 1;
	for(int q=1;q<=n;q++)
	{
		for(int i=0;i<2005;i++) dpx[i][nxt] = dpy[i][nxt] = 1e9;
		for(int i=0;i<2005;i++)
		{
			//(i-1000,b[q-1])
			dpx[i][nxt] = min(dpx[i][nxt],dpx[i][cur]+abs(b[q-1]-b[q]));
			dpy[b[q-1]+1000][nxt] = min(dpy[b[q-1]+1000][nxt],dpx[i][cur]+abs(i-1000-a[q]));
			//(a[q-1],i-1000)
			dpy[i][nxt] = min(dpy[i][nxt],dpy[i][cur]+abs(a[q-1]-a[q]));
			dpx[a[q-1]+1000][nxt] = min(dpx[a[q-1]+1000][nxt],dpy[i][cur]+abs(i-1000-b[q]));
		}
		swap(cur,nxt);
	}
	int res = 1e9;
	for(int i=0;i<2005;i++) res = min(res,min(dpx[i][cur],dpy[i][cur]));
	printf("%d\n",res);
}

Submission Info

Submission Time
Task 1 - Hermes
User IH19980412
Language C++ (G++ 4.6.4)
Score 100
Code Size 975 Byte
Status AC
Exec Time 331 ms
Memory 868 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:16:29: 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 20 ms 800 KB
02 AC 21 ms 668 KB
03 AC 21 ms 676 KB
04 AC 22 ms 796 KB
05 AC 22 ms 684 KB
06 AC 20 ms 676 KB
07 AC 20 ms 804 KB
08 AC 20 ms 680 KB
09 AC 21 ms 796 KB
10 AC 21 ms 668 KB
11 AC 22 ms 756 KB
12 AC 24 ms 800 KB
13 AC 25 ms 672 KB
14 AC 23 ms 668 KB
15 AC 26 ms 804 KB
16 AC 37 ms 760 KB
17 AC 174 ms 808 KB
18 AC 254 ms 808 KB
19 AC 331 ms 868 KB
20 AC 101 ms 680 KB