QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377667 | #2833. Hamilton | Jerrywang | RE | 0ms | 0kb | C++14 | 1.3kb | 2024-04-05 16:34:45 | 2024-04-05 16:34:46 |
answer
// Title: Hamilton
// Source: QOJ2833
// Author: Jerrywang
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define ll long long
#define rep(i, s, t) for(int i=s; i<=t; ++i)
#define debug(x) cerr<<#x<<":"<<x<<endl;
const int N=2005;
using namespace std;
int n, g[N][N]; vector<int> a;
void ins(int i, int x)
{
a.insert(a.begin()+i, x);
}
void solve()
{
rep(i, 1, n) rep(j, 1, n) scanf("%1d", &g[i][j]);
a.clear();
rep(i, 1, n)
{
bool f=0;
rep(j, 1, n) if(g[i][j])
{
a.push_back(i), a.push_back(j), f=1; break;
}
if(f) break;
}
rep(i, 1, n)
{
int k=-1;
for(int x:a) if(x==i) k=1;
if(k==1) continue;
rep(j, 1, a.size()-2)
{
if(g[a[j-1]][a[j]] && !g[a[j]][a[j+1]])
{
k=j; break;
}
}
if(k==-1) a.push_back(i);
else if(g[a[k]][i]==0) ins(k, i);
else ins(k+1, i);
}
if(g[a[n-1]][a[0]]==1)
a.insert(a.begin(), a[n-1]), a.pop_back();
for(int x:a) printf("%d ", x);
puts("");
}
int main()
{
#ifdef Jerrywang
freopen("E:/OI/in.txt", "r", stdin);
#endif
while(~scanf("%d", &n)) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 001 000 100 4 0000 0000 0000 0000