Submission #85261


Source Code Expand

#include<iostream>
#include<fstream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<climits>
#include<ctime>
#include<sstream>
#define mp       make_pair
#define pb       push_back
#define st       first
#define nd       second
#define wait     system("pause");
#define lint     long long int
#define KARE(a)	 ( (a)*(a) )
#define MAX(a,b) ( (a)>(b) ? (a) : (b) )
#define MIN(a,b) ( (a)<(b) ? (a) : (b) )
#define INF		   INT_MAX
#define ii       pair<int,int>
#define EPS      (1e-7)
#define ZERO(k)  ( abs(k)<(EPS) )
#define mxn       20005
using namespace std;

int N;
ii dp[2][2005],K[mxn];

void read(){

  scanf( "%d" , &N );

  for( int i=1 ; i<=N ; i++ )
      scanf( "%d %d" , &K[i].st , &K[i].nd ),
      K[i].st += 1000,
      K[i].nd += 1000;
}

void fill(){

  K[0].st = K[0].nd += 1000;

  for( int i=0 ; i<2001 ; i++ )
    dp[0][i].st = dp[0][i].nd = abs( 1000 - i );
}

void solve(){
  int i,a,b,j,res=INF;

  fill();

  for( i=1 ; i<=N ; i++ ){
    a = i&1;
    b = !a;
    for( j=0 ; j<2001 ; j++ ){

      dp[a][j].st = MIN( dp[b][j].st + abs( K[i-1].st - K[i].st ) , dp[b][ K[i].st ].nd + abs( K[i-1].nd - j ) );
      dp[a][j].nd = MIN( dp[b][j].nd + abs( K[i-1].nd - K[i].nd ) , dp[b][ K[i].nd ].st + abs( K[i-1].st - j ) );

    }
  }

  a = N&1;

  for( i=0 ; i<2001 ; i++ )
    res = MIN( res , MIN( dp[a][i].st , dp[a][i].nd ) );
  cout<<res<<endl;

}

int main(){
	read();
	solve();
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘void read()’:
./Main.cpp:39:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:44:22: 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 23 ms 1064 KB
02 AC 23 ms 1012 KB
03 AC 25 ms 1036 KB
04 AC 23 ms 1032 KB
05 AC 23 ms 1016 KB
06 AC 23 ms 1032 KB
07 AC 24 ms 1152 KB
08 AC 24 ms 1040 KB
09 AC 24 ms 1048 KB
10 AC 25 ms 1036 KB
11 AC 24 ms 1040 KB
12 AC 25 ms 1088 KB
13 AC 25 ms 1036 KB
14 AC 24 ms 1036 KB
15 AC 41 ms 1120 KB
16 AC 33 ms 1040 KB
17 AC 118 ms 1008 KB
18 AC 181 ms 1148 KB
19 AC 259 ms 972 KB
20 AC 71 ms 968 KB