QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201026#5019. 整数hos_lyric#65 388ms9696kbC++146.7kb2023-10-05 06:31:482024-07-04 02:16:05

Judging History

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

  • [2024-07-04 02:16:05]
  • 评测
  • 测评结果:65
  • 用时:388ms
  • 内存:9696kb
  • [2023-10-05 06:31:48]
  • 提交

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


constexpr int E = 60;

int N;
vector<Int> R;
char S[(1 << 18) + 1];


namespace brute {
Mint dp[2][1 << 11][1 << 11];
Mint run() {
  memset(dp, 0, sizeof(dp));
  auto crt = dp[0], nxt = dp[1];
  crt[0][0] = 1;
  for (int e = E; --e >= 0; ) {
    for (int i = 0; i < N; ++i) {
      const int r = R[i] >> e & 1;
      for (int p = 0; p < 1 << (i + 1); ++p) {
        fill(nxt[p], nxt[p] + (1 << N), 0);
      }
      for (int p = 0; p < 1 << i; ++p) for (int q = 0; q < 1 << N; ++q) {
        nxt[p][q | r << i] += crt[p][q];
        if ((q & 1 << i) || r) {
          nxt[p | 1 << i][q] += crt[p][q];
        }
      }
      swap(crt, nxt);
    }
    fill(nxt[0], nxt[0] + (1 << N), 0);
    for (int p = 0; p < 1 << N; ++p) if (S[p] == '1') {
      for (int q = 0; q < 1 << N; ++q) {
        nxt[0][q] += crt[p][q];
      }
    }
    swap(crt, nxt);
  }
  Mint ans = 0;
  for (int q = 0; q < 1 << N; ++q) {
    ans += crt[0][q];
  }
  return ans;
}
}  // brute


namespace slow {
Mint run() {
  vector<int> thr(N + 1);
  thr[0] = 1;
  for (int i = 1; i <= N; ++i) {
    thr[i] = thr[i - 1] * 3;
  }
  vector<int> tr(1 << N, 0);
  for (int i = 0; i < N; ++i) {
    for (int p = 0; p < 1 << i; ++p) {
      tr[p | 1 << i] = tr[p] + thr[i];
    }
  }
  // 0,1 -> 0,1,*
  vector<int> fs(thr[N], 0);
  for (int p = 0; p < 1 << N; ++p) {
    fs[tr[p]] += (S[p] - '0');
  }
  for (int i = 0; i < N; ++i) {
    for (int t = 0; t < thr[N]; ++t) {
      const int a = t / thr[i] % 3;
      if (a < 2) {
        fs[t + (2 - a) * thr[i]] += fs[t];
      }
    }
  }
// cerr<<"fs = "<<fs<<endl;
  const int mask = (1 << N) - 1;
  vector<Mint> crt(1 << N);
  crt[0] = 1;
  for (int e = E; --e >= 0; ) {
    int r = 0;
    for (int i = 0; i < N; ++i) {
      r |= (R[i] >> e & 1) << i;
    }
    vector<Mint> nxt(1 << N);
    for (int qq = 0; qq < 1 << N; ++qq) {
      for (int q = qq; ; --q &= qq) {
        /*
          q' - q \subseteq r
          
          r q q'  p
          ---------
          0 0 0   0
          0 0 1
          0 1 1   *
          1 0 0   1
          1 0 1   0
          1 1 1   *
        */
        if (!((qq - q) & ~r)) {
          const int mask0 = ((~r & ~qq) | (r & (qq - q))) & mask;
          const int mask1 = (r & ~qq) & mask;
          const int mask2 = mask - mask0 - mask1;
          const int t = tr[mask1] + 2 * tr[mask2];
// if(N<=2&&e<3)cerr<<e<<" "<<r<<" "<<q<<" "<<qq<<": "<<fs[t]<<endl;
          nxt[qq] += crt[q] * fs[t];
        }
        if (!q) break;
      }
    }
// if(e<3)cerr<<nxt<<endl;
    crt = nxt;
  }
  Mint ans = 0;
  for (int q = 0; q < 1 << N; ++q) {
    ans += crt[q];
  }
  return ans;
}
}  // slow


int main() {
  for (; ~scanf("%d", &N); ) {
    R.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &R[i]);
    }
    scanf("%s", S);
    
    const Mint ans = slow::run();
    printf("%u\n", ans.x);
  }
  return 0;
}

詳細信息

Test #1:

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

input:

2
557860450892773247 1006376652976945084
1001

output:

434419861

result:

ok 1 number(s): "434419861"

Test #2:

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

input:

2
1114627670617095929 177024338535020511
1000

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2
1149393890526355314 1070730158013930700
1001

output:

315168037

result:

ok 1 number(s): "315168037"

Test #4:

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

input:

2
971930549804858302 431201925917048822
1001

output:

713084688

result:

ok 1 number(s): "713084688"

Test #5:

score: 0
Time Limit Exceeded

input:

15
3 2 1 3 0 3 2 2 3 0 3 3 3 1 1
111100000011100110100011100000100010011010010011011101110110000011100111101101100011111100111010001010010001001111010011000000110110011111000011100100010100011010110000000010011110101111110110110100011101011101011100110000001100110111101001101001010111011000000110010...

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

18
3 0 3 2 3 3 3 3 3 3 3 1 3 3 3 3 1 3
101101001111111010001101010111101111110111100111111011010010011000101111101100011100101111101001001010010110011001001110011101011100001100100000100011001110101101110010011011000001001001000000001001010000010100010101010101010001001110100111001001110001101000111...

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

18
3 2 3 3 3 3 3 3 3 1 1 1 2 3 1 3 3 3
100101100011011110000000100100001001010001001000110011011111000010001110111011111010001011101101010101111111000111000011110001100111100001110100110100010101111100001001110110000000111100110011011011000110001010100110001101011011011101000110001000101101000110000...

output:


result:


Test #8:

score: 5
Accepted
time: 7ms
memory: 3876kb

input:

9
774618017057897470 1150648813667465147 936044467577552867 540429591977619391 492984435788926911 706491668336975855 1148409108818935103 1152305623476461243 1151646826418395103
101100111100110000011001010001100101011001010001111000000000000001011100001010001011100110010110100001000101101101101001011...

output:

762304370

result:

ok 1 number(s): "762304370"

Test #9:

score: 5
Accepted
time: 6ms
memory: 4108kb

input:

9
864195661015236599 828072363954386938 215046877307787767 125420173910435807 863300627424341495 1125890835854768063 538106264396606431 1008449764986412979 1112933880000274175
1111011011101000110000110000110110111101111110011110001110010111100001010001110110111000101011110011001000101011100011011100...

output:

91522040

result:

ok 1 number(s): "91522040"

Test #10:

score: 5
Accepted
time: 6ms
memory: 3812kb

input:

9
1060294142652751871 270953131468627965 950114304166317032 1023152535943950935 1124721212123772879 1136030244306680786 575888989072637942 576457170017579983 1071468780714196734
10010111011101001111011010000011000000111111000001100001001110001000000000101001001101110110001001111011110111101001000000...

output:

235859607

result:

ok 1 number(s): "235859607"

Test #11:

score: 5
Accepted
time: 52ms
memory: 5996kb

input:

11
1044692707433249934 1008683100277431676 999797431367270367 1143631656501850799 1098790111790735245 468268805647233519 539233207094867537 414313023104679647 1113992177660166126 1150563014851263359 1146149597257104766
111100100001011011010001100111000010001101110011110101110101010110100111111011000...

output:

238088536

result:

ok 1 number(s): "238088536"

Test #12:

score: 5
Accepted
time: 49ms
memory: 3940kb

input:

11
1136928866896019455 954477066817884159 139540257629524991 920699090857753087 852006989960417247 557707207097472255 575228611095427007 1006976729003116287 709142041517850567 1136595818501773047 1006109764096082108
100001110101001011001100010000100000111110011110100011000011111011000001010001110001...

output:

770640307

result:

ok 1 number(s): "770640307"

Test #13:

score: 5
Accepted
time: 48ms
memory: 3960kb

input:

11
1152568556892716543 1152920608551467963 216135265528237819 1116892698712710517 1125524963696923135 990737955748133887 575754796832378359 959086400709851129 571809817905978127 391758946252877613 553053934827077551
100001001101100001010110011000000001110110100101011111010110001101000110111100110011...

output:

12490130

result:

ok 1 number(s): "12490130"

Test #14:

score: 5
Accepted
time: 388ms
memory: 9620kb

input:

13
431747275278769839 792173935971856335 842168688984356222 709201683711004463 1096549254077341383 432312541824942061 423302887995576278 1152284609275166700 1150353045444060639 858881033326555901 429385610205061119 394803803773730111 792573841785221941
11101010110000000010101000000011010001110011111...

output:

711924090

result:

ok 1 number(s): "711924090"

Test #15:

score: 5
Accepted
time: 342ms
memory: 9696kb

input:

13
384952197575497562 925188207794820790 819636358341950664 1008806169945307033 485498962656536575 576170342985224059 1152884825316839167 519602798379984887 1148271257506507710 864338725486642591 141147914734645085 945751520335947454 828363124049108987
10111011110011010100110001011011010100001001111...

output:

17257245

result:

ok 1 number(s): "17257245"

Test #16:

score: 5
Accepted
time: 351ms
memory: 9668kb

input:

13
812148678079544783 531352737042856447 360252648370171639 827797221788122302 1076354330155122647 571657826460300281 995857311985303518 576390067592282047 573059687658290935 1134130623250689782 573953435640528550 1148043723132895167 576443122223672059
11010001100111100001101001010010100111100000010...

output:

513017470

result:

ok 1 number(s): "513017470"

Test #17:

score: 0
Time Limit Exceeded

input:

18
557601891651940085 863281395625602303 810348831133032447 855679530581929974 1143340273566153982 1142779849869883883 495305789849593903 1141378831228050923 539285017652624765 1151477836095937523 968834653063196607 462735989800959869 567170978455011071 936570564589289083 1089862139502785535 1274543...

output:


result:


Test #18:

score: 0
Runtime Error

input:

18
35461063007254983 250722149174607860 990787107658114938 521176448595639215 1142533318210222071 848423510290851199 936184673027902967 1035761934176939767 1152921455940040799 759980081052254206 841582125096893943 1105339004669119437 1071810531808477044 1072419334446896991 1152903339507575642 131161...

output:


result:


Test #19:

score: 0
Runtime Error

input:

18
526745011001725941 995280101634205694 1150650377238908861 1152780629645981351 378291368993988607 754341611678006135 1133780828220553215 467476844077883365 998548842292821951 1125758065340935934 1074758391215161343 359069688757419477 863137999561424871 459006511440394231 856772308259666431 2832407...

output:


result:


Test #20:

score: 0
Runtime Error

input:

18
1116852845721419519 564031047050710929 1152918474977164029 288041155646291455 647954749928207825 978368260719998815 1141854864204889983 1121382897240509261 576459613035256827 1134273717606465523 1124121994315404271 714513083207720351 1001083345502337005 642993847483219627 1143878547027000662 1139...

output:


result: