QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#115044 | #5956. Paradox Sort | Zesty_Fox | 32 ✓ | 32ms | 3820kb | C++20 | 3.1kb | 2023-06-24 15:17:26 | 2023-06-24 15:17:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using u32=unsigned int;
using i64=long long;
using u64=unsigned long long;
using db=double;
using vi=vector<int>;
using pii=pair<int,int>;
template<typename T>
T read(){
T x=0,f=0;char ch=getchar();
while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
while(isdigit(ch)) x=x*10+(ch-'0'),ch=getchar();
return f?-x:x;
}
#define rdi read<int>
#define rdi64 read<i64>
#define fi first
#define se second
#define pb push_back
const int N=110;
int n,t;
int g[N][N];
vi e[N],re[N];
int use[N],vis[N];
// int dfn[N],low[N],ti;
// int st[N],tp,ins[N];
// int bl[N],siz[N],scc;
// void dfs(int x){
// dfn[x]=low[x]=++ti;
// st[++tp]=x,ins[x]=1;
// for(auto y:e[x]){
// if(vis[y]) continue;
// if(!dfn[y])
// dfs(y),low[x]=min(low[x],low[y]);
// else if(ins[y])
// low[x]=min(low[x],dfn[y]);
// }
// if(low[x]==dfn[x]){
// ++scc;
// do{
// bl[st[tp]]=scc,ins[st[tp]]=0;
// ++siz[scc];
// }while(st[tp--]!=x);
// }
// }
bool check(int s,int t){
// scc=ti=tp=0;
// for(int i=1;i<=n;i++)
// dfn[i]=low[i]=bl[i]=siz[i]=0;
// for(auto y:re[s])
// if(!vis[y]&&y!=t) vis[y]=2;
// for(int i=1;i<=n;i++)
// if(!vis[i]&&!dfn[i]) dfs(i);
// for(auto y:re[s])
// if(vis[y]==2) vis[y]=0;
// return bl[t]==1;
if(vis[t]) return false;
queue<int> q;q.push(t);
while(!q.empty()){
int x=q.front();q.pop();
if(vis[x]) continue;
vis[x]=2;
if(x==s) continue;
for(auto y:re[x])
if(!vis[y]) q.push(y);
}
if(vis[s]){
for(auto y:re[s])
if(!vis[y]) vis[y]=2;
}
bool ret=!count(vis+1,vis+n+1,0);
for(int i=1;i<=n;i++)
if(vis[i]==2) vis[i]=0;
return ret;
}
int res[N];
void clear(){
for(int i=1;i<=n;i++){
use[i]=vis[i]=res[i]=0;
e[i].clear(),re[i].clear();
for(int j=1;j<=n;j++) g[i][j]=0;
}
}
void solve(int id){
printf("Case #%d: ",id);
n=rdi(),t=rdi()+1;
for(int i=1;i<=n;i++){
static char s[N];scanf("%s",s+1);
for(int j=1;j<=n;j++)
if(s[j]=='N')
g[i][j]=1,e[i].pb(j),re[j].pb(i);
}
int cur=0;
fill(res+1,res+n+1,0);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(use[j]) continue;
int nx=(!cur||g[cur][j]?j:cur);
vis[cur^j^nx]=1;
if(check(nx,t)){
use[j]=1,res[i]=j,cur=nx;
break;
}
vis[cur^j^nx]=0;
}
if(!res[i]){
puts("IMPOSSIBLE");
clear();return;
}
}
for(int i=1;i<=n;i++)
cout<<res[i]-1<<" \n"[i==n];
clear();
}
int main(){
#ifdef LOCAL
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
int T=rdi();
for(int i=1;i<=T;i++) solve(i);
return 0;
}
詳細信息
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 1ms
memory: 3664kb
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 3 1 2 0 Case...
result:
ok 100 lines
Subtask #2:
score: 28
Accepted
Test #2:
score: 28
Accepted
time: 32ms
memory: 3820kb
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 9...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed