QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#115026 | #5956. Paradox Sort | youngsystem | 32 ✓ | 46ms | 3776kb | C++20 | 2.1kb | 2023-06-24 14:23:40 | 2023-06-24 14:23:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int n=0,f=1,ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
n=n*10+ch-'0';
ch=getchar();
}
return n*f;
}
char s[105];
int g[105][105],rd[105];
int pos[105];
int p[105];
bool bi(int x,int y)
{
return rd[x]<rd[y];
}
int fj[105],cnt;
bool vis[105];
int main()
{
int t,n,x;
t=read();
for(int greg=1;greg<=t;greg++)
{
n=read();
x=read()+1;
for(int i=1;i<=n;i++)
{
scanf("%s",s+1);
rd[i]=0;
for(int j=1;j<=n;j++)
{
if(j==i)continue;
if(s[j]=='Y')
{
g[j][i]=1;
}
else
{
g[j][i]=0;
rd[i]++;
}
}
}
for(int i=1;i<=n;i++)pos[i]=i;
sort(pos+1,pos+n+1,bi);
cnt=0;
int sth=0;
for(int i=1;i<=n;i++)
{
sth+=rd[pos[i]];
//printf("%d\n",sth);
if(sth==i*(i-1)/2)fj[++cnt]=i;
}
bool flag=false;
for(int i=1;i<=fj[1];i++)if(pos[i]==x)flag=true;
if(flag==false)
{
printf("Case #%d: IMPOSSIBLE\n",greg);
continue;
}
for(int i=1;i<=n;i++)vis[i]=false;
int pre=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(vis[j])continue;
if(pre==x)
{
if(g[pre][j])continue;
vis[j]=true;
p[i]=j;
break;
}
int now=0;
if(pre==0||g[pre][j])now=j;
else now=pre;
for(int k=1;k<=n;k++)if(g[j][k]==0)rd[k]--;
int ttt=0;
for(int k=1;k<=n;k++)
{
if(k!=j&&vis[k]==false)pos[++ttt]=k;
}
sort(pos+1,pos+ttt+1,bi);
int sth=0,las=0;
bool flag=true;
for(int k=1;k<=ttt;k++)
{
if(pos[k]==x)break;
sth+=rd[pos[k]];
if(sth==k*(k-1)/2)
{
for(int l=las+1;l<=k;l++)
{
if(g[now][pos[l]])
{
flag=false;
break;
}
}
las=k;
}
}
if(flag==true)
{
vis[j]=true;
p[i]=j;
pre=now;
break;
}
for(int k=1;k<=n;k++)if(g[j][k]==0)rd[k]++;
}
}
printf("Case #%d: ",greg);
for(int i=1;i<=n;i++)printf("%d ",p[i]-1);
printf("\n");
}
return 0;
}
詳細信息
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 1ms
memory: 3776kb
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: 28
Accepted
Test #2:
score: 28
Accepted
time: 46ms
memory: 3644kb
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:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed