Submission #32163
Source Code Expand
#include<queue>
#include<cstdio>
#include<cstdlib>
#include"porter.h"
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int L,S,sx,sy;
void init(int L,int S){
::L=L;
::S=S;
sx=sy=0;
}
void go_x(int &x,int &y,int &k,int d){
if(d==0) return;
if(d>0){ // 東
if(k==0){
if(x<L-1) x++;
else x=0, k=1;
}
else{
if(x<S-1) x++;
else if(S-L<=y) x=0, y-=S-L, k=0;
else x=0, y+=L;
}
}
else{ // 西
if(k==0){
if(x>0) x--;
else x=S-1, y+=S-L, k=1;
}
else{
if(x>0) x--;
else if(y<L) x=L-1, k=0;
else x=S-1, y-=L;
}
}
}
void go_y(int &x,int &y,int &k,int d){
if(d==0) return;
if(d>0){ // 北
if(k==0){
if(y<L-1) y++;
else y=0, x+=S-L, k=1;
}
else{
if(y<S-1) y++;
else if(L<=x) y=0, x-=L;
else y=0, k=0;
}
}
else{ // 南
if(k==0){
if(y>0) y--;
else y=S-1, k=1;
}
else{
if(y>0) y--;
else if(x<S-L) y=S-1, x+=L;
else y=L-1, x-=S-L, k=0;
}
}
}
int moveTo(int tx,int ty,int a,int b){
int dx[]={a,-b,-a,b};
int dy[]={b,a,-b,-a};
static int d[2][1000][1000]; // d[0]: 陸, d[1]: 海
rep(k,2) rep(i,S) rep(j,S) d[k][i][j]=INF;
d[0][sy][sx]=0;
queue< pair<pair<int,int>,int> > Q;
Q.push(make_pair(make_pair(sx,sy),0));
while(!Q.empty()){
int x=Q.front().first.first,y=Q.front().first.second,k=Q.front().second;
Q.pop();
rep(i,4){
int x2=x,y2=y,k2=k;
rep(j,abs(dx[i])) go_x(x2,y2,k2,dx[i]);
rep(j,abs(dy[i])) go_y(x2,y2,k2,dy[i]);
if(d[k2][y2][x2]==INF){
d[k2][y2][x2]=d[k][y][x]+1;
Q.push(make_pair(make_pair(x2,y2),k2));
}
}
}
sx=tx;
sy=ty;
return d[0][ty][tx]<INF?d[0][ty][tx]:-1;
}
Submission Info
Judge Result
Set Name |
Subtask1 |
Subtask2 |
Subtask3 |
Score / Max Score |
21 / 21 |
0 / 27 |
0 / 52 |
Status |
|
|
|
Set Name |
Test Cases |
Subtask1 |
subtask1/1, subtask1/2, subtask1/3, subtask1/4, subtask1/5, subtask1/6, subtask1/7, subtask1/8, subtask1/9 |
Subtask2 |
subtask1/1, subtask1/2, subtask1/3, subtask1/4, subtask1/5, subtask1/6, subtask1/7, subtask1/8, subtask1/9, subtask2/1, subtask2/2, subtask2/3, subtask2/4, subtask2/5, subtask2/6, subtask2/7, subtask2/8, subtask2/9 |
Subtask3 |
subtask1/1, subtask1/2, subtask1/3, subtask1/4, subtask1/5, subtask1/6, subtask1/7, subtask1/8, subtask1/9, subtask2/1, subtask2/2, subtask2/3, subtask2/4, subtask2/5, subtask2/6, subtask2/7, subtask2/8, subtask2/9, subtask3/1, subtask3/2, subtask3/3, subtask3/4, subtask3/5, subtask3/6, subtask3/7, subtask3/8, subtask3/9 |
Case Name |
Status |
Exec Time |
Memory |
subtask1/1 |
AC |
1254 ms |
8380 KB |
subtask1/2 |
AC |
1615 ms |
8668 KB |
subtask1/3 |
AC |
957 ms |
8172 KB |
subtask1/4 |
AC |
1234 ms |
8420 KB |
subtask1/5 |
AC |
1301 ms |
8304 KB |
subtask1/6 |
AC |
729 ms |
8316 KB |
subtask1/7 |
AC |
1283 ms |
8568 KB |
subtask1/8 |
AC |
1526 ms |
8180 KB |
subtask1/9 |
AC |
133 ms |
8428 KB |
subtask2/1 |
TLE |
2036 ms |
8160 KB |
subtask2/2 |
TLE |
2035 ms |
8560 KB |
subtask2/3 |
TLE |
2034 ms |
8688 KB |
subtask2/4 |
TLE |
2036 ms |
8828 KB |
subtask2/5 |
TLE |
2035 ms |
8576 KB |
subtask2/6 |
TLE |
2034 ms |
8548 KB |
subtask2/7 |
TLE |
2036 ms |
8676 KB |
subtask2/8 |
TLE |
2035 ms |
8676 KB |
subtask2/9 |
TLE |
2035 ms |
8580 KB |
subtask3/1 |
RE |
615 ms |
10208 KB |
subtask3/2 |
RE |
447 ms |
10208 KB |
subtask3/3 |
RE |
575 ms |
10212 KB |
subtask3/4 |
RE |
557 ms |
10208 KB |
subtask3/5 |
RE |
537 ms |
10212 KB |
subtask3/6 |
RE |
494 ms |
10212 KB |
subtask3/7 |
RE |
466 ms |
10212 KB |
subtask3/8 |
RE |
523 ms |
10212 KB |
subtask3/9 |
RE |
546 ms |
10212 KB |