QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#390636 | #2833. Hamilton | Nahidameow | WA | 1ms | 3868kb | C++20 | 1.7kb | 2024-04-15 18:51:29 | 2024-04-15 18:51:29 |
Judging History
answer
#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lower_bound lb
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
std::ifstream f(name.c_str());
return f.good();
}
namespace Math{
ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
int n;
void solve(){
//don't forget to open long long
ve<std::string>v(n+1);
for(int i=1;i<=n;i++){
std::cin>>v[i];
v[i]=" "+v[i];
}
ve<int>ans;ans.pd(1);ans.pd(2);
for(int i=3;i<=n;i++){
int pos=-1;
for(int j=0;j+2<ans.size();j++){
if(v[ans[j]][ans[j+1]]!=v[ans[j+1]][ans[j+2]]){
pos=j;
break;
}
}
if(pos==-1)ans.pd(i);
else{
if(v[ans[pos]][ans[pos+1]]==v[ans[pos+1]][i])
ans.insert(ans.begin()+pos+2,i);
else ans.insert(ans.begin()+pos,i);
}
}
int pos=-1;
for(int i=0;i+2<ans.size();i++){
if(v[ans[i]][ans[i+1]]!=v[ans[i+1]][ans[i+2]]){
pos=i;
break;
}
}
if(pos==-1){
for(int i=0;i<n;i++)
std::cout<<ans[i]<<(i==n-1?'\n':' ');
}
else{
pos++;
for(int i=pos;i<ans.size();i++)
std::cout<<ans[i]<<' ';
for(int i=0;i<pos;i++)
std::cout<<ans[i]<<' ';
std::cout<<'\n';
}
}
int main(){
#ifndef ONLINE_JUDGE
if(!FileIfstream("IO.in")){
freopen("IO.in","w",stdout);
return 0;
}
freopen("IO.in","r",stdin);
freopen("IO.out","w",stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int T=1;
while(std::cin>>n)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
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: 0
Accepted
time: 0ms
memory: 3560kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 2 3 2 3 1 2 3 1 1 2 3
result:
ok 4 cases.
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3868kb
input:
4 0000 0000 0000 0000 4 0000 0001 0000 0100 4 0100 1010 0100 0000 4 0111 1000 1000 1000 4 0010 0011 1101 0110 4 0111 1011 1100 1100 4 0111 1011 1101 1110 4 0000 0011 0101 0110 4 0101 1010 0100 1000 4 0011 0011 1100 1100 4 0010 0001 1000 0100
output:
1 2 3 4 1 2 3 4 3 4 1 2 2 3 4 1 2 3 4 1 3 4 1 2 1 2 3 4 2 3 4 1 3 4 1 2 1 2 3 4 1 2 3 4
result:
wrong answer case #10: found 3 indices