QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740177#9614. 分治hos_lyric65 119ms7896kbC++145.8kb2024-11-13 02:57:522024-11-13 02:57:52

Judging History

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

  • [2024-11-13 02:57:52]
  • 评测
  • 测评结果:65
  • 用时:119ms
  • 内存:7896kb
  • [2024-11-13 02:57:52]
  • 提交

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 <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#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; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


/*
  \sum[s \in {0,1}^L] (max length of contiguous 1's)
  
  max < k
    [x^L] (1 - x^k) / (1 - 2 x + x^(k+1))
    = [x^L] (1 - x^k) \sum[i>=0] (-1)^i (x^(k+1))^i / (1-2x)^(i+1)
*/


int L;
char S[200'010];

pair<int, int> where[200'010][2];
Mint dp[200'010][2];

/*
  10 11
  || /|
   5  6
  
  11 12
  |\ ||
  5  6
*/
pair<int, int> to(const pair<int, int> &p, int e) {
  if (!~p.first || p == make_pair(L - 1, 0) || p == make_pair(L, 1)) {
    return make_pair(-1, -1);
  }
  return make_pair(p.first + 1, (S[p.first] - '0') ? (p.second | e) : (p.second & e));
}

int main() {
  for (; ~scanf("%s", S); ) {
    L = strlen(S);
    reverse(S, S + L);
    
    Mint all = 0;
    for (int i = L; --i >= 0; ) (all *= 2) += (S[i] - '0');
    
    for (int i = 0; i <= L; ++i) for (int u = 0; u < 2; ++u) {
      where[i][u] = make_pair(i, u);
    }
    
    Mint ans = 0;
    for (int k = 1; k <= L; ++k) {
      // where: go 1^k
      for (int i = 0; i <= L; ++i) for (int u = 0; u < 2; ++u) if (!(i == L && u == 0)) {
        where[i][u] = to(where[i][u], 1);
        dp[i][u] = 0;
      }
      dp[L - 1][0] = 1;
      dp[L][0] = 1;
      dp[L][1] = 1;
      for (int i = L; --i >= 0; ) for (int u = 0; u < 2; ++u) if (!(i == L - 1 && u == 0)) {
        // 0, 1
        for (int e = 0; e < 2; ++e) {
          const auto p = to(make_pair(i, u), e);
          dp[i][u] += dp[p.first][p.second];
        }
        // 1^k $
        if (where[i][u] == make_pair(L - 1, 0) || where[i][u] == make_pair(L, 1)) {
          dp[i][u] -= 1;
        }
        // 1^k 0
        {
          const auto p = to(where[i][u], 0);
          if (~p.first) dp[i][u] -= dp[p.first][p.second];
        }
      }
// cerr<<"k = "<<k<<": "<<dp[0][0]<<endl;
// cerr<<"  where = ";for(int i=0;i<=L;++i)cerr<<"["<<where[i][0]<<","<<where[i][1]<<"] ";cerr<<endl;
// cerr<<"  dp = ";for(int i=0;i<=L;++i)cerr<<"["<<dp[i][0]<<","<<dp[i][1]<<"] ";cerr<<endl;
      ans += (all - dp[0][0]);
    }
    ans += all;
    printf("%u\n", ans.x);
  }
  return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 5916kb

input:

110

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: 10
Accepted
time: 1ms
memory: 5856kb

input:

101

output:

12

result:

ok 1 number(s): "12"

Subtask #2:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #3:

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

input:

111110

output:

198

result:

ok 1 number(s): "198"

Test #4:

score: 10
Accepted
time: 1ms
memory: 5940kb

input:

1001001

output:

253

result:

ok 1 number(s): "253"

Subtask #3:

score: 20
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 20
Accepted
time: 1ms
memory: 5788kb

input:

10100011000100111

output:

386882

result:

ok 1 number(s): "386882"

Test #6:

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

input:

111010011111010110

output:

1107742

result:

ok 1 number(s): "1107742"

Subtask #4:

score: 5
Accepted

Test #7:

score: 5
Accepted
time: 1ms
memory: 6000kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

412796008

result:

ok 1 number(s): "412796008"

Test #8:

score: 5
Accepted
time: 2ms
memory: 5928kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

818656648

result:

ok 1 number(s): "818656648"

Subtask #5:

score: 5
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #9:

score: 5
Accepted
time: 2ms
memory: 5808kb

input:

10000000100000010010011110111101101110000000000001100000011000111111010011010101010000101001110110010001100110000110111101000101001111101111001010001001011101011111010000100010111100110000001101111

output:

703266161

result:

ok 1 number(s): "703266161"

Test #10:

score: 5
Accepted
time: 2ms
memory: 7896kb

input:

110100000100001000101000010010101000110111101010110000101001001100100111000011100101110110010000001111010011101001111110110010001110011101001111010101100100010011101010101111111111010110001100100110

output:

330527406

result:

ok 1 number(s): "330527406"

Subtask #6:

score: 5
Accepted

Dependency #4:

100%
Accepted

Test #11:

score: 5
Accepted
time: 31ms
memory: 3924kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

340672883

result:

ok 1 number(s): "340672883"

Test #12:

score: 5
Accepted
time: 89ms
memory: 3808kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

555946758

result:

ok 1 number(s): "555946758"

Subtask #7:

score: 10
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #13:

score: 10
Accepted
time: 119ms
memory: 5868kb

input:

110011100110101000000110101010111111001101101011010110100100110010111110110110000111011001110000101111110111011111000110001011011011101100001100100011010010111111010110010000101001001000100001100100000001000111110100000101001011100001100011011110110101101111110011100111001010001010001111001110111100...

output:

324123594

result:

ok 1 number(s): "324123594"

Test #14:

score: 10
Accepted
time: 117ms
memory: 6012kb

input:

110100110100110110001011100000011010000010000101100100001101100100110000101000111001111100001110001001101010110010111101000100111010001011001110101010001101111010000011000010110011000011100101110100000001011100111000101111010100001101011010100101110000010001101001000100111001101101110000101101011011...

output:

209285599

result:

ok 1 number(s): "209285599"

Subtask #8:

score: 0
Time Limit Exceeded

Dependency #6:

100%
Accepted

Test #15:

score: 0
Time Limit Exceeded

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:


result:


Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

0%