QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95967 | #5575. Knight's Tour Redux | aguo123 | WA | 2ms | 3396kb | C++14 | 1.6kb | 2023-04-12 19:02:28 | 2023-04-12 19:02:31 |
Judging History
answer
#include<iostream>
#include<string>
#include <cstring>
#include <vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL N=1e6+10,mod=998244353;
int n;
int m;
string s;
int a[1000010];
LL cnt1[200],cnt2[200];
bool col[N],row[N];
int num,vis;
vector<PII>ans;
int dx[]={1,3,3,1,-1,-3,-3,-1},dy[]={3,1,-1,-3,-3,-1,1,3};
void dfs(int x,int y){
if(vis)return;
if(x<1||x>n||y<1||y>n)return;
if(col[x]||row[y])return;
num++;
col[x]=row[y]=1;
ans.push_back({x,y});
if(num==n){
for(auto k:ans)
cout<<k.first<<' '<<k.second<<endl;
vis=1;
return ;
}
for(int i=0;i<8;i++)
dfs(x+dx[i],y+dy[i]);
col[x]=row[y]=0;
num--;
ans.pop_back();
}
int main()
{ //LL ans=0;
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
cin>>n;
if(n==1){
// puts("POSSIBLE");
cout<<"POSSIBLE"<<endl;
cout<<1<<' '<<1<<endl;
return 0;
}else if(n<5){cout<<"POSSIBLE"<<endl;;return 0;}
cout<<"POSSIBLE"<<endl;
int pos=0;
while(pos+18<n){
cout<<pos+1<<' '<<pos+3<<endl;
cout<<pos+4<<' '<<pos+2<<endl;
cout<<pos+7<<' '<<pos+1<<endl;
cout<<pos+6<<' '<<pos+4<<endl;
cout<<pos+3<<' '<<pos+5<<endl;
cout<<pos+2<<' '<<pos+8<<endl;
cout<<pos+5<<' '<<pos+7<<endl;
cout<<pos+8<<' '<<pos+6<<endl;
cout<<pos+9<<' '<<pos+9<<endl;
for(int i=1;i<=9;i++)col[pos+i]=row[pos+i]=1,num++;
pos+=9;
}
dfs(pos+1,pos+3);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3384kb
input:
1
output:
POSSIBLE 1 1
result:
ok answer = 1
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3396kb
input:
2
output:
POSSIBLE
result:
wrong output format Unexpected end of file - int32 expected