Submission #89590
Source Code Expand
#include <iostream>
#include <climits>
#include <cstdio>
#define ABS(aa) ((aa) > 0 ? (aa) : -(aa))
#define MIN(aa,bb) ((aa) < (bb) ? (aa) : (bb))
#define MAXN 20005
#define INF INT_MAX
using namespace std;
int N;
int X[MAXN];
int Y[MAXN];
int DPX[2][2005];
int DPY[2][2005];
void Read()
{
int i;
scanf("%d",&N);
X[0]=Y[0]=1000;
for(i=1;i<=N;i++)
{
scanf("%d %d",&X[i],&Y[i]);
X[i] += 1000;
Y[i] += 1000;
}
}
void Solve()
{
int i,j,a,b;
for(i=0;i<=2000;i++)
DPX[0][i] = DPY[0][i] = ABS(i-1000);
a = 0 , b = 1;
for(i=1;i<=N;i++)
{
a = b;
b = 1 - a;
for(j=0;j<=2000;j++)
{
DPX[a][j] = MIN(DPX[b][j] + ABS(X[i] - X[i-1]) , DPY[b][X[i]] + ABS(j - Y[i-1]));
DPY[a][j] = MIN(DPX[b][Y[i]] + ABS(j - X[i-1]) , DPY[b][j] + ABS(Y[i] - Y[i-1]));
}
}
int res = INF;
for(i=0;i<=N;i++)
res = MIN(res , MIN(DPX[a][Y[i]] , DPY[a][X[i]]));
printf("%d\n",res);
}
int main()
{
Read();
Solve();
return 0;
}
Submission Info
Submission Time
2013-07-11 06:55:06+0900
Task
1 - Hermes
User
edogan
Language
C++ (GCC 4.4.7)
Score
100
Code Size
981 Byte
Status
AC
Exec Time
219 ms
Memory
912 KB
Compile Error
./Main.cpp: In function ‘void Read()’:
./Main.cpp:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_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
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
55 ms
732 KB
02
AC
23 ms
896 KB
03
AC
51 ms
736 KB
04
AC
22 ms
784 KB
05
AC
31 ms
740 KB
06
AC
22 ms
912 KB
07
AC
39 ms
796 KB
08
AC
22 ms
780 KB
09
AC
22 ms
784 KB
10
AC
23 ms
788 KB
11
AC
23 ms
784 KB
12
AC
24 ms
788 KB
13
AC
24 ms
784 KB
14
AC
27 ms
776 KB
15
AC
25 ms
768 KB
16
AC
32 ms
776 KB
17
AC
120 ms
888 KB
18
AC
169 ms
896 KB
19
AC
219 ms
888 KB
20
AC
70 ms
780 KB