QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#761359#9565. Birthday GiftMeowmeowmeow#RE 0ms0kbC++142.7kb2024-11-18 22:22:592024-11-18 22:23:00

Judging History

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

  • [2024-11-18 22:23:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-18 22:22:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define MAXN 200005
#define int long long

int fl[MAXN][2][2];
int fr[MAXN][2][2];
int p[MAXN];
char a[MAXN];
int n;

int mx(int &x,int y) {
    if(x < y) x = y;
}
int mn(int &x,int y) {
    if(y < 0) y = 0;
    if(x > y) x = y;
}


signed main() {
    int T;
    cin >> T;
    while(T --) {
        scanf("%s",a+1);
        n = strlen(a+1);
        for(int i = 0; i <= n; i ++) {
            memset(fl[i],0x3f,sizeof(fl[i]));
            memset(fr[i],0,sizeof(fr[i]));
            p[i] = 0;
            fr[i][0][1] = -1;
            fr[i][1][1] = -1;
        }
        p[0] = 1;

        for(int i = 1; i <= n; i ++) {
            if(a[i] != '1') {
                if(p[i-1] == 1) {
                    fl[i][0][1] = 1; 
                    mx(fr[i][0][1],1);
                }
                mn(fl[i][1][1],fl[i-1][0][0]-1);
                mn(fl[i][1][0],fl[i-1][0][1]-1);
                mn(fl[i][0][1],fl[i-1][1][0]+1);
                mn(fl[i][0][0],fl[i-1][1][1]+1);

                mx(fr[i][1][1],fr[i-1][0][0]-1);
                mx(fr[i][1][0],fr[i-1][0][1]-1);
                mx(fr[i][0][1],fr[i-1][1][0]+1);
                mx(fr[i][0][0],fr[i-1][1][1]+1);


                if(fl[i][0][0] == 0 || fl[i][1][0] == 0) p[i] = 1;
            } 
            if(a[i] != '0') {
                if(p[i-1] == 1) {
                    fl[i][1][1] = 1;
                    mx(fr[i][1][1],1);
                }
                mn(fl[i][1][1],fl[i-1][0][0]+1);
                mn(fl[i][1][0],fl[i-1][0][1]+1);
                mn(fl[i][0][1],fl[i-1][1][0]-1);
                mn(fl[i][0][0],fl[i-1][1][1]-1);

                mx(fr[i][1][1],fr[i-1][0][0]+1);
                mx(fr[i][1][0],fr[i-1][0][1]+1);
                mx(fr[i][0][1],fr[i-1][1][0]-1);
                mx(fr[i][0][0],fr[i-1][1][1]-1);

                if(fl[i][0][0] == 0 || fl[i][1][0] == 0) p[i] = 1;
              
            }
    
            if(p[i]) {
                if(fr[i][0][0] >= 2) fl[i][0][0] = 2;
                else fl[i][0][0] = 1e18;
                if(fr[i][1][0] >= 2) fl[i][1][0] = 2;
                else fl[i][1][0] = 1e18;
                
            }
         /*   cout<<i<<" "<<p[i]<<"---\n";
                cout<<fl[i][0][0]<<" "<<fl[i][0][1]<<" "<<fl[i][1][0]<<" "<<fl[i][1][1]<<"\n";
                cout<<fr[i][0][0]<<" "<<fr[i][0][1]<<" "<<fr[i][1][0]<<" "<<fr[i][1][1]<<"\n";
           */ //if(p[i]) fl[i][0][0] = fl[i][1][0] = 0;     
        }
        if(p[n]) cout<<0<<"\n";
        else cout<<min({fl[n][0][0],fl[n][0][1],fl[n][1][0],fl[n][1][1]})<<"\n";
    }

}
/*
5
0110101
01020102
0000021111
1012121010
0100202010
*/

详细

Test #1:

score: 0
Runtime Error

input:

5
0110101
01020102
0000021111
1012121010
0100202010

output:


result: