QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246092 | #2833. Hamilton | nameless_story# | RE | 0ms | 3784kb | C++20 | 1.1kb | 2023-11-10 16:10:37 | 2023-11-10 16:10:38 |
Judging History
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];
}
}
Details
Tip: Click on the bar to expand more detailed information
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