QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376130 | #2833. Hamilton | zhulexuan | WA | 1ms | 5736kb | C++14 | 2.6kb | 2024-04-03 21:16:50 | 2024-04-03 21:16:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
T w=1; n=0; char ch=getchar();
while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
n*=w;
}
template<typename T>inline void write(T x){
if (x==0){ putchar('0'); return ; }
T tmp;
if (x>0) tmp=x;
else tmp=-x;
if (x<0) putchar('-');
char F[105];
long long cnt=0;
while (tmp){
F[++cnt]=tmp%10+48;
tmp/=10;
}
while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 2005;
ll n,m,ans=0,x,y,l,r,s,z;
ll a[N][N];
ll b[N];
bool get_in(){
ll i,j;
char ch[N];
read(n);
if (!n) return false;
fr(i,1,n){
scanf("%s",ch+1);
fr(j,1,n)
a[i][j] = ch[j]-'0';
}
return true;
}
int main(){
// freopen("a.in","r",stdin);
// freopen(".out","w",stdout);
ll i,j;
while (get_in()){
b[1] = 1; b[2] = 2; b[3] = 3;
fr(i,4,n){
ll st = a[b[1]][b[2]];
bool flg = true;
fr(j,1,i-2)
if (a[b[j]][b[j+1]]!=st) flg = false;
if (a[b[1]][b[i-1]]!=st) flg = false;
// printf("st = %lld\n",st);
if (flg){ b[i] = i; continue; }
ll pos = -1;
fr(j,1,i-3)
if (a[b[j]][b[j+1]]!=a[b[j+1]][b[j+2]]) pos = i;
if (a[b[1]][b[2]]!=a[b[1]][b[i-1]]) pos = i-1;
if (a[b[i-2]][b[i-1]]!=a[b[1]][b[i-1]]) pos = i-2;
ll x,y,z;
x = pos; y = pos+1; z = pos+2;
if (y>=i) y -= i-1;
if (z>=i) z -= i-1;
ll ip;
if (a[b[y]][b[x]]!=a[b[y]][i]) ip = x; else ip = y;
rfr(j,i-1,ip) b[j+1] = b[j];
// printf("ip = %lld\n",ip);
b[ip] = i;
}
ll pos = 1;
fr(i,1,n-2)
if (a[b[i]][b[i+1]]!=a[b[i+1]][b[i+2]]) pos = i+1;
if (a[b[n-1]][b[n]]!=a[b[n]][b[1]]) pos = n;
if (a[b[n]][b[1]]!=a[b[1]][b[2]]) pos = 1;
fr(i,pos,n) write(b[i]),putchar(' ');
fr(i,1,pos-1) write(b[i]),putchar(' ');
putchar('\n');
}
return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=512000000
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3748kb
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: 3828kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 2 3 1 2 3 3 1 2 1 2 3
result:
ok 4 cases.
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5736kb
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 1 4 2 3 1 2 4 1 2 4 3 4 1 2 3 1 2 3 4 3 1 2 4 1 4 2 3 4 1 2 3 1 2 4 3
result:
wrong answer case #9: found 3 indices