QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#375720#2833. HamiltonTx_LcyWA 1ms3948kbC++141.3kb2024-04-03 15:10:592024-04-03 15:11:00

Judging History

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

  • [2024-04-03 15:11:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3948kb
  • [2024-04-03 15:10:59]
  • 提交

answer

//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
int const N=2e3+10;
string s[N];
int n,a[N][N],p[N];
inline void add(int x,int y){
	vector<int>g;g.push_back(y);
	rep(i,x+1,n)
		if (p[i]) g.push_back(p[i]);
	rep(i,1,x) g.push_back(p[i]);
	rep(i,1,g.size()) p[i]=g[i-1];
}
inline void solve(){
	while (cin>>n){
		rep(i,1,n) cin>>s[i],s[i]=" "+s[i];
		rep(i,1,n) rep(j,1,n) a[i][j]=s[i][j]-'0';
		rep(i,1,n) p[i]=0;
		p[1]=1,p[2]=2;
		rep(i,3,n){
			int pl=0;
			rep(j,1,i-1)
				if (a[p[j]][p[j%n+1]] && !a[p[j%n+1]][p[(j%n+1)%n+1]]){pl=j+1;break;}
			if (pl){
				if (!a[p[i]][p[pl%n+1]]) add(pl,i);
				else add(pl%n+1,i);
			}else add(i-1,i);
		}
		int tag=1;
		rep(i,1,n-1)
			if (a[p[i]][p[i%n+1]]!=a[p[i%n+1]][p[(i%n+1)%n+1]]){tag=i%n+1;break;}
		rep(i,tag,n) cout<<p[i]<<' ';
		rep(i,1,tag-1) cout<<p[i]<<' ';
		cout<<'\n';
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t=1;
	// cin>>t;
	while (t--) solve();
	cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<" s\n";
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3948kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
4 3 1 2 

result:

ok 2 cases.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3936kb

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

3 1 2 
1 2 3 
2 3 1 
3 1 2 

result:

ok 4 cases.

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3944kb

input:

4
0000
0000
0000
0000
4
0000
0001
0000
0100
4
0100
1010
0100
0000
4
0111
1000
1000
1000
4
0010
0011
1101
0110
4
0111
1011
1100
1100
4
0111
1011
1101
1110
4
0000
0011
0101
0110
4
0101
1010
0100
1000
4
0011
0011
1100
1100
4
0010
0001
1000
0100

output:

4 3 1 2 
2 4 3 1 
1 2 4 3 
3 1 2 4 
1 4 2 3 
3 1 2 4 
4 3 1 2 
3 1 2 4 
1 2 4 3 
4 2 3 1 
2 3 1 4 

result:

wrong answer case #11: found 3 indices