QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#422325 | #5956. Paradox Sort | Naganohara_Yoimiya | 32 ✓ | 43ms | 3936kb | C++14 | 2.3kb | 2024-05-27 11:51:22 | 2024-05-27 11:51:22 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
return x*f;
}
const int mod=998244353;
int ksm(int x,ll y,int p=mod){
int ans=1;y%=(p-1);
for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
int cmod(int x){if(x>=mod)x-=mod;return x;}
template<typename T>void cmax(T &x,T v){x=max(x,v);}
template<typename T>void cmin(T &x,T v){x=min(x,v);}
const int N=105;
bitset<N>F[N],V;
int n,Case;
bool G[N][N];
void clr(){
for(int i=1;i<=n;i++)F[i].reset();
}
void solve(){
n=read();int A=read()+1;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
char c=getchar();while(c!='Y'&&c!='N'&&c!='-')c=getchar();
G[i][j]=(c=='N'),F[i][j]=(c=='Y');
}
for(int i=1;i<=n;i++)G[0][i]=true;
vector<int>vis(n+1,0),ans(n+1,0);
int now=0;
auto chk=[&](){
// cout<<"chk now = "<<now<<endl;
for(int i=1;i<=n;i++)V[i]=(!vis[i]);
queue<int>q;
if(V[A])q.push(A),V[A]=0;
while(q.size()){
int x=q.front();q.pop();
auto W=(V&F[x]);
// cout<<"x = "<<x<<endl;
// cout<<"W = ";for(int i=1;i<=n;i++)cout<<W[i];puts("");
int cc=W.count();
for(int _=1;_<=cc;_++){
int x=W._Find_first();
q.push(x),V[x]=0,W[x]=0;
}
}
for(int i=1;i<=n;i++)if(V[i]){
if(!G[i][now])return false;
}
return true;
};
if(!chk()){
cout<<"Case #"<<++Case<<": IMPOSSIBLE\n";
clr();return ;
}
for(int i=1;i<=n;i++){
int tmp=now;
for(int j=1;j<=n;j++)if(!vis[j]){
vis[j]=true,now=(G[now][j]?j:now);
if(chk()){ans[i]=j;break;}
vis[j]=false,now=tmp;
}
now=(G[now][ans[i]]?ans[i]:now);
}
cout<<"Case #"<<++Case<<": ";
for(int i=1;i<=n;i++)cout<<ans[i]-1<<" \n"[i==n];
clr();
}
signed main(void){
#ifndef ONLINE_JUDGE
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
// freopen("sort/ex_1.in","r",stdin);
// freopen("in.txt","r",stdin);
#endif
int tt=read();while(tt--)solve();
return 0;
}
詳細信息
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 1ms
memory: 3936kb
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: 43ms
memory: 3852kb
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