QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21900 | #2833. Hamilton | DaBenZhongXiaSongKuaiDi# | WA | 3ms | 3564kb | C++14 | 1.3kb | 2022-03-08 17:15:09 | 2022-05-08 04:13:49 |
Judging History
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