QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375734#2833. HamiltonschrodingerstomWA 0ms4000kbC++142.8kb2024-04-03 15:20:092024-04-03 15:20:09

Judging History

你现在查看的是最新测评结果

  • [2024-04-03 15:20:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4000kb
  • [2024-04-03 15:20:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
bool memBeg;
template<typename T,typename TT> void chkmin(T &x,TT y) {if(x>y) x=y;}
template<typename T,typename TT> void chkmax(T &x,TT y) {if(x<y) x=y;}
constexpr int mod=998244353;
void inc(int &x,int y) {x+=y; x-=(x>=mod)*mod;}
void dec(int &x,int y) {x-=y; x+=(x<0)*mod;}
constexpr int add(int x,int y) {return (x+y>=mod)?x+y-mod:x+y;}
constexpr int sub(int x,int y) {return (x<y)?x-y+mod:x-y;}
constexpr int quick_pow(int x,ll times,int ret=1) {
    for(;times;times>>=1,x=1ll*x*x%mod) if(times&1) ret=1ll*ret*x%mod;
    return ret;
}
constexpr int maxn=2005;
int n,ppre[maxn],pnxt[maxn];
char mat[maxn][maxn];
bool memEn;
void fl() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}
int main() {
    fprintf(stderr,"%.24lf\n",fabs(&memEn-&memBeg)/1024.0/1024.0);
    // fl();
    int tur=0;
    while(~scanf("%d",&n)) {
        for(int i=1;i<=n;i++) scanf("%s",mat[i]+1);
        memset(ppre,0,sizeof(int)*(n+2));
        memset(pnxt,0,sizeof(int)*(n+2));
        int tead=0,rail=n+1;
        pnxt[tead]=1; ppre[rail]=2;
        ppre[1]=tead; pnxt[1]=2;
        ppre[2]=1; pnxt[2]=rail;
        auto emplace=[&](int pos,int idx)->void {
            ppre[idx]=ppre[pos]; pnxt[ppre[pos]]=idx;
            pnxt[idx]=pos; ppre[pos]=idx;
        };
        int dif=-1;
        for(int i=3;i<=n;i++) {
            if(dif==-1) {
                if(mat[pnxt[tead]][pnxt[pnxt[tead]]]==mat[ppre[rail]][i]) {
                    emplace(rail,i);
                    if(mat[ppre[ppre[rail]]][i]!=mat[i][pnxt[tead]]) dif=i;
                } else if(mat[ppre[rail]][i]==mat[i][pnxt[tead]]) {
                    emplace(rail,i); dif=ppre[ppre[rail]];
                } else {
                    emplace(pnxt[tead],i); dif=ppre[rail];
                }
            } else {
                if(mat[ppre[dif]][dif]==mat[dif][i]) {
                    emplace(pnxt[dif],i);
                    if(mat[ppre[i]][i]!=mat[i][pnxt[i]]) {
                        dif=i;
                    } else dif=pnxt[i];
                } else {
                    emplace(dif,i);
                    if(mat[ppre[i]][i]!=mat[i][pnxt[i]]) {
                        dif=i;
                    } else dif=ppre[i];
                }
                if(dif==pnxt[tead]&&mat[dif][pnxt[dif]]==mat[dif][ppre[rail]]) dif=-1;
            }
            // for(int j=pnxt[tead];j!=rail;j=pnxt[j]) printf("%d ",j);
            // puts("");
            // for(int j=pnxt[tead];pnxt[j]!=rail;j=pnxt[j]) printf("%c ",mat[j][pnxt[j]]);
            // printf("%c\n",mat[ppre[rail]][pnxt[tead]]);
            // printf("dif = %d\n",dif);
        }
        for(int i=pnxt[tead];i!=rail;i=pnxt[i]) printf("%d ",i);
        puts("");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4000kb

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: 3952kb

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: 0
Accepted
time: 0ms
memory: 3928kb

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 
1 2 4 3 
3 1 4 2 
1 4 2 3 
4 1 2 3 
1 2 3 4 
3 1 4 2 
1 2 4 3 
1 4 2 3 
1 2 3 4 

result:

ok 11 cases.

Test #4:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

5
00000
00000
00000
00000
00000
5
00001
00000
00000
00000
10000
5
00010
00010
00000
11000
00000
5
00000
00001
00001
00001
01110
5
00001
00001
00001
00001
11110
5
00101
00100
11011
00100
10100
5
01111
10011
10000
11000
11000
5
00011
00011
00011
11101
11110
5
01101
10111
11001
01001
11110
5
00111
0011...

output:

1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
5 1 2 3 4 
1 2 3 4 5 
1 2 4 5 3 
3 1 2 5 4 
1 2 5 3 4 
1 2 3 5 4 
1 4 2 3 5 
1 2 3 4 5 
3 1 2 4 5 
3 1 2 4 5 
3 1 2 4 5 
3 1 5 4 2 
3 1 2 4 5 
1 2 3 4 5 
1 2 3 5 4 
1 2 5 4 3 
1 2 5 4 3 
1 2 3 5 4 
3 5 1 4 2 
1 2 4 5 3 
1 2 4 5 3 
1 4 5 2 3 
1 2 4 5 3 
5 1 2 3 4 
1 2...

result:

ok 34 cases.

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3944kb

input:

6
000000
000000
000000
000000
000000
000000
6
000000
000000
000001
000000
000000
001000
6
010000
100100
000000
010000
000000
000000
6
000100
000000
000100
101010
000100
000000
6
000100
000000
000100
101011
000100
000100
6
001000
001000
110111
001000
001000
001000
6
001100
000100
100100
111011
000100...

output:

1 2 3 4 5 6 
1 2 3 4 5 6 
1 6 2 5 4 3 
1 2 3 5 6 4 
1 2 3 5 6 4 
1 2 4 5 6 3 
1 2 5 6 4 3 
1 2 5 6 3 4 
1 2 3 6 5 4 
1 2 6 5 4 3 
1 5 4 2 3 6 
1 2 3 4 5 6 
1 2 3 5 6 4 
6 1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 
3 6 1 5 4 2 
1 2 3 6 4 5 
5 1 4 2 3 6 
4 1 2 3 6 5 
5 1 2 3 6 4 
4 1 2 3 5 6 
1 2 3 5 6 4 
1...

result:

wrong answer case #37: found 2 indices