QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#246092#2833. Hamiltonnameless_story#RE 0ms3784kbC++201.1kb2023-11-10 16:10:372023-11-10 16:10:38

Judging History

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

  • [2023-11-10 16:10:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3784kb
  • [2023-11-10 16:10:37]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
mt19937 rnd(345);
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n,i,j;
	while (cin>>n)
	{
		vector a(n,vector<int>(n));
		for (auto &v:a)
		{
			string s;
			cin>>s;
			for (i=0; i<n; i++) v[i]=s[i]&1;
		}
		vector<int> r={0,1};
		for (i=2; i<n; i++)
		{
			// cerr<<i<<endl;
			for (j=1; j+1<i; j++) if (a[r[j]][r[j+1]]!=a[r[j-1]][r[j]]) break;
			if (j+1>=i)
			{
				r.push_back(i);
				continue;
			}
			// cerr<<i<<' '<<j<<endl;
			if (a[r[j-1]][r[j]]==a[r[j]][i])
			{
				r.insert(r.begin()+j+1,i);
			}
			else
			{
				r.insert(r.begin()+j,i);
			}
		}
		int cnt=0;
		for (i=1; i<n; i++) if (a[r[i-1]][r[i]]!=a[r[i]][r[(i+1)%n]]) ++cnt;
		assert(cnt<=1);
		for (i=0; i<n; i++) cout<<r[i]+1<<" \n"[i+1==n];
	}
}

详细

Test #1:

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

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: -100
Runtime Error

input:

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

output:


result: