QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115050#5956. Paradox Sortjuju52732 ✓49ms3656kbC++141.9kb2023-06-24 15:32:382023-06-24 15:32:41

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 15:32:41]
  • 评测
  • 测评结果:32
  • 用时:49ms
  • 内存:3656kb
  • [2023-06-24 15:32:38]
  • 提交

answer

//Code by juju527.
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define fi first
#define se second
#define vec vector<int>
#define eb emplace_back
using namespace std;
const int maxn=105;
int n,a;
char s[maxn];
bool e[maxn][maxn];
int cd[maxn];
int read(){
	int x=0,y=1;
	char ch=getchar();
	while(ch<48||ch>57){if(ch==45)y=-1;ch=getchar();}
	while(ch>=48&&ch<=57)x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*y;
}
pii buf[maxn];
bool use[maxn];
inline int trans(int p,int x){
	if(!p)return x;
	return e[p][x]?x:p;
}
int it[maxn];
bool chk(int x){
	if(x==a){
		for(int i=1;i<=n;i++)if(!use[i]&&e[a][i])return 0;
		return 1;
	}
	int len=0;
	for(int i=1;i<=n;i++)if(!use[i])buf[++len]=pii(cd[i],i);
	sort(buf+1,buf+len+1);
	int sum=0,scc=0,pos;
	for(int i=1;i<=len;i++){
		sum+=buf[i].fi;if(buf[i].se==a)pos=i;
		if(sum==i*(i-1)/2)it[++scc]=i;
	}
	int p=0;
	for(int i=1;i<=scc;i++)if(it[i]<pos)p=i;
	for(int i=1;i<=it[p];i++)if(e[x][buf[i].se])return 0;
	return 1;
}
int main(){
	int T,cas=0;
	T=read();
	while(T--){
		n=read(),a=read()+1;
		for(int i=1;i<=n;i++){
			scanf("%s",s+1);
			for(int j=1;j<=n;j++)e[i][j]=(s[j]=='N');
		}
		for(int i=1;i<=n;i++){
			cd[i]=0;
			for(int j=1;j<=n;j++)cd[i]+=e[i][j];
			buf[i]=pii(cd[i],i);
		}
		sort(buf+1,buf+n+1);
		int sum=0;bool ok=0;
		for(int i=1;i<=n;i++){
			sum+=buf[i].fi;ok|=(buf[i].se==a);
			if(sum==i*(i-1)/2)break;
		}
		if(!ok){printf("Case #%d: IMPOSSIBLE\n",++cas);continue;}
		for(int i=1;i<=n;i++)use[i]=0;
		int p=0;
		printf("Case #%d: ",++cas);
		for(int i=1;i<=n;i++){
			for(int x=1;x<=n;x++){
				if(use[x])continue;
				int z=trans(p,x);
				if(x==a&&z!=a)continue;
				use[x]=1;
				for(int u=1;u<=n;u++)if(!use[u])cd[u]-=e[u][x];
				if(chk(z)){p=z;printf("%d ",x-1);break;}
				for(int u=1;u<=n;u++)if(!use[u])cd[u]+=e[u][x];
				use[x]=0;
			}
		}
		puts("");
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 0ms
memory: 3588kb

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: 49ms
memory: 3656kb

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