QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#115012 | #5956. Paradox Sort | bear0131 | 4 | 27ms | 3536kb | C++14 | 1.8kb | 2023-06-24 13:49:16 | 2023-06-24 13:49:18 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
int n, targ;
string s[111];
bitset<111> g[111], rg[111];
vi ans;
bool in[111];
bool check(int u){
bitset<111> q, done;
q = 0, done = 0;
q[targ] = done[targ] = 1;
while(1){
int i = (int)q._Find_first();
if(i >= n) break;
//cout << " " << "bfs " << i << endl;
q[i] = 0;
if(!in[i])
q |= rg[i] & (~done);
if(!in[i] || i == u)
done |= rg[i];
}
bool ret = 1;
rep(i, n) if(!in[i] || i == u)
ret &= done[i];
//cout << "check " << u << " " << ret << endl;
return ret;
}
bool search(int u){
if(!check(u))
return 0;
//cout << "search " << u << ": ";
//rep(i, (int)ans.size())
// cout << ans[i] << " ";
//cout << "\n";
if((int)ans.size() == n)
return 1;
for(int i = 0; i < n; ++i){
if(in[i]) continue;
in[i] = 1;
ans.emplace_back(i);
//cout << " " << u << " to " << i << endl;
if(search(g[u][i] ? i : u)) return 1;
ans.pop_back();
in[i] = 0;
}
return 0;
}
void solve(){
cin >> n >> targ;
rep(i, n){
cin >> s[i];
rep(j, n)
g[i][j] = (s[i][j] == 'N'), rg[i][j] = (s[i][j] == 'Y');
}
if(n == 1){
cout << "0\n";
return ;
}
memset(in, 0, sizeof(in));
rep(i, n){
ans.clear();
in[i] = 1;
ans.emplace_back(i);
if(search(i)){
rep(j, n)
cout << ans[j] << " ";
cout << "\n";
return ;
}
in[i] = 0;
}
cout << "IMPOSSIBLE\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
rep(i, T){
cout << "Case #" << i+1 << ": ";
solve();
}
return 0;
}
// by zxb
// start coding at 13:19
// submission #1 at 13:45
// submission #2 at 13:49
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 1ms
memory: 3536kb
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: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 27ms
memory: 3460kb
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:
wrong answer 31st lines differ - expected: 'Case #31: 0 1 2 3 4 5 6 7 8 9 ...8 79 80 81 82 83 84 86 87 85 77', found: 'Case #31: 0 1 2 3 4 5 6 7 8 9 ... 79 81 82 83 84 85 87 86 80 77 '