QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#903275#10089. Elegia❄️'s Mindhos.lyric🐇AC ✓5484ms344960kbC++147.1kb2025-02-17 06:27:272025-02-17 06:27:27

Judging History

This is the latest submission verdict.

  • [2025-02-17 06:27:27]
  • Judged
  • Verdict: AC
  • Time: 5484ms
  • Memory: 344960kb
  • [2025-02-17 06:27:27]
  • Submitted

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>;

/*
  Q = {+-1, +-i, +-j, +-k} (quaternion)
  given a, b, c: Q -> \A s.t. a[+-1] = b[+-1] = c[+-1] = 0
  want tensor \sum[x,y,z\in Q] [xyz = -1] a[x] b[y] c[z]
  
  1-dimensional representation of Q:
    trivial
    sign, kernal <i>
    sign, kernal <j>
    sign, kernal <k>
  
  a'[i] := a[i] + a[-i], etc.
  
  + (+ a'[i] + a'[j] + a'[k]) (b...) (c...)
  - (- a'[i] + a'[j] + a'[k]) (b...) (c...)
  - (+ a'[i] - a'[j] + a'[k]) (b...) (c...)
  - (+ a'[i] + a'[j] - a'[k]) (b...) (c...)
  = 4 \sum[{x,y,z}={i,j,k}] a'[x] b'[y] c'[z]
  
  a''[i] := a[i] - a[-i], etc.
  want \sum[{x,y,z}={i,j,k}] (-xyz) a''[x] b''[y] c''[z]
  
  000    000    000    000    
  00+    00+    00+    00+    
  0-0    000    000    000    
                              
  00-    00-    00-    ++0    
  000 -> 000 -> 000 -> 000 -> 
  +00    ++0    ++0    ++0    
                              
  0+0    0+0    ++0    ++0    
  -00    -00    000    000    
  000    0+0    ++0    ++0    
  
  - (a''[i] + a''[j] + a''[k]) b''[k] c''[j]
  - a''[k] (b''[j] + b''[k] + b''[i]) c''[i]
  - a''[j] b''[i] (c''[k] + c''[i] + c''[j])
  + (a''[j] + a''[k]) (b''[k] + b''[i]) (c''[i] + c''[j])
  + a''[i] b''[j] c''[k]
*/

int N;
char S[11'000'000];

int SIX[10];
vector<Mint> f[10][9][3];

Mint rec(int n, int u) {
  if (n == 0) {
    return f[0][u][0][0] * f[0][u][1][0] * f[0][u][2][0];
  } else {
    --n;
#define rep(v) \
    for (int h = 0; h < SIX[n]; ++h) {\
      const Mint i0 = f[n + 1][u][v][h + 0 * SIX[n]];\
      const Mint j0 = f[n + 1][u][v][h + 1 * SIX[n]];\
      const Mint k0 = f[n + 1][u][v][h + 2 * SIX[n]];\
      const Mint k1 = f[n + 1][u][v][h + 3 * SIX[n]];\
      const Mint j1 = f[n + 1][u][v][h + 4 * SIX[n]];\
      const Mint i1 = f[n + 1][u][v][h + 5 * SIX[n]];\
      const Mint i = i0 + i1, ii = i0 - i1;\
      const Mint j = j0 + j1, jj = j0 - j1;\
      const Mint k = k0 + k1, kk = k0 - k1;\
      f[n][0][v][h] = i + j + k;\
      f[n][1][v][h] = j + k - i;\
      f[n][2][v][h] = k + i - j;\
      f[n][3][v][h] = i + j - k;\
    
    rep(0)
      f[n][4][0][h] = ii + jj + kk;
      f[n][5][0][h] = kk;
      f[n][6][0][h] = jj;
      f[n][7][0][h] = jj + kk;
      f[n][8][0][h] = ii;
    }
    rep(1)
      f[n][4][1][h] = kk;
      f[n][5][1][h] = jj + kk + ii;
      f[n][6][1][h] = ii;
      f[n][7][1][h] = kk + ii;
      f[n][8][1][h] = jj;
    }
    rep(2)
      f[n][4][2][h] = jj;
      f[n][5][2][h] = ii;
      f[n][6][2][h] = kk + ii + jj;
      f[n][7][2][h] = ii + jj;
      f[n][8][2][h] = kk;
    }
#undef rep
    Mint ret = 0;
    for (int uu = 0; uu < 1; ++uu) ret += rec(n, uu);
    for (int uu = 1; uu < 4; ++uu) ret -= rec(n, uu);
    for (int uu = 4; uu < 7; ++uu) ret -= 4 * rec(n, uu);
    for (int uu = 7; uu < 9; ++uu) ret += 4 * rec(n, uu);
    return ret;
  }
}

int main() {
  for (; ~scanf("%d", &N); ) {
    scanf("%s", S);
    
    SIX[0] = 1;
    for (int n = 1; n <= N; ++n) SIX[n] = SIX[n - 1] * 6;
    for (int n = 0; n < N; ++n) for (int u = 0; u < 9; ++u) for (int v = 0; v < 3; ++v) f[n][u][v].assign(SIX[n], 0);
    for (int v = 0; v < 3; ++v) f[N][0][v].assign(SIX[N], 0);
    for (int v = 0; v < 3; ++v) for (int h = 0; h < SIX[N]; ++h) f[N][0][v][h] = (S[h] - '0') & (S[SIX[N] - 1 - h] - '0');
    Mint ans = rec(N, 0);
    ans *= Mint(8).pow(-N);
    printf("%u\n", ans.x);
  }
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
111111

output:

24

result:

ok answer is '24'

Test #2:

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

input:

1
110111

output:

0

result:

ok answer is '0'

Test #3:

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

input:

2
000001001000010000000010000100100000

output:

24

result:

ok answer is '24'

Test #4:

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

input:

2
111111111111111111111111111111111111

output:

576

result:

ok answer is '576'

Test #5:

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

input:

1
000000

output:

0

result:

ok answer is '0'

Test #6:

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

input:

1
111100

output:

0

result:

ok answer is '0'

Test #7:

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

input:

3
110111110110101101111111101111110111111111111111111111011111111111111110111111111011111111111101111111111111111111111101111111111111111111111111110011111010111111110001111111111111111111110111111111111111111110101111

output:

6984

result:

ok answer is '6984'

Test #8:

score: 0
Accepted
time: 5436ms
memory: 344184kb

input:

9
0111110101111111111111111111111111101111111111110110111111111111111111011101111110111111111011111111111110110111110110111111110111111111110011111111111111111111111110011111111111111001111111111111111011111101111111111111111111111011111110111111111111110110111111110111111011110111011111111101111111...

output:

866504671

result:

ok answer is '866504671'

Test #9:

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

input:

2
111111111100111111111110110111111011

output:

192

result:

ok answer is '192'

Test #10:

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

input:

4
1111110111101111111101010111111111111111110111111111111111111011111111111101011111110111111111111110110111110101111111111011111111101110101111111111111111111111111110011111111111110111111111110111111111101111011011011111111111111111111111110111110110111101111111111101011111111111111111111111011111...

output:

174192

result:

ok answer is '174192'

Test #11:

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

input:

5
1001111111101111111111111111111011111101111011111111011111111101111111111111110110111111111111111111111111111111011111111111111111111111111111111011110111111111111110011111011111111111111101110111111111111111111001111111011111101111111111111111111111111111101111111110111101111111111111101101101111...

output:

3948120

result:

ok answer is '3948120'

Test #12:

score: 0
Accepted
time: 8ms
memory: 4864kb

input:

6
1111111101100110110111111111111111111111111111111011111111111110101111110111111111111100101111111111111111111111101111111111111111111011111110111101111011111111011110011111101110110111111111110011001110111111111011111101111011111101111110011111111111101110111111111111111111111111111111111111111101...

output:

95252376

result:

ok answer is '95252376'

Test #13:

score: 0
Accepted
time: 67ms
memory: 13056kb

input:

7
1111111111101111011110111111011110100111011110110101111111111111101101111011111010111111111111101011111110011101111111111111111101111111111010111111111101111111111110011111111101101111111110110111111111011111111011011111111111111111111111010101111101011111110111111111101111111111110111111111110110...

output:

295411814

result:

ok answer is '295411814'

Test #14:

score: 0
Accepted
time: 5427ms
memory: 344184kb

input:

9
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok answer is '0'

Test #15:

score: 0
Accepted
time: 5484ms
memory: 344244kb

input:

9
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

452982186

result:

ok answer is '452982186'

Test #16:

score: 0
Accepted
time: 5449ms
memory: 344184kb

input:

9
0000111111101111101011101111100011011001011101100111111010001101101101101100110111100100011110111001011111000111111010010100111011101111011011011100101100001111100011110001111010101110111101110111011010011101011001101101011101111110110001101010110111001101101110010011010011100011111011110101110101...

output:

614920512

result:

ok answer is '614920512'

Test #17:

score: 0
Accepted
time: 5434ms
memory: 344184kb

input:

9
0011011111111111111111001111111111011101100111111110111111110011011111001110011001111110111101011111111011111101111111101001000111101011011001001001111001111111111110101111011111011110111100111111011111111111001110111001111111111111100001111110101011011110001011011110111011100111011111111111011111...

output:

251072287

result:

ok answer is '251072287'

Test #18:

score: 0
Accepted
time: 5452ms
memory: 344180kb

input:

9
0101101111110101111100111111111101111111111101111111111111111111110010111110001111011111111111101111111101110111111111111111011110111111111001011001101111111111011111111011101001111111110001011111111111001110011001011111111111111011110011110111111111111111111111111011111011100101111100111111011011...

output:

157940654

result:

ok answer is '157940654'

Test #19:

score: 0
Accepted
time: 5432ms
memory: 344504kb

input:

9
0111111111111111011111111111110111111110111111011101011111101110111011111011101111110101101111110111011011111111011111001111111011111111111011111110111110011111111001111110110111111101111111111101111111111011111111111111110111111011000111111111111111111011111111111111111011110110111111110011111111...

output:

180048062

result:

ok answer is '180048062'

Test #20:

score: 0
Accepted
time: 5437ms
memory: 344152kb

input:

9
0110111111111111111110110111111101111111111111111111111111111111111101111111111111111111111111111111111101111110111111111011111111111111111011111111111111110111111111111101111110111111111110111111111111111111111101101111111111111111101111111111110111111011111011111111111011110111111111111111111000...

output:

282572133

result:

ok answer is '282572133'

Test #21:

score: 0
Accepted
time: 5445ms
memory: 344960kb

input:

9
0011111111011111111111101111111111111111111111111111110011011111111111101111111111111101110111011111011111111111111111111101111111111111111011111111011111111111111011111111111111111111111111111111111111111111111111111111111110011101111111111011011011111111111111111111111011111111111101111111111111...

output:

696888724

result:

ok answer is '696888724'

Test #22:

score: 0
Accepted
time: 5430ms
memory: 344328kb

input:

9
0111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111101101111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111110111111111111111111111111111...

output:

749364971

result:

ok answer is '749364971'

Test #23:

score: 0
Accepted
time: 5431ms
memory: 344120kb

input:

9
0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111110111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

966399738

result:

ok answer is '966399738'

Test #24:

score: 0
Accepted
time: 5435ms
memory: 344744kb

input:

9
1110011111011111111111110111111100110111111111111111111111011111110111111110111111110011011110111111100111111101011110111111101111111101111111111111111111010111111111111011110111110111111111111111111111111111110111111011111111010111011111111111111111111111110111111111111110111111110111111111111111...

output:

702453964

result:

ok answer is '702453964'

Test #25:

score: 0
Accepted
time: 604ms
memory: 60380kb

input:

8
0111111111111111111111111111111111111101001011111111011110101101101111111111111111111111111111111111111111111111111111111111110111111111111110111111111111111111111110011111111111111111111111111101111111111101011101111111110111111111111111111111101111111111101111101111101111101111011111111111011111...

output:

44138593

result:

ok answer is '44138593'

Test #26:

score: 0
Accepted
time: 602ms
memory: 60924kb

input:

8
0111110111111111111111111111111111111111111111111111111100111111111111111101111101111111111111011100111111111111111111111111111111111101110111111111101111111111101111110011111011011011111111111111111101111111111110111111111111101111111111111111111111111110111111111010111111001111101011111110111111...

output:

61612038

result:

ok answer is '61612038'

Test #27:

score: 0
Accepted
time: 603ms
memory: 61700kb

input:

8
0111111111111100111101101111111111101110110111111111111111111001111101001111111111011111111111111111111111011011010101111101111011011011111111111111111101101111110011101011011100110110111111111111011111110111101111001111111111111111100011111101110011110101111111111111111101101100111010111100111101...

output:

148483028

result:

ok answer is '148483028'

Extra Test:

score: 0
Extra Test Passed