QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#142121 | #5575. Knight's Tour Redux | Phantom Threshold (Jiachen Tang, Changdong Li, Weinuo Li)# | WA | 1ms | 3516kb | C++20 | 2.0kb | 2023-08-18 15:18:17 | 2023-08-18 15:18:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
int main()
{
ios_base::sync_with_stdio(false);
long long n;
cin>>n;
if(n==1)
{
cout<<"POSSIBLE\n1 1\n";
}
else if(n%2==1 or n<=4)
{
cout<<"IMPOSSIBLE\n";
}
else if(n<18)
{
cout<<"POSSIBLE\n";
vector<int> vr(n+5),vc(n+5);
int sx,sy;
vector<int> dx={1,3,3,1,-1,-3,-3,-1},dy={-3,-1,1,3,3,1,-1,-3};
vector<pair<int,int>> sol;
auto chk=[&](int x){return 1<=x and x<=n;};
function<void(int,int,int)> dfs=[&](int x,int y,int dep)
{
// cerr<<"dfs "<<x<<' '<<y<<' '<<dep<<endl;
sol.emplace_back(x,y);
if(dep==n)
{
for(int i=0;i<8;i++)
{
if(x+dx[i]==sx and y+dy[i]==sy)
{
for(auto [xx,yy]:sol)
cout<<xx<<' '<<yy<<endl;
exit(0);
}
}
sol.pop_back();
return;
}
vr[x]=1;vc[y]=1;
for(int i=0;i<8;i++)
{
if(chk(x+dx[i]) and chk(y+dy[i]) and vr[x+dx[i]]==0 and vc[y+dy[i]]==0)
{
dfs(x+dx[i],y+dy[i],dep+1);
}
}
vr[x]=0;vc[y]=0;
sol.pop_back();
};
for(int i=1;i<=n;i++)
{
sx=1;sy=i;
dfs(1,i,1);
}
}
else if(n%4==2)
{
cout<<"POSSIBLE\n";
cout<<1<<' '<<2<<endl;
cout<<4<<' '<<1<<endl;
cout<<5<<' '<<4<<endl;
for(int i=8;i<=n;i+=4)
{
cout<<i<<' '<<i-5<<"\n";
cout<<i+1<<' '<<i-2<<"\n";
}
cout<<n<<' '<<n-1<<endl;
cout<<n-3<<' '<<n<<endl;
cout<<n-4<<' '<<n-3<<endl;
for(int i=n-7;i>=1;i-=4)
{
cout<<i<<' '<<i+5<<"\n";
cout<<i-1<<' '<<i+2<<"\n";
}
}
else //n%4==0
{
cout<<"POSSIBLE\n";
cout<<1<<' '<<6<<endl;
cout<<2<<' '<<3<<endl;
cout<<5<<' '<<2<<endl;
for(int i=8;i<n;i+=4)
{
cout<<i<<' '<<i-7<<"\n";
cout<<i+1<<' '<<i-4<<"\n";
}
cout<<n<<' '<<n-7<<endl;
cout<<n-1<<' '<<n-4<<endl;
cout<<n-2<<' '<<n-1<<endl;
cout<<n-5<<' '<<n<<endl;
cout<<n-6<<' '<<n-3<<endl;
for(int i=n-9;i>=7;i-=4)
{
cout<<i<<' '<<i+7<<"\n";
cout<<i-1<<' '<<i+4<<"\n";
}
cout<<3<<' '<<10<<endl;
cout<<4<<' '<<7<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3488kb
input:
1
output:
POSSIBLE 1 1
result:
ok answer = 1
Test #2:
score: 0
Accepted
time: 1ms
memory: 3464kb
input:
2
output:
IMPOSSIBLE
result:
ok answer = 0
Test #3:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
3
output:
IMPOSSIBLE
result:
ok answer = 0
Test #4:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
4
output:
IMPOSSIBLE
result:
ok answer = 0
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3496kb
input:
5
output:
IMPOSSIBLE
result:
wrong answer jury has the better answer: jans = 1, pans = 0 (1 is Possible)