QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375718#2833. HamiltonTx_LcyWA 1ms4160kbC++141.3kb2024-04-03 15:09:572024-04-03 15:09:57

Judging History

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

  • [2024-04-03 15:09:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4160kb
  • [2024-04-03 15:09:57]
  • 提交

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';
		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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4160kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
4 2 3 2 

result:

wrong answer case #2: not a permutation