QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377608#6185. Best ProblemKevin5307AC ✓58ms67260kbC++203.1kb2024-04-05 15:49:062024-04-05 15:49:06

Judging History

你现在查看的是测评时间为 2024-04-05 15:49:06 的历史记录

  • [2024-04-05 16:19:23]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:57ms
  • 内存:65828kb
  • [2024-04-05 16:19:14]
  • hack成功,自动添加数据
  • (/hack/587)
  • [2024-04-05 16:06:13]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:44ms
  • 内存:67184kb
  • [2024-04-05 16:05:44]
  • hack成功,自动添加数据
  • (/hack/586)
  • [2024-04-05 15:49:06]
  • 评测
  • 测评结果:100
  • 用时:58ms
  • 内存:67260kb
  • [2024-04-05 15:49:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
bool memBeg;
template<typename T> void chkmin(T &x,T y) {if(x>y) x=y;}
template<typename T> void chkmax(T &x,T y) {if(x<y) x=y;}
constexpr int mod=1e9+7;
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,int 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=5e6+15;
int n;
char s[maxn],t[maxn];
pair<int,char> stk[maxn];
ll ret,cot[maxn];
bool memEn;
void fl() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}
void solve(){
    // fprintf(stderr,"%.24lf\n",fabs(&memEn-&memBeg)/1024.0/1024.0);
    // fl();
    scanf("%s",s+1);
    n=strlen(s+1);
    int top=0;
    ll ret=0ll;
    // 0...1 -> .....
    auto emplace=[&](int idx,char c) {
        if(top&&stk[top].second=='0'&&c=='1'&&((idx-stk[top].first)&3)==0) {
            ret+=(idx-stk[top].first)>>2; top--;
        } else stk[++top]={idx,c};
    };
    emplace(0,'1');
    if(s[1]=='1') emplace(1,'1');
    for(int i=2;i<=n;i++) if(s[i]==s[i-1]) emplace(i,s[i]);
    if(s[n]=='0') emplace(n+1,'0');
    emplace(n+2,'0');
    // 0.... -> ....0
    for(int i=top-1;i>=1;i--) {
        if(stk[i].second=='0'&&stk[i+1].second=='0') {
            int t=(stk[i+1].first-stk[i].first)>>2;
            ret+=t; stk[i].first+=t<<2;
        }
    }
    // ....1 -> 1....
    for(int i=2;i<=top;i++) {
        if(stk[i].second=='1'&&stk[i-1].second=='1') {
            int t=(stk[i].first-stk[i-1].first)>>2;
            ret+=t; stk[i].first-=t<<2;
        }
    }
    // printf("ret = %lld\n",ret);
    for(int i=6;i<=n+2;i++) {
        int t=(i-2)>>2;
        cot[i]=t+cot[t<<2];
    }
    int ept[2]={-1,-1};
    ll mx[2]={0ll,0ll};
    for(int i=1,i0,i1;i<=top;i=i1) {
        for(i0=i;i0<=top&&stk[i0].second=='0';i0++);
        for(i1=i0;i1<=top&&stk[i1].second=='1';i1++);
        if(i==1) {
            ept[0]=ept[1]=stk[i1-1].first;
        } else if(i1==top+1) {
            for(int t=0;t<2;t++) mx[t]+=cot[stk[i].first-ept[t]];
        } else {
            int nept[2]={-1,-1};
            ll nmx[2]={0ll,0ll};
            int step=(stk[i0].first-stk[i0-1].first)>>2;
            // 0.....1 -> ....0.1
            nept[0]=stk[i1-1].first;
            for(int t=0;t<2;t++) {
                chkmax(nmx[0],mx[t]+cot[(stk[i].first+(step<<2))-ept[t]]+1ll*(i0-i)*step);
            }
            // 0.....1 -> 0.1....
            nept[1]=stk[i1-1].first-(step<<2);
            for(int t=0;t<2;t++) {
                chkmax(nmx[1],mx[t]+cot[stk[i].first-ept[t]]+1ll*(i1-i0)*step);
            }
            memcpy(ept,nept,sizeof(int)*2);
            memcpy(mx,nmx,sizeof(ll)*2);
        }
    }
    printf("%lld\n",ret+max(mx[0],mx[1]));
}
int main()
{
    int _=1;
    while(_--)solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7852kb

input:

10100010011001011111

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 1ms
memory: 8052kb

input:

0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010

output:

58

result:

ok 1 number(s): "58"

Test #3:

score: 0
Accepted
time: 17ms
memory: 23564kb

input:

100011000011001011010100111110011001000110111101101001100000110101101001101111100101110001101101000001001011011111001100111010101111001110000110001100101100101001001110000111100001100110000101111110001010101100100110010001110011101011110011101111000111010111100110100011110000011111110000111110111110...

output:

302244

result:

ok 1 number(s): "302244"

Test #4:

score: 0
Accepted
time: 4ms
memory: 17064kb

input:

100101010101010101010101010101010101010101100101101010101101010110101001001010101010101101010101010010101010010101010110101010101010101010101101010110101010101010101010101010101010101010101010101010101010101010101010101010101011010101010101010101010101011010010101110101010110101010101010101010111010...

output:

3328566

result:

ok 1 number(s): "3328566"

Test #5:

score: 0
Accepted
time: 6ms
memory: 19368kb

input:

101010101010101010101101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010110...

output:

36918913

result:

ok 1 number(s): "36918913"

Test #6:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

371689423

result:

ok 1 number(s): "371689423"

Test #7:

score: 0
Accepted
time: 6ms
memory: 19752kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

3378077368

result:

ok 1 number(s): "3378077368"

Test #8:

score: 0
Accepted
time: 5ms
memory: 16660kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

31250155082

result:

ok 1 number(s): "31250155082"

Test #9:

score: 0
Accepted
time: 2ms
memory: 17088kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

21976748120

result:

ok 1 number(s): "21976748120"

Test #10:

score: 0
Accepted
time: 2ms
memory: 16732kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

31249989871

result:

ok 1 number(s): "31249989871"

Test #11:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

15417990032

result:

ok 1 number(s): "15417990032"

Test #12:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

31249770935

result:

ok 1 number(s): "31249770935"

Test #13:

score: 0
Accepted
time: 48ms
memory: 67260kb

input:

001001110010100110000111011111010010000100110011010111100100011110101100000001000011001011010000100101101110001010011110010000000101110101101101001011000101011000001001110011001101111010111010000100011011111101101001000001111000001101100011011011111100001000000011001111110000100001111110111000011110...

output:

1529176

result:

ok 1 number(s): "1529176"

Test #14:

score: 0
Accepted
time: 58ms
memory: 61044kb

input:

111100101110111001010010100101010101110101100100011110100001010110101101000010100111001101110011011010010101100101010111001001100111001010111010100111010001110110000001001100001010000101011011010101010011000111010111111011011000010101101001010101010101111010101100101000010100101101110101110101011100...

output:

3453809

result:

ok 1 number(s): "3453809"

Test #15:

score: 0
Accepted
time: 43ms
memory: 56940kb

input:

010100110101010101111100101010101010010100101010010101010010010101011010101010100101010101010011100110101011010011100101010101001010101010110011001010101101101110101010101010101010100101010101100100101010101100010101001010101010101010110100101001010010100101101010101010101010101011101001010101101010...

output:

7267243

result:

ok 1 number(s): "7267243"

Test #16:

score: 0
Accepted
time: 24ms
memory: 54896kb

input:

101100101010101010100010101010101001101010101010101010101101011010100101010101001010110101010101011011001010010101010101010001101010010010101010101101010100010101010101010100101010100101010101010101010101010010101000101010111010010110100101001010101101010101010110101001001010101001101010101010101010...

output:

11025428

result:

ok 1 number(s): "11025428"

Test #17:

score: 0
Accepted
time: 28ms
memory: 52852kb

input:

101010101010101101001010101010101011010110010101001010101010100101010101010101010101010101010101010101010110101010101010101010101010101010110101010101010101010101010011010010101010110101010101001010110101010010101010100101011101010110101010010100101010010101101010101010101010101101010101010011010101...

output:

16770603

result:

ok 1 number(s): "16770603"

Test #18:

score: 0
Accepted
time: 20ms
memory: 50792kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010101010101010101010110101001010101010101010101010101010101010101010101010101010101010101...

output:

188646665

result:

ok 1 number(s): "188646665"

Test #19:

score: 0
Accepted
time: 7ms
memory: 48768kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010110101010101010101010101010101010101010101010101010101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

1815374361

result:

ok 1 number(s): "1815374361"

Test #20:

score: 0
Accepted
time: 7ms
memory: 50796kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

16307938305

result:

ok 1 number(s): "16307938305"

Test #21:

score: 0
Accepted
time: 17ms
memory: 48632kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

184171987292

result:

ok 1 number(s): "184171987292"

Test #22:

score: 0
Accepted
time: 11ms
memory: 50740kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

128638532514

result:

ok 1 number(s): "128638532514"

Test #23:

score: 0
Accepted
time: 11ms
memory: 50724kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

434363327492

result:

ok 1 number(s): "434363327492"

Test #24:

score: 0
Accepted
time: 13ms
memory: 50788kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

493093081142

result:

ok 1 number(s): "493093081142"

Test #25:

score: 0
Accepted
time: 11ms
memory: 50876kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

669857207760

result:

ok 1 number(s): "669857207760"

Test #26:

score: 0
Accepted
time: 11ms
memory: 50668kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

468842033630

result:

ok 1 number(s): "468842033630"

Test #27:

score: 0
Accepted
time: 18ms
memory: 50688kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

639985723182

result:

ok 1 number(s): "639985723182"

Test #28:

score: 0
Accepted
time: 20ms
memory: 50876kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

391921131742

result:

ok 1 number(s): "391921131742"

Test #29:

score: 0
Accepted
time: 11ms
memory: 50740kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

781249375000

result:

ok 1 number(s): "781249375000"

Test #30:

score: 0
Accepted
time: 15ms
memory: 50796kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

781249997600

result:

ok 1 number(s): "781249997600"