QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#423933 | #5956. Paradox Sort | hansiyuan | 0 | 571ms | 3968kb | C++14 | 1.4kb | 2024-05-28 19:44:33 | 2024-05-28 19:44:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int T,n,A,ok;
char input[N];
int g0[N][N];
int used[N];
int ans[N];
int vis[N];
bool dfs(int u){
//printf("hi! %d\n",u);
vis[u] = 1;
if(u==A) return 1;
for(int v=0;v<n;v++){
if(!g0[u][v] || used[v] || vis[v]) continue;
if(dfs(v)) return 1;
}
return 0;
}
bool chk(int u){
//printf("checking %d\n",u);
for(int x=0;x<n;x++){
if((used[x] && x!=u) || g0[x][u]) continue;
memset(vis,0,sizeof(vis));
//printf("%d dfs!\n",x);
if(!dfs(x)) return 0;
}
return 1;
}
void dfs(int cur,int fa){
if(cur==n+1){
ok = 1;
return;
}
for(int u=0;u<n;u++){
if(used[u]) continue;
//cout<<"hiiiiiiiiiiiiii! "<<cur<<' '<<u<<endl;
used[u] = 1;
if(fa!=-1 && g0[u][fa] && chk(fa)){
ans[cur] = u;
dfs(cur+1,fa);
return;
}
else if(chk(u)){
ans[cur] = u;
dfs(cur+1,u);
return;
}
used[u] = 0;
}
}
int main(){
scanf("%d",&T);//initialize the arrays
for(int tt=1;tt<=T;tt++){
scanf("%d%d",&n,&A);
ok = 0;
memset(g0,0,sizeof(g0));
memset(used,0,sizeof(used));
for(int i=0;i<n;i++){
scanf("%s",input);
for(int j=0;j<n;j++)
if(input[j]=='N')
g0[i][j] = 1;
}
dfs(1,-1);
printf("Case #%d: ",tt);
if(!ok) puts("IMPOSSIBLE");
else{
for(int i=1;i<=n;i++)
printf("%d ",ans[i]);
puts("");
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3912kb
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 1 2 0 Case #4: 0 2 3 4 1 Case #5: 0 1 3 2 4 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 4 5 2 3 0 1 Case #11: 0 1 2 Case #12: 0 1 Case #13: 0 1 Case #14: IMPOSSIBLE Case #15: IMPOSSIBLE Case #16: 7 8 5 6 3 ...
result:
wrong answer 3rd lines differ - expected: 'Case #3: 3 4 2 1 0', found: 'Case #3: 3 4 1 2 0 '
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 571ms
memory: 3968kb
input:
100 39 0 -YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN N-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN YYYYYYN-YNN...
output:
Case #1: 37 38 35 36 33 34 31 32 29 30 27 28 25 26 23 24 21 22 19 20 17 18 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2 0 Case #2: 0 13 23 28 30 34 38 40 41 42 43 46 49 51 52 5 33 1 17 15 32 19 29 10 16 47 9 48 4 6 27 7 18 8 31 11 26 3 50 25 37 35 20 45 24 22 39 12 36 44 2 14 21 Case #3: 0 1 2 3 4 5 6 8...
result:
wrong answer 1st lines differ - expected: 'Case #1: 37 38 36 35 34 33 32 ...13 12 11 10 9 8 7 6 5 4 3 2 1 0', found: 'Case #1: 37 38 35 36 33 34 31 ...4 11 12 9 10 7 8 5 6 3 4 1 2 0 '