QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#375340#2833. Hamiltonwsc2008WA 0ms4036kbC++141.6kb2024-04-03 09:21:382024-04-03 09:21:39

Judging History

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

  • [2024-04-03 09:21:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4036kb
  • [2024-04-03 09:21:38]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=2e3+9;
ll T,n;
char e[N][N];
void solve(){
	rep(i,1,n)scanf("%s",e[i]+1);
	vector<ll>ans(1,1);
	rep(i,2,n){
		ll fl=1,lst=-1;
		rep(j,0,(ll)ans.size()-1){
			ll es=e[ans[j]][ans[(j+1)%ans.size()]]-'0';
			if((!(~lst))||es==lst)lst=es;
			else fl=0;
		}
		if(fl)ans.push_back(i);
		else {
			rep(j,0,(ll)ans.size()-1){
				ll es1=e[ans[j]][ans[(j+1)%ans.size()]]-'0';
				ll es2=e[ans[(j+1)%ans.size()]][ans[(j+2)%ans.size()]]-'0';	
				if(es1==0||es2==1)continue;
				ll es3=e[ans[(j+1)%ans.size()]][i]-'0';
				if(!es3)ans.insert(ans.begin()+j,i);
				else ans.insert(ans.begin()+(j+1)%ans.size(),i);
				break;
			}
		}
	}
	rep(i,0,(ll)ans.size()-1){
		ll cnt=0,lst=e[ans[i]][ans[(i+1)%ans.size()]]-'0';
		rep(j,1,(ll)ans.size()-1){
			ll es=e[ans[(i+j)%ans.size()]][ans[(i+j+1)%ans.size()]]-'0';
			if(lst!=es)cnt++;
			lst=es;
		}
		if(cnt<=1){
			rep(j,0,(ll)ans.size()-1)write(ans[(i+j)%ans.size()]),putchar(' ');
			putchar('\n');
			return ;
		}
	}
	puts("-1");
}
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	while(cin>>n)solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3916kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
1 2 3 4 

result:

ok 2 cases.

Test #2:

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

input:

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

output:

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

result:

ok 4 cases.

Test #3:

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

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:

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

result:

wrong answer case #9: user does not find a solution