QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114978#5956. Paradox Sortyoungsystem0 6ms3708kbC++203.2kb2023-06-24 12:05:582023-06-24 12:05:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-24 12:05:59]
  • 评测
  • 测评结果:0
  • 用时:6ms
  • 内存:3708kb
  • [2023-06-24 12:05:58]
  • 提交

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;
}
vector<int>v[105];
int g[105][105];
int cd[105];
int col[105];
int dfn[105],low[105],cnt;
int sta[105],ttop;
bool vis[105];
char s[105];
int csl;
void tarjan(int x)
{
	dfn[x]=low[x]=++cnt;
	vis[x]=true;
	sta[++ttop]=x;
	for(int i=0;i<v[x].size();i++)
	{
		if(dfn[v[x][i]]==0)
		{
			tarjan(v[x][i]);
			low[x]=min(low[x],low[v[x][i]]);
		}
		else if(vis[v[x][i]]==true)low[x]=min(low[x],dfn[v[x][i]]);
	}
	if(dfn[x]==low[x])
	{
		++csl;
		while(1)
		{
			col[sta[ttop]]=csl;
			vis[sta[ttop]]=false;
			if(sta[ttop]==x)
			{
				ttop--;
				break;
			}
			ttop--;
		}
	}
}
int nex[305];
int xl[305],tmp;
int p[305],ttt;
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++)v[i].clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%s",s+1);
			for(int j=1;j<=n;j++)
			{
				if(s[j]=='Y')
				{
					g[j][i]=1;
					v[j].push_back(i);
				}
				else if(s[j]=='N')
				{
					g[j][i]=0;
				}
			}
		}
		for(int j=1;j<=n;j++)
		{
			dfn[j]=low[j]=col[j]=cd[j]=nex[j]=0; 
			vis[j]=false;
		}
		cnt=0;
		ttop=0;
		csl=0;
		tmp=ttt=0;
		for(int j=1;j<=n;j++)
		{
			if(dfn[j]==0)tarjan(j);
		} 
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(i==j)continue;
				if(g[i][j]==1&&col[i]!=col[j])
				{
					cd[col[i]]++;
				}
			}
		}
		//printf("%d %d\n",col[1],col[2]);
		if(cd[col[x]]!=0)
		{
			printf("Case #%d: IMPOSSIBLE\n",greg);
			continue;
		}
		tmp=0;
		int s=0,t=0;
		for(int i=1;i<=n;i++)
		{
			if(cd[col[i]]!=0)continue;
			//printf("!!!%d %d %d\n",i,s,t);
			if(s==0)
			{
				s=t=i;
				continue;
			}
			if(g[i][s])
			{
				nex[i]=s;
				s=i;
				continue; 
			}
			if(g[t][i])
			{
				nex[t]=i;
				t=i;
				continue;
			}
			for(int j=s;j!=t;j=nex[j])
			{
				if(g[j][i]&&g[i][nex[j]])
				{
					int k=nex[j];
					nex[j]=i;
					nex[i]=k;
					break;
				}
			}
			//printf("%d %d %d\n",s,nex[s],nex[nex[nex[s]]]);
		}
		if(s==t)
		{
			printf("Case #%d: ",greg);
			for(int i=1;i<=n;i++)if(i!=x)printf("%d ",i-1);
			printf("%d\n",x-1);
			continue;
		}
		//printf("???%d %d\n",s,t);
		t=0;
		for(int i=nex[s];i;i=nex[i])
		{
			//printf("orz%d\n",i);
			if(t!=0)
			{
				if(g[i][s])t=i;
				else
				{
					for(int j=s;j!=t;j=nex[j])
					{
						if(g[i][nex[j]])
						{
							int k=nex[j];
							nex[j]=nex[t];
							nex[t]=s;
							s=k;
							t=i;
							break;
						}
					}
				}
			}
			else if(g[i][s])t=i;
		}
		//printf("%d %d\n",s,t);
		for(int j=s;j!=t;j=nex[j])xl[++tmp]=j;
		xl[++tmp]=t;
		int pos=0;
		for(int i=1;i<=tmp;i++)if(xl[i]==x)
		{
			pos=i;
			break;
		}
		for(int i=1;i<=n;i++)
		{
			if(cd[col[i]]!=0)
			{
				p[++ttt]=i;
			}
		}
		for(int i=pos+1;i<=tmp;i++)p[++ttt]=xl[i];
		for(int i=1;i<=pos;i++)p[++ttt]=xl[i];
		printf("Case #%d: ",greg);
		for(int i=1;i<=ttt;i++)printf("%d ",p[i]-1);
		printf("\n"); 
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3708kb

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: 2 1 0 
Case #2: 1 0
Case #3: 4 3 2 1 0 
Case #4: 3 4 2 0 1 
Case #5: 1 0 3 4 2 5 
Case #6: 1 2 3 0
Case #7: 1 0
Case #8: 0 2 3 4 1
Case #9: IMPOSSIBLE
Case #10: 7 6 5 4 3 2 1 0 
Case #11: 1 2 0
Case #12: 1 0
Case #13: 1 0
Case #14: IMPOSSIBLE
Case #15: IMPOSSIBLE
Case #16: 8 7 6 5 4 3 1 2 0...

result:

wrong answer 1st lines differ - expected: 'Case #1: 1 2 0', found: 'Case #1: 2 1 0 '

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 6ms
memory: 3648kb

input:

100
39 0
-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
N-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYN-YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
YYYYYYN-YNN...

output:

Case #1: 38 37 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: 41 40 49 34 13 28 38 30 42 43 46 23 51 52 0 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: 21 24 26 18 16 ...

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: 38 37 36 35 34 33 32 ...3 12 11 10 9 8 7 6 5 4 3 2 1 0 '