Submission #76721


Source Code Expand

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000; 
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
int n;
pi p[20005];
int dp[2][2][2005];
inline void chmin(int& a,int b){
	if(a>b) a=b;
}

int main(){
	scanf("%d",&n);
	REP(i,n) scanf("%d%d",&p[i].fr,&p[i].sc);
	REP(i,2005) REP(j,2) dp[0][j][i]=INF;
	dp[0][0][1000]=abs(p[0].sc);
	dp[0][1][1000]=abs(p[0].fr);
	REP(i,n) p[i]=mp(p[i].fr+1000,p[i].sc+1000);
	int cur=0,nxt=1;
	REP(i,n-1){
		int dif1=abs(p[i+1].sc-p[i].sc),dif2=abs(p[i+1].fr-p[i].fr);
		REP(j,2005){
			dp[nxt][0][j]=dp[cur][0][j]+dif1;
			dp[nxt][1][j]=dp[cur][1][j]+dif2;
		}
		REP(j,2005){
			if(dp[cur][0][j]+abs(p[i+1].fr-j)<dp[nxt][1][p[i].sc])
				dp[nxt][1][p[i].sc]=dp[cur][0][j]+abs(p[i+1].fr-j);
		}
		REP(j,2005){
			if(dp[cur][1][j]+abs(p[i+1].sc-j)<dp[nxt][0][p[i].fr])
				dp[nxt][0][p[i].fr]=dp[cur][1][j]+abs(p[i+1].sc-j);
		}
		swap(cur,nxt);
	}
	int res=INF;
	REP(i,2005) chmin(res,min(dp[cur][0][i],dp[cur][1][i]));
	printf("%d\n",res);
	return 0;
}


Submission Info

Submission Time
Task 1 - Hermes
User hogloid
Language C++ (G++ 4.6.4)
Score 100
Code Size 1518 Byte
Status AC
Exec Time 275 ms
Memory 1152 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:28:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:29:42: 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 26 ms 1024 KB
02 AC 52 ms 1008 KB
03 AC 25 ms 1012 KB
04 AC 25 ms 1080 KB
05 AC 25 ms 1036 KB
06 AC 25 ms 1080 KB
07 AC 25 ms 1008 KB
08 AC 24 ms 1048 KB
09 AC 24 ms 1144 KB
10 AC 23 ms 1148 KB
11 AC 26 ms 1024 KB
12 AC 26 ms 1032 KB
13 AC 28 ms 1016 KB
14 AC 27 ms 1148 KB
15 AC 29 ms 1028 KB
16 AC 37 ms 1004 KB
17 AC 151 ms 1148 KB
18 AC 214 ms 1032 KB
19 AC 275 ms 1152 KB
20 AC 88 ms 1152 KB