Submission #163481


Source Code Expand

#include<stdio.h>
#include<algorithm>
using namespace std;
int x[30000];
int y[30000];
int segtree[4][4096];
void update(int a,int b,int c){
	b+=2048;
	while(b){
		segtree[a][b]=min(segtree[a][b],c);
		b/=2;
	}
}
int query(int t,int a,int b,int c,int d,int e){
	if(d<a||b<c)return 1010101010;
	if(c<=a&&b<=d)return segtree[t][e];
	return min(query(t,a,(a+b)/2,c,d,e*2),query(t,(a+b)/2+1,b,c,d,e*2+1));
}
int ABS(int a){return max(a,-a);}
int AD=1000;
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d%d",x+i+1,y+i+1);
	for(int i=0;i<4;i++)
		for(int j=0;j<4096;j++)
			segtree[i][j]=1010101010;
	update(0,AD,0);
	update(1,AD,0);
	update(2,AD,0);
	update(3,AD,0);
	int yoko=0;
	int tate=0;
	for(int i=0;i<a;i++){
		int yval=min(query(0,0,2047,0,y[i+1]+AD,1)+y[i+1],query(1,0,2047,y[i+1]+AD,2047,1)-y[i+1])+yoko;
		int tval=min(query(2,0,2047,0,x[i+1]+AD,1)+x[i+1],query(3,0,2047,x[i+1]+AD,2047,1)-x[i+1])+tate;
		yoko+=ABS(x[i+1]-x[i]);
		tate+=ABS(y[i+1]-y[i]);
		update(0,y[i]+AD,tval-yoko-y[i]);
		update(1,y[i]+AD,tval-yoko+y[i]);
		update(2,x[i]+AD,yval-tate-x[i]);
		update(3,x[i]+AD,yval-tate+x[i]);
	}
	int ret=1010101010;
	for(int i=0;i<2048;i++){
		ret=min(ret,query(0,0,2047,i,i,1)+yoko+i-AD);
		ret=min(ret,query(2,0,2047,i,i,1)+tate+i-AD);
	}
	printf("%d\n",ret);
}

Submission Info

Submission Time
Task 1 - Hermes
User tozangezan
Language C++ (G++ 4.6.4)
Score 100
Code Size 1344 Byte
Status AC
Exec Time 47 ms
Memory 936 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:23:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:24:47: 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 24 ms 796 KB
02 AC 22 ms 800 KB
03 AC 22 ms 800 KB
04 AC 29 ms 792 KB
05 AC 21 ms 796 KB
06 AC 21 ms 792 KB
07 AC 23 ms 788 KB
08 AC 23 ms 796 KB
09 AC 22 ms 800 KB
10 AC 21 ms 796 KB
11 AC 22 ms 792 KB
12 AC 20 ms 796 KB
13 AC 24 ms 800 KB
14 AC 21 ms 692 KB
15 AC 20 ms 792 KB
16 AC 23 ms 792 KB
17 AC 35 ms 920 KB
18 AC 40 ms 920 KB
19 AC 47 ms 936 KB
20 AC 28 ms 912 KB