QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120136#6185. Best Problemhos_lyricAC ✓66ms86456kbC++148.0kb2023-07-06 14:11:142024-04-05 16:19:18

Judging History

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

  • [2024-04-05 16:19:18]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:66ms
  • 内存:86456kb
  • [2024-04-05 16:19:14]
  • hack成功,自动添加数据
  • (/hack/587)
  • [2024-04-05 16:05:56]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:60ms
  • 内存:86312kb
  • [2024-04-05 16:05:44]
  • hack成功,自动添加数据
  • (/hack/586)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 14:11:16]
  • 评测
  • 测评结果:100
  • 用时:54ms
  • 内存:86276kb
  • [2023-07-06 14:11:14]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


/*
  orz
  
  0[0101]0 -> 0[1010]0   0.... -> ....0
  0[0101]1 -> 0[1010]1   0...1 -> .....
  1[0101]0 -> 1[1010]0   ..... -> 1...0
  1[0101]1 -> 1[1010]1   ....1 -> 1....
*/

void experiment() {
  for (int n = 1; n <= 24; ++n) {
    vector<int> dp(1 << n, 0);
    vector<int> im(1 << n, -1);
    for (int p = 0; p < 1 << n; ++p) {
      for (int i = 0; i + 4 <= n; ++i) if ((p >> i & 15) == 10) {
        if (chmax(dp[p], 1 + dp[p ^ 15 << i])) {
          im[p] = i;
        }
      }
    }
    for (int p = 0; p < 1 << n; ++p) {
      string s(n + 1, '.');
      if ((p >> 0 & 1) == 1) s[0] = '1';
      for (int i = 1; i < n; ++i) {
        if ((p >> (i-1) & 3) == 0) s[i] = '0';
        if ((p >> (i-1) & 3) == 3) s[i] = '1';
      }
      if ((p >> (n-1) & 1) == 0) s[n] = '0';
      
      auto dump = [&]() -> void {
        cerr << "p = ";
        for (int i = 0; i < n; ++i) cerr << (p >> i & 1);
        cerr << endl;
        cerr << "s = " << s << endl;
        cerr << "dp[p] = " << dp[p] << ", im[p] = " << im[p] << endl;
      };
      
      vector<pair<char, int>> ics;
      for (int i = 0; i <= n; ++i) if (s[i] != '.') {
        ics.emplace_back(i, s[i]);
      }
      const int icsLen = ics.size();
      
      bool done = false;
      
      // 0...1 -> .....
      // 0.......1 -> ....0...1
      for (int j = 0; j < icsLen - 1; ++j) {
        if (ics[j].second == '0' &&
            ics[j + 1].second == '1' &&
            (ics[j + 1].first - ics[j].first) % 4 == 0) {
          done = true;
          const int i = ics[j].first;
          if (dp[p] != 1 + dp[p ^ 15 << i]) {
            cerr << "FAIL " << __LINE__ << " " << i << endl;
            dump();
            assert(false);
          }
        }
      }
      if (done) continue;
      
      // 0.... -> ....0 (no 1 to the right)
      for (int j = 0; j < icsLen; ++j) {
        if (ics[j].second == '0' &&
            (j + 1 == icsLen || ics[j + 1].second == '0')) {
          const int i = ics[j].first;
          if (i + 4 <= n && s.substr(i, 5) == "0....") {
            done = true;
            if (dp[p] != 1 + dp[p ^ 15 << i]) {
              cerr << "FAIL " << __LINE__ << " " << i << endl;
              dump();
              assert(false);
            }
          }
        }
      }
      // ....1 -> 1.... (no 0 to the left)
      for (int j = 0; j < icsLen; ++j) {
        if (ics[j].second == '1' &&
            (j == 0 || ics[j - 1].second == '1')) {
          const int i = ics[j].first - 4;
          if (i >= 0 && s.substr(i, 5) == "....1") {
            done = true;
            if (dp[p] != 1 + dp[p ^ 15 << i]) {
              cerr << "FAIL " << __LINE__ << " " << i << endl;
              dump();
              assert(false);
            }
          }
        }
      }
      if (done) continue;
      
      for (int j = 0; j < icsLen - 1; ++j) {
        if (ics[j].second == '0' &&
            ics[j + 1].second == '1' &&
            (ics[j + 1].first - ics[j].first >= 5)) {
          done = true;
          const int i0 = ics[j].first;
          const int i1 = ics[j + 1].first - 4;
          if (dp[p] != 1 + max(dp[p ^ 15 << i0], dp[p ^ 15 << i1])) {
            cerr << "FAIL " << __LINE__ << " " << i0 << " " << i1 << endl;
            dump();
            assert(false);
          }
        }
      }
      if (done) continue;
      
      for (int i = 0; i + 4 <= n; ++i) if (s.substr(i, 5) == ".....") {
        assert((p >> i & 15) == 10);
        done = true;
        if (dp[p] != 1 + dp[p ^ 15 << i]) {
          cerr << "FAIL " << __LINE__ << " " << i << endl;
          dump();
          assert(false);
        }
        break;
      }
      if (done) continue;
      
      if (dp[p] != 0) {
        cerr << "FAIL " << __LINE__ << endl;
        dump();
        assert(false);
      }
    }
    cerr << "DONE n = " << n << endl;
  }
}


int N;
char S[5'000'010];

int main() {
  // experiment();
  
  for (; ~scanf("%s", S); ) {
    N = strlen(S);
    
    Int ans = 0;
    
    int psLen = 0;
    vector<pair<int, char>> ps(N + 3);
    auto add = [&](int i, char c) -> void {
      ps[psLen++] = make_pair(i, c);
      if (psLen >= 2) {
        const int ii = ps[psLen - 2].first;
        const char cc = ps[psLen - 2].second;
        if (cc == '0' && c == '1' && (i - ii) % 4 == 0) {
          ans += (i - ii) / 4;
          psLen -= 2;
        }
      }
    };
    
    // 0...1 -> .....
    add(-1, '1');
    if (S[0] == '1') add(0, '1');
    for (int i = 1; i < N; ++i) {
      if (S[i - 1] == S[i]) add(i, S[i]);
    }
    if (S[N - 1] == '0') add(N, '0');
    add(N + 1, '0');
    
    ps.resize(psLen);
// cerr<<"ans = "<<ans<<", ps = "<<ps<<endl;
    
    // 0.... -> ....0
    for (int j = psLen - 1; --j >= 0; ) if (ps[j].second == '0' && ps[j + 1].second == '0') {
      const int t = (ps[j + 1].first - ps[j].first) / 4;
      ans += t;
      ps[j].first += 4 * t;
    }
    // ....1 -> 1....
    for (int j = 1; j < psLen; ++j) if (ps[j].second == '1' && ps[j - 1].second == '1') {
      const int t = (ps[j].first - ps[j - 1].first) / 4;
      ans += t;
      ps[j].first -= 4 * t;
    }
// cerr<<"ans = "<<ans<<", ps = "<<ps<<endl;
    
    // ..... -> 1...0
    vector<Int> emerge(N + 3, 0);
    for (int n = 6; n < N + 3; ++n) {
      const int t = (n - 2) / 4;
      emerge[n] = t + emerge[4 * t];
    }
// cerr<<"emerge = "<<emerge<<endl;
    
    int is[2] = {-1, -1};
    Int fs[2] = {0, 0};
    for (int j0 = 0, j1, j2; j0 < psLen; j0 = j2) {
      for (j1 = j0; j1 < psLen && ps[j1].second == '0'; ++j1) {}
      for (j2 = j1; j2 < psLen && ps[j2].second == '1'; ++j2) {}
      if (j0 == 0) {
        assert(j0 == j1);
        assert(j1 < j2);
        for (int x = 0; x < 2; ++x) {
          is[x] = ps[j2 - 1].first;
        }
      } else if (j2 == psLen) {
        assert(j0 < j1);
        assert(j1 == j2);
        for (int x = 0; x < 2; ++x) {
          fs[x] += emerge[ps[j0].first - is[x]];
        }
      } else {
        assert(j0 < j1);
        assert(j1 < j2);
        const int t = (ps[j1].first - ps[j1 - 1].first) / 4;
        int iis[2] = {-1, -1};
        Int ffs[2] = {-1, -1};
        // 0.... -> ....0
        {
          iis[0] = ps[j2 - 1].first;
          for (int x = 0; x < 2; ++x) {
            chmax(ffs[0], fs[x] + emerge[(ps[j0].first + 4 * t) - is[x]]);
          }
          ffs[0] += (Int)(j1 - j0) * t;
        }
        // ....1 -> 1....
        {
          iis[1] = ps[j2 - 1].first - 4 * t;
          for (int x = 0; x < 2; ++x) {
            chmax(ffs[1], fs[x] + emerge[ps[j0].first - is[x]]);
          }
          ffs[1] += (Int)(j2 - j1) * t;
        }
        copy(iis, iis + 2, is);
        copy(ffs, ffs + 2, fs);
      }
    }
    ans += max(fs[0], fs[1]);
    
    printf("%lld\n", ans);
  }
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10100010011001011111

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010

output:

58

result:

ok 1 number(s): "58"

Test #3:

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

input:

100011000011001011010100111110011001000110111101101001100000110101101001101111100101110001101101000001001011011111001100111010101111001110000110001100101100101001001110000111100001100110000101111110001010101100100110010001110011101011110011101111000111010111100110100011110000011111110000111110111110...

output:

302244

result:

ok 1 number(s): "302244"

Test #4:

score: 0
Accepted
time: 10ms
memory: 21812kb

input:

100101010101010101010101010101010101010101100101101010101101010110101001001010101010101101010101010010101010010101010110101010101010101010101101010110101010101010101010101010101010101010101010101010101010101010101010101010101011010101010101010101010101011010010101110101010110101010101010101010111010...

output:

3328566

result:

ok 1 number(s): "3328566"

Test #5:

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

input:

101010101010101010101101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010110...

output:

36918913

result:

ok 1 number(s): "36918913"

Test #6:

score: 0
Accepted
time: 3ms
memory: 21432kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

371689423

result:

ok 1 number(s): "371689423"

Test #7:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

3378077368

result:

ok 1 number(s): "3378077368"

Test #8:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

31250155082

result:

ok 1 number(s): "31250155082"

Test #9:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

21976748120

result:

ok 1 number(s): "21976748120"

Test #10:

score: 0
Accepted
time: 3ms
memory: 21104kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

31249989871

result:

ok 1 number(s): "31249989871"

Test #11:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

15417990032

result:

ok 1 number(s): "15417990032"

Test #12:

score: 0
Accepted
time: 3ms
memory: 21352kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

31249770935

result:

ok 1 number(s): "31249770935"

Test #13:

score: 0
Accepted
time: 66ms
memory: 86320kb

input:

001001110010100110000111011111010010000100110011010111100100011110101100000001000011001011010000100101101110001010011110010000000101110101101101001011000101011000001001110011001101111010111010000100011011111101101001000001111000001101100011011011111100001000000011001111110000100001111110111000011110...

output:

1529176

result:

ok 1 number(s): "1529176"

Test #14:

score: 0
Accepted
time: 55ms
memory: 86148kb

input:

111100101110111001010010100101010101110101100100011110100001010110101101000010100111001101110011011010010101100101010111001001100111001010111010100111010001110110000001001100001010000101011011010101010011000111010111111011011000010101101001010101010101111010101100101000010100101101110101110101011100...

output:

3453809

result:

ok 1 number(s): "3453809"

Test #15:

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

input:

010100110101010101111100101010101010010100101010010101010010010101011010101010100101010101010011100110101011010011100101010101001010101010110011001010101101101110101010101010101010100101010101100100101010101100010101001010101010101010110100101001010010100101101010101010101010101011101001010101101010...

output:

7267243

result:

ok 1 number(s): "7267243"

Test #16:

score: 0
Accepted
time: 35ms
memory: 86112kb

input:

101100101010101010100010101010101001101010101010101010101101011010100101010101001010110101010101011011001010010101010101010001101010010010101010101101010100010101010101010100101010100101010101010101010101010010101000101010111010010110100101001010101101010101010110101001001010101001101010101010101010...

output:

11025428

result:

ok 1 number(s): "11025428"

Test #17:

score: 0
Accepted
time: 30ms
memory: 86160kb

input:

101010101010101101001010101010101011010110010101001010101010100101010101010101010101010101010101010101010110101010101010101010101010101010110101010101010101010101010011010010101010110101010101001010110101010010101010100101011101010110101010010100101010010101101010101010101010101101010101010011010101...

output:

16770603

result:

ok 1 number(s): "16770603"

Test #18:

score: 0
Accepted
time: 16ms
memory: 86456kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010101010101010101010101010101010101010101010101010101010110101001010101010101010101010101010101010101010101010101010101010101...

output:

188646665

result:

ok 1 number(s): "188646665"

Test #19:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010110101010101010101010101010101010101010101010101010101010101010101010101010101010101010100101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

1815374361

result:

ok 1 number(s): "1815374361"

Test #20:

score: 0
Accepted
time: 14ms
memory: 86124kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

16307938305

result:

ok 1 number(s): "16307938305"

Test #21:

score: 0
Accepted
time: 16ms
memory: 86184kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

184171987292

result:

ok 1 number(s): "184171987292"

Test #22:

score: 0
Accepted
time: 22ms
memory: 86324kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

128638532514

result:

ok 1 number(s): "128638532514"

Test #23:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

434363327492

result:

ok 1 number(s): "434363327492"

Test #24:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

493093081142

result:

ok 1 number(s): "493093081142"

Test #25:

score: 0
Accepted
time: 16ms
memory: 86212kb

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

669857207760

result:

ok 1 number(s): "669857207760"

Test #26:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

468842033630

result:

ok 1 number(s): "468842033630"

Test #27:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

639985723182

result:

ok 1 number(s): "639985723182"

Test #28:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

391921131742

result:

ok 1 number(s): "391921131742"

Test #29:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

781249375000

result:

ok 1 number(s): "781249375000"

Test #30:

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

input:

101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

781249997600

result:

ok 1 number(s): "781249997600"

Extra Test:

score: 0
Extra Test Passed