QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375335 | #2833. Hamilton | wsc2008 | WA | 0ms | 3816kb | C++14 | 1.6kb | 2024-04-03 09:17:14 | 2024-04-03 09:17:16 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
inline void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const ll N=2e3+9;
ll T,n;
char e[N][N];
void solve(){
rep(i,1,n)scanf("%s",e[i]+1);
vector<ll>ans(1,1);
rep(i,2,n){
ll fl=1,lst=-1;
rep(j,0,(ll)ans.size()-1){
ll es=e[ans[j]][ans[(j+1)%ans.size()]]-'0';
if((!(~lst))||es==lst)lst=es;
else fl=0;
}
if(fl)ans.push_back(i);
else {
rep(j,0,(ll)ans.size()-1){
ll es1=e[ans[j]][ans[(j+1)%ans.size()]]-'0';
ll es2=e[ans[(j+1)%ans.size()]][ans[(j+2)%ans.size()]]-'0';
if(es1==0||es2==1)continue;
ll es3=e[ans[(j+1)%ans.size()]][i]-'0';
if(!es3)ans.insert(ans.begin()+j,i);
else ans.insert(ans.begin()+(j+1)%ans.size(),i);
}
}
}
rep(i,0,(ll)ans.size()-1){
ll cnt=0,lst=e[ans[i]][ans[(i+1)%ans.size()]]-'0';
rep(j,1,(ll)ans.size()-1){
ll es=e[ans[(i+j)%ans.size()]][(i+j+1)%ans.size()]-'0';
if(lst!=es)cnt++;
lst=es;
}
if(cnt<=1){
rep(j,0,(ll)ans.size()-1)write(ans[(i+j)%ans.size()]),putchar(' ');
return ;
}
}
puts("-1");
}
bool Med;
int main(){
cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
while(cin>>n)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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
Wrong Answer
time: 0ms
memory: 3816kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 2 3 3 1 2 3 1 2 3 1 2
result:
wrong answer case #2: found 2 indices