QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376123 | #2833. Hamilton | zhulexuan | WA | 1ms | 3760kb | C++14 | 2.3kb | 2024-04-03 21:10:11 | 2024-04-03 21:10:13 |
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;
}
fr(i,1,n) write(b[i]),putchar(' ');
putchar('\n');
}
return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=512000000
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3744kb
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: 3760kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 2 3 1 2 3 1 2 3 1 2 3
result:
wrong answer case #3: found 2 indices