QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#422178 | #5956. Paradox Sort | unputdownable | 32 ✓ | 16ms | 3912kb | C++17 | 2.3kb | 2024-05-26 21:40:04 | 2024-05-26 21:40:05 |
Judging History
answer
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#include <bits/stdc++.h>
// #define int long long
#define i64 long long
#define pii pair <int, int>
using namespace std;
inline int read(void) {
int x=0,sgn=1; char ch=getchar();
while(ch<48||57<ch) {if(ch==45)sgn=0;ch=getchar();}
while(47<ch&&ch<58) {x=x*10+ch-48; ch=getchar();}
return sgn? x:-x;
}
void write(int x) {
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
/*
write((Ans%p+p)%p); pls
*/
int n,tar;
char V[102][102];
bitset <102> que,crvis,eto[102];
vector <int> res;
bool vis[102];
inline bool check(int u) {
que.reset(); crvis.reset(); que[tar]=crvis[tar]=1;
int x;
while((x=que._Find_first())<n) {
que[x]=0; if(vis[x]) continue;
que|=eto[x]&(~crvis);
crvis|=eto[x];
}
if(!crvis[u]) return 0;
crvis|=eto[u];
for(int i=0; i<n; ++i) if(!vis[i]&&!crvis[i]) return 0;
return 1;
}
bool solve(int st) {
if(!check(st)) return 0;
if(res.size()==n) return 1;
for(int i=0; i<n; ++i) if(!vis[i]) {
vis[i]=1;
res.push_back(i);
if(solve(V[st][i]=='Y' ? st :i)) return 1;
res.pop_back();
vis[i]=0;
}
return 0;
}
inline void work(const int testid) {
n=read(); tar=read();
for(int i=0; i<n; ++i) scanf("%s",V[i]);
for(int i=0; i<n; ++i) eto[i].reset();
for(int i=0; i<n; ++i)
for(int u=0; u<n; ++u)
if(V[i][u]=='Y')
eto[i][u]=1;
for(int i=0; i<n; ++i) vis[i]=0;
res.clear();
for(int st=0; st<n; ++st) {
vis[st]=1;
res.push_back(st);
if(solve(st)) {
printf("Case #%d:",testid);
for(int v : res) putchar(' '),write(v);
puts("");
return ;
}
res.pop_back();
vis[st]=0;
}
printf("Case #%d:",testid);
puts(" IMPOSSIBLE");
}
signed main() {
// freopen("localinput","r",stdin);
// freopen("localoutput","w",stdout);
// freopen("localerr","w",stderr);
int T=read();
for(int i=1; i<=T; ++i) {
work(i);
}
// fprintf(stderr,"%.4lf\n",1.0*clock()/CLOCKS_PER_SEC);
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: 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 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: 16ms
memory: 3812kb
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