QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505187 | #2833. Hamilton | xiaohuzai | WA | 0ms | 3780kb | C++14 | 2.7kb | 2024-08-04 21:33:21 | 2024-08-04 21:33:21 |
Judging History
answer
#include<bits/stdc++.h>
#define gt getchar
#define pt putchar
#define fst first
#define scd second
typedef long long ll;
using namespace std;
const int N=2005;
typedef pair<int,int> pii;
inline bool __(char ch){return ch>=48&&ch<=57;}
template<class T> inline void read(T &x){
x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF) sgn|=(ch=='-'),ch=gt();
while(__(ch)) x=(x<<1)+(x<<3)+(ch&15),ch=gt();
if(sgn) x=-x;
}
template<class T,class ...T1> inline void read(T &x,T1 &...x1){
read(x);
read(x1...);
}
template<class T> inline void print(T x){
static char st[70];short top=0;
if(x<0) pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top) pt(st[top--]);
}
template<class T> inline void printsp(T x){
print(x);
putchar(' ');
}
template<class T> inline void println(T x){
print(x);
putchar('\n');
}
bool a[N][N];
int nxt[N],st,pre[N];
map<int,int>M;
void solve(int n){
M.clear();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char ch;cin>>ch;
a[i][j]=ch-'0';
}
}
for(int i=0;i<=n;i++)nxt[i]=0,pre[i]=0;
int nn=1,st=1;
nxt[1]=2,nxt[2]=1;
pre[2]=1;pre[1]=2;
for(int i=3;i<=n;i++){
if(nn==1){
nxt[i]=nxt[st];pre[nxt[st]]=i;
nxt[st]=i;pre[i]=st;
// for(int j=1;j<=n;j++)cout<<nxt[j]<<" "<<a[j][nxt[j]]<<endl;
if(a[i][nxt[i]]!=a[st][i]||a[st][i]!=a[pre[st]][st]||a[i][nxt[i]]!=a[nxt[i]][nxt[nxt[i]]])nn=2;
}
else{
int nw=st,ck=0,ckk=0;
while(nw!=st||ckk==0){
ckk=1;
if(a[pre[nw]][nw]==0&&a[nw][nxt[nw]]==1){
if(a[i][nw]==1){
nxt[pre[nw]]=i,pre[i]=pre[nw];
nxt[i]=nw,pre[nw]=i;
}
else{
pre[nxt[nw]]=i,nxt[i]=nxt[nw];
nxt[nw]=i,pre[i]=nw;
}
ck=1;
break;
}
if(a[pre[nw]][nw]==1&&a[nw][nxt[nw]]==0){
//puts("!");
if(a[i][nw]==1){
pre[nxt[nw]]=i,nxt[i]=nxt[nw];
nxt[nw]=i,pre[i]=nw;
}
else{
nxt[pre[nw]]=i,pre[i]=pre[nw];
nxt[i]=nw,pre[nw]=i;
}
ck=1;
break;
}
assert(nw!=0);
nw=nxt[nw];
}
nw=st,ck=0,ckk=0;
while(nw!=st||ckk==0){
ckk=1;
M[a[nw][nxt[nw]]]=1;
nw=nxt[nw];
}
if((!M[1])||(!M[0]))puts("-1");
//assert(ck!=0);
}
}
// for(int i=1;i<=n;i++)cout<<nxt[i]<<" "<<a[i][nxt[i]]<<endl;
for(int i=1;i<=n;i++){
int ck=0,ck1=0,nw=-1;
st=i;
while(st!=i||nw==-1){
nw=0;
if(ck&&a[st][nxt[st]]==0){ck1=-1;break;}
if(a[st][nxt[st]]==1)ck=1;
st=nxt[st];
}
if(ck1==0){
st=i;nw=-1;
while(st!=i||nw==-1){
nw=0;
printsp(st);
st=nxt[st];
}
cout<<endl;
return;
}
}
puts("-1");
//assert(0);
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
//cin>>n;
solve(n);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
3 2 1 1 4 3 2
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 3 2 1 3 2 3 2 1 1 3 2
result:
ok 4 cases.
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3780kb
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 4 3 2 1 4 3 2 2 4 1 3 4 3 2 1 2 1 4 3 4 3 2 1 1 4 3 2 2 1 4 3 4 3 2 1 -1 1 3 2 4 -1 1 4 3 2
result:
wrong answer case #10: user does not find a solution