QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508499 | #2615. Surround the Cat | ZhouShang# | WA | 3ms | 3896kb | C++14 | 3.3kb | 2024-08-07 16:33:52 | 2024-08-07 16:33:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector <pair<int,int>> sp;
map <pair<int,int>,int> id;
int dis[305],xx[305],yy[305],f[305];
vector <int> v[305];
int dx[6]={1,0,-1,-1,0,1},dy[6]={1,1,0,-1,-1,0};
void print(int x,int y){
printf("%d %d\n",x,y);
fflush(stdout);
}
int main() {
sp.push_back({8,0}),sp.push_back({9,2}),sp.push_back({9,3}),sp.push_back({8,4});
sp.push_back({9,6}),sp.push_back({9,7});
sp.push_back({8,8}),sp.push_back({7,9}),sp.push_back({6,9}),sp.push_back({4,8});
sp.push_back({3,9}),sp.push_back({2,9});
sp.push_back({0,8}),sp.push_back({-2,7}),sp.push_back({-3,6}),sp.push_back({-4,4});
sp.push_back({-6,3}),sp.push_back({-7,2});
for(int i=0;i<18;i++) sp.push_back({-sp[i].first,-sp[i].second});
int cnt=0;
for(int i=9;i>=0;i--)
for(int j=i-9;j<=9;j++)
id[{i,j}]=++cnt,xx[cnt]=i,yy[cnt]=j;
for(int i=-1;i>=-9;i--)
for(int j=-9;j<=i+9;j++)
id[{i,j}]=++cnt,xx[cnt]=i,yy[cnt]=j;
for(int i=1;i<=cnt;i++){
for(int j=0;j<6;j++){
int tx=xx[i]+dx[j],ty=yy[i]+dy[j];
if(id.count({tx,ty})) v[i].push_back(id[{tx,ty}]);
}
}
int x=0,y=0;
while(1){
scanf("%d%d",&x,&y);
// cout<<"--->"<<x<<" "<<y<<endl;
vector <pair<int,int>> must;
for(int i=0;i<6;i++){
int tx=x+dx[i],ty=y+dy[i];
if(id.count({tx,ty})&&f[id[{tx,ty}]]==0){
if(abs(tx)==9||abs(ty)==9) must.push_back({tx,ty});
}
}
if(must.size()>1){
return 1;
}
if(must.size()==1){
print(must[0].first,must[0].second);
f[id[{must[0].first,must[0].second}]]=1;
}
else{
memset(dis,-1,sizeof(dis));
queue <int> q;
dis[id[{x,y}]]=0,q.push(id[{x,y}]);
while(!q.empty()){
int temp=q.front();
q.pop();
for(auto t:v[temp]) if(!f[t]&&dis[t]==-1)
dis[t]=dis[temp]+1,q.push(t);
}
int ch=-1,mn=INT_MAX;
for(auto temp:sp){
if(dis[id[{temp.first,temp.second}]]!=-1&&dis[id[{temp.first,temp.second}]]<mn)
mn=dis[id[{temp.first,temp.second}]],ch=id[{temp.first,temp.second}];
}
if(ch!=-1){
print(xx[ch],yy[ch]);
f[ch]=1;
}
else{
for(int i=1;i<=cnt;i++)
if(!f[i]&&(xx[i]!=x||yy[i]!=y)){
print(xx[i],yy[i]);
f[i]=1;
break;
}
}
}
int fl=0;
for(int i=0;i<6;i++){
int tx=x+dx[i],ty=y+dy[i];
if(id.count({tx,ty})){
if(f[id[{tx,ty}]]==0)
fl=1;
}
}
if(!fl){
// puts("WIN!!!");
break;
}
// else{
// for(int i=0;i<6;i++){
// int tx=x+dx[i],ty=y+dy[i];
// if(id.count({tx,ty})&&f[id[{tx,ty}]]==0){
// x=tx,y=ty;
//// break;
// }
// }
// }
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
0 0 1 1 1 2 2 3 3 4 4 5 4 6 5 7 4 7 3 7 4 7 3 7 4 7 3 7 4 7 5 7 6 7 7 7 6 7 5 7 6 7 5 7 4 7 3 7 2 7 3 7 4 7 3 7 2 7 1 7 2 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 7 6 7 5 7 6 7 5 7 6 7 7 7 6 7 5 7 4 7 3 7 4 7 3 7 2 7 1 7 2 7 3 7 4 7 5 7 6 7 7 6 7 5 7 6 7 5 7 4 7 5 7 4 7 5 7 4 7 5 7 6 7 5 7 4 7 3 7 4 7 5 7 4 7 ...
output:
8 0 8 4 4 8 8 8 7 9 6 9 3 9 9 7 2 9 0 8 9 6 -2 7 -3 6 -4 4 9 3 9 2 6 -3 7 -2 4 -4 -6 3 -7 2 -8 0 -8 -4 -9 -2 -9 -3 -9 -6 3 -6 -9 -7 2 -7 -8 -8 -4 -8 0 -8 -7 -9 -6 -9 -3 -9 -2 -9 9 0 9 1 9 4 9 5 9 8 9 9 8 -1 8 1 8 2 8 3 8 5 8 6 8 7 8 9 7 -1 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 6 -2 6 -1 6 0 6 1 6 2 6 ...
result:
ok There is no valid neighbouring location.
Test #2:
score: 0
Accepted
time: 3ms
memory: 3836kb
input:
0 0 -1 0 -2 0 -3 0 -4 0 -5 0 -6 -1 -7 -2 -7 -1 -7 0 -7 -1 -7 0 -6 1 -7 0 -7 -1 -7 0 -7 -1 -7 0 -7 -1 -7 0 -6 1 -7 0 -6 1 -7 0 -7 -1 -7 0 -6 1 -7 0 -6 1 -7 0 -6 1 -5 2 -6 1 -7 0 -6 1 -7 0 -7 -1 -7 0 -6 1 -7 0 -6 1 -7 0 -7 -1 -7 0 -6 1 -7 0 -6 1 -7 0 -7 -1 -7 0 -6 1 -7 0 -6 1 -7 0 -6 1 -7 0 -6 1 -7 0 ...
output:
8 0 -4 4 -8 0 -8 -4 -6 3 -7 2 -9 -2 -9 -3 -9 -6 -3 6 -9 -7 -2 7 0 8 -8 -8 -7 -9 2 9 -6 -9 3 9 -4 -8 4 8 6 9 -3 -9 7 9 -2 -9 0 -8 8 4 8 8 4 -4 9 2 9 3 9 6 9 7 2 -7 3 -6 6 -3 7 -2 9 0 9 1 9 4 9 5 9 8 9 9 8 -1 8 1 8 2 8 3 8 5 8 6 8 7 8 9 7 -1 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 6 -2 6 -1 6 0 6 1 6 2 6 ...
result:
ok There is no valid neighbouring location.
Test #3:
score: 0
Accepted
time: 2ms
memory: 3812kb
input:
0 0 1 0 2 0 3 0 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8 8 7 9 6 9 4 8 3 9 -6 -9 2 9 -7 -9 0 8 -4 4 -8 -4 -8 0 -2 7 -8 -8 -9 -2 -9 -3 -9 -6 -3 6 -9 -7 -6 3 -7 2 9 0 9 1 9 4 9 5 9 8 9 9 8 -1 8 1 8 2 8 3 8 5 8 6 8 7 8 9 7 -1 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 6 -2 6 -1 6 0 6 1 6 2 6 ...
result:
ok There is no valid neighbouring location.
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3816kb
input:
0 0 -1 -1 -2 -1 -3 -1 -4 -1 -5 -2 -6 -3 -7 -3 -7 -2 -7 -3 -7 -4 -7 -3 -7 -4 -7 -3 -7 -4 -7 -5 -7 -6 -7 -5 -7 -6 -7 -5 -7 -6 -7 -7 -7 -6 -7 -7 -6 -7 -7 -7 -6 -7 -5 -7 -4 -7 -5 -7 -4 -7 -3 -7 -4 -7 -3 -7 -4 -7 -5 -7 -4 -7 -3 -7 -4 -7 -3 -7 -2 -7 -3 -7 -2 -7 -1 -7 -2 -7 -1 -7 0 -7 -1 -7 -2 -7 -3 -7 -4 ...
output:
8 0 -8 -4 -4 4 -8 0 -9 -2 -9 -3 -9 -6 -9 -7 -7 2 -8 -8 -7 -9 -6 3 -6 -9 -4 -8 -3 -9 -2 -9 0 -8 -3 6 2 -7 3 -6 4 -4 6 -3 -2 7 7 -2 8 4 8 8 9 2 9 3 9 6 9 7 4 8 0 8 7 9 6 9 3 9 2 9 9 0 9 1 9 4 9 5 9 8 9 9 8 -1 8 1 8 2 8 3 8 5 8 6 8 7 8 9 7 -1 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 6 -2 6 -1 6 0 6 1 6 2 6 ...
result:
wrong answer Cat reaches the boundary -8 1