QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114995 | #5956. Paradox Sort | sjc061031 | 32 ✓ | 35ms | 3700kb | C++14 | 2.3kb | 2023-06-24 13:30:08 | 2023-06-24 13:30:10 |
Judging History
answer
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int n,X,vis[110],used[110],bad[110],ans[110],ok[110][110];
vector<int> v[110];
inline void dfs(int x,int y)
{
used[x]=1;
if(x==y) return;
for(int i=0;i<(int)v[x].size();i++) if(!bad[v[x][i]]&&!used[v[x][i]]){
dfs(v[x][i],y);
}
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);
int t;cin>>t;
int tot=0;
while(t--){
cin>>n>>X;X++;tot++;
for(int i=1;i<=n;i++) v[i].clear(),vis[i]=0,bad[i]=0,ans[i]=0;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ok[i][j]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char ch;cin>>ch;
if(ch=='Y'){
ok[i][j]=1;
v[i].push_back(j);
}
}
}
bool flag=true;
int p=-1;
for(int i=1;i<=n;i++){
int pos=-1;
for(int j=1;j<=n;j++) if(!vis[j]){
int u=j;
if(i>1&&ok[p][j]) u=p;
if(i>1){
if(u==p) bad[j]=1;
else bad[p]=1;
}
if(bad[X]){
if(i>1){
if(u==p) bad[j]=0;
else bad[p]=0;
}
continue;
}
for(int k=1;k<=n;k++) used[k]=0;
dfs(X,u);
bool now=true;
for(int k=1;k<=n;k++) if(!bad[k]&&!used[k]){
if(!ok[u][k]){
now=false;break;
}
}
if(i>1){
if(u==p) bad[j]=0;
else bad[p]=0;
}
if(now){
pos=j;break;
}
}
if(pos==-1){
flag=false;break;
}
ans[i]=pos;vis[pos]=1;
if(i==1) p=ans[i];
else{
if(ok[p][ans[i]]) bad[ans[i]]=1;
else bad[p]=1,p=ans[i];
}
}
cout<<"Case #"<<tot<<": ";
if(!flag) cout<<"IMPOSSIBLE\n";
else{
for(int i=1;i<=n;i++) cout<<ans[i]-1<<' ';
cout<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 1ms
memory: 3440kb
input:
100 3 0 -YN N-Y YN- 2 0 -Y N- 5 0 -YNNN N-YNN YN-YN YYN-Y YYYN- 5 1 -NYYY Y-NNN NY-NY NYY-N NYNY- 6 5 -YYNNY N-YYNY NN-NYN YNY-NY YYNY-Y NNYNN- 4 0 -YYY N-YN NN-N NYY- 2 0 -Y N- 5 1 -NYNY Y-YYY NN-YY YNN-N NNNY- 7 5 -YYYYYY N-NNYYN NY-YNNN NYN-NYN NNYY-NN NNYNY-N NYYYYY- 8 0 -YNNNNNN N-YNNNNN YN-YNN...
output:
Case #1: 1 2 0 Case #2: 0 1 Case #3: 3 4 2 1 0 Case #4: 0 2 3 4 1 Case #5: 0 1 3 4 2 5 Case #6: 0 1 2 3 Case #7: 0 1 Case #8: 0 1 2 3 4 Case #9: IMPOSSIBLE Case #10: 6 7 5 4 3 2 1 0 Case #11: 0 1 2 Case #12: 0 1 Case #13: 0 1 Case #14: IMPOSSIBLE Case #15: IMPOSSIBLE Case #16: 7 8 6 5 4 ...
result:
ok 100 lines
Subtask #2:
score: 28
Accepted
Test #2:
score: 28
Accepted
time: 35ms
memory: 3700kb
input:
100 39 0 -YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN N-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYYYYN-YNN...
output:
Case #1: 37 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Case #2: 0 13 23 28 30 34 38 40 41 42 43 46 49 51 52 33 5 1 17 32 15 29 19 10 16 47 48 9 4 27 6 7 18 31 8 11 26 50 3 37 25 35 45 20 24 39 22 12 44 36 2 21 14 Case #3: 0 1 2 3 4 5 6 8...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed