QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21900#2833. HamiltonDaBenZhongXiaSongKuaiDi#WA 3ms3564kbC++141.3kb2022-03-08 17:15:092022-05-08 04:13:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 04:13:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3564kb
  • [2022-03-08 17:15:09]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
char e[2005][2005];
vector <int> v;
signed main(int argc, char** argv) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	while(cin >> n)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
				cin >> e[i][j];
		}
		v.clear();
		v.push_back(1);
		v.push_back(2);
		v.push_back(3);
		for(int i=4;i<=n;i++)
		{
			int mn=1e9,pos=0,N=v.size();
			for(int j=0;j<N;j++)
			{
				int w=0;
				if(e[v[(j-1+N)%N]][v[j]]!=e[v[j]][v[(j+1)%N]]) --w;
				if(e[v[j]][v[(j+1)%N]]!=e[v[(j+1)%N]][v[(j+2)%N]]) --w;
				if(e[v[(j-1+N)%N]][v[j]]!=e[v[j]][i]) ++w;
				if(e[v[j]][i]!=e[i][v[(j+1)%N]]) ++w;
				if(e[i][v[(j+1)%N]]!=e[v[(j+1)%N]][v[(j+2)%N]]) ++w;
				if(w<mn) mn=w,pos=j;
			}
			vector <int> nxt;
			for(int i=0;i<=pos;i++) nxt.push_back(v[i]);
			nxt.push_back(i);
			for(int i=pos+1;i<N;i++) nxt.push_back(v[i]);
			swap(nxt,v);
		}
		int flag=0;
		for(int j=0;j<n;j++)
		{
			if(e[v[j]][v[(j+1)%v.size()]]==1)
			{
				for(int i=j;i<v.size();i++)
					cout << v[i] << " ";
				for(int i=0;i<j;i++)
					cout << v[i] << " ";
				cout << "\n";
				flag=1;
				break;
			}
		}
		if(!flag)
		{
			for(auto t:v) cout << t << " ";
			cout << "\n";
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3564kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
1 4 2 3 

result:

ok 2 cases.

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3564kb

input:

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

output:

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

result:

wrong answer case #3: found 2 indices