QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505283#5066. String-dle Counthos_lyricWA 69ms5516kbC++146.0kb2024-08-05 01:01:502024-08-05 01:01:50

Judging History

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

  • [2024-08-05 01:01:50]
  • 评测
  • 测评结果:WA
  • 用时:69ms
  • 内存:5516kb
  • [2024-08-05 01:01:50]
  • 提交

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 = 1000000007;
using Mint = ModInt<MO>;


constexpr int A = 26;

int N, K;
char S[10'010][20], T[10'010][20];

int main() {
  for (; ~scanf("%d%d", &N, &K); ) {
    for (int n = 0; n < N; ++n) {
      scanf("%s", S[n]);
      scanf("%s", T[n]);
    }
    
    vector<int> can(K, (1 << A) - 1);
    for (int n = 0; n < N; ++n) {
      for (int k = 0; k < K; ++k) {
        const int a = S[n][k] - 'A';
        can[k] &= (T[n][k] == 'O') ? (1 << a) : ~(1 << a);
      }
    }
    
    bool ok = true;
    vector<int> L(A, 0), R(A, N);
    for (int n = 0; n < N; ++n) {
      vector<string> ts(A);
      for (int k = 0; k < K; ++k) if (T[n][k] == 'O') {
        const int a = S[n][k] - 'A';
        ts[a] += '-';
      }
      for (int k = 0; k < K; ++k) if (T[n][k] != 'O') {
        const int a = S[n][k] - 'A';
        ts[a] += T[n][k];
      }
      for (int a = 0; a < A; ++a) {
        const int len = ts[a].size();
        const int l = count(ts[a].begin(), ts[a].end(), '-');
        ok = ok && (ts[a] == string(l, '-') + string(len - l, 'x'));
        chmax(L[a], l);
        if (l < len) chmin(R[a], l);
      }
    }
    for (int a = 0; a < A; ++a) {
      ok = ok && (L[a] <= R[a]);
    }
    vector<int> as;
    for (int a = 0; a < A; ++a) for (int i = 0; i < L[a]; ++i) as.push_back(a);
    const int asLen = as.size();
    ok = ok && ((int)asLen <= K);
    
    Mint ans = 0;
    if (ok) {
cerr<<"L = "<<L<<endl;
cerr<<"R = "<<R<<endl;
cerr<<"as = "<<as<<endl;
      int amari = 0;
      for (int a = 0; a < A; ++a) if (L[a] < R[a]) amari |= 1 << a;
      vector<Mint> dp(1 << K, 0);
      dp[0] = 1;
      for (int p = 0; p < (1 << K) - 1; ++p) if (dp[p]) {
        const int k = __builtin_popcount(p);
        for (int i = 0; i < asLen; ++i) if (!(p & 1 << i)) {
          if (i - 1 >= 0 && as[i - 1] == as[i] && !(p & 1 << (i - 1))) continue;
          if (can[k] & 1 << as[i]) {
            dp[p | 1 << i] += dp[p];
          }
        }
        int ama = amari;
        for (int i = 0; i < asLen; ++i) if (!(p & 1 << i)) ama &= ~(1 << as[i]);
        for (int i = asLen; i < K; ++i) if (!(p & 1 << i)) {
          dp[p | 1 << i] += dp[p] * __builtin_popcount(can[k] & ama);
          break;
        }
      }
      ans = dp.back();
    }
    printf("%u\n", ans.x);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

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

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

score: 0
Accepted
time: 61ms
memory: 5460kb

input:

19 19
ZAZZZAZZZZZZZZZZAAZ
x-xxxxxxxxxxxxxxxxx
ZBZBZZBZZZZBZZZZBZZ
x-xxxxxxxxxxxxxxxxx
CZZCZZCZCZZCZZZCZZZ
-xxxxxxxxxxxxxxxxxx
ZDZZDZDZZZZZZZZZZZZ
x-xxxxxxxxxxxxxxxxx
ZZZZEEZEZZEEZZZZZZZ
xxxx-xxxxxxxxxxxxxx
ZZZZZFZZZZZZZZZZZZF
xxxxx-xxxxxxxxxxxxx
ZZGGZZZZZZZZGGGZZGZ
xx-xxxxxxxxxxxxxxxx
HHHHZHZZZZHHZZ...

output:

182644947

result:

ok 1 number(s): "182644947"

Test #9:

score: 0
Accepted
time: 69ms
memory: 5360kb

input:

19 19
AZZZZZAZZZZZZAZZZZZ
-xxxxxxxxxxxxxxxxxx
ZZZBZZBBZZBBZZBZBZB
xxx-xxxxxxxxxxxxxxx
ZZZZZCCZZZZZZZZZZZZ
xxxxx-xxxxxxxxxxxxx
ZZZDZDZZZZZZDZZZZDZ
xxx-xxxxxxxxxxxxxxx
EZZZZZZZEZZZZZZZZZZ
-xxxxxxxxxxxxxxxxxx
ZZZZZZZZFFZZZZZZZZZ
xxxxxxxx-xxxxxxxxxx
ZZZZZZZZZZZZZGZZZZG
xxxxxxxxxxxxx-xxxxx
ZZHHZZHZZZHZZH...

output:

791604390

result:

ok 1 number(s): "791604390"

Test #10:

score: 0
Accepted
time: 65ms
memory: 5500kb

input:

19 19
ZAZAZZZZAZZZZZZAZZZ
x-xxxxxxxxxxxxxxxxx
ZBZZZBZZBZZZZZZZBZZ
x-xxxxxxxxxxxxxxxxx
ZZZZZZZCZCZZZZZZZZZ
xxxxxxx-xxxxxxxxxxx
ZDDDZZZDZZZZZZZZZZZ
x-xxxxxxxxxxxxxxxxx
ZEZZEEZZZZZEZZEZZZE
x-xxxxxxxxxxxxxxxxx
ZZZFZZZZFZZZZZFZFFZ
xxx-xxxxxxxxxxxxxxx
ZZZGGZZZZZZZZZZZZZG
xxx-xxxxxxxxxxxxxxx
ZHHZZZZZZZZZHZ...

output:

721023482

result:

ok 1 number(s): "721023482"

Test #11:

score: 0
Accepted
time: 68ms
memory: 5388kb

input:

19 19
ZZZAZZZAZZZAZZAAZZA
xxx-xxxxxxxxxxxxxxx
BBZZBZZBZZZBBBZZBZB
-xxxxxxxxxxxxxxxxxx
ZZCZCCZCCCZCCZCCZZC
xx-xxxxxxxxxxxxxxxx
ZDZZDZDDZDZZZDZDDZZ
x-xxxxxxxxxxxxxxxxx
EEZEZEZEZZZZEZEEEZE
-xxxxxxxxxxxxxxxxxx
ZZZFZFFFZFFFFZFFFFZ
xxx-xxxxxxxxxxxxxxx
ZGZGGZGZGZGGGZZGGGZ
x-xxxxxxxxxxxxxxxxx
ZHZZZHZHHZZHZZ...

output:

432987142

result:

ok 1 number(s): "432987142"

Test #12:

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

input:

19 19
ZAAZAZZAAZAZZZZZZAA
x-xxxxxxxxxxxxxxxxx
ZBZBBBZZBZZBZBBBZZB
x-xxxxxxxxxxxxxxxxx
CZCCCZZCCCZZZCCZZCC
-xxxxxxxxxxxxxxxxxx
DZDZDDDDZDDZZZZZZDD
-xxxxxxxxxxxxxxxxxx
ZEEEEEZZEEZEZZZZEZE
x-xxxxxxxxxxxxxxxxx
ZZFFZZZFZFFFZZFFZFF
xx-xxxxxxxxxxxxxxxx
ZZGZZZGZGZZGZZZGZGG
xx-xxxxxxxxxxxxxxxx
HZZZHZHZZZZZHZ...

output:

562846236

result:

ok 1 number(s): "562846236"

Test #13:

score: 0
Accepted
time: 69ms
memory: 5308kb

input:

19 19
AZZZZAZAZZZAZAZZAZZ
-xxxxxxxxxxxxxxxxxx
BZBBZBZZZBBZBZBBZBZ
-xxxxxxxxxxxxxxxxxx
ZCCCCCZCCZCCZZCZZCC
x-xxxxxxxxxxxxxxxxx
DDDDZDDZDZDZDDDZZDZ
-xxxxxxxxxxxxxxxxxx
EZZEZZEZZEEZEEZZEEZ
-xxxxxxxxxxxxxxxxxx
ZZZZFZZFZZZFZZZZFZZ
xxxx-xxxxxxxxxxxxxx
GGZGZGGZGGZGGZZZGGG
-xxxxxxxxxxxxxxxxxx
ZHZZHHHHHZZHHH...

output:

241578701

result:

ok 1 number(s): "241578701"

Test #14:

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

input:

26 19
AAAAAAAAAAAAAAAAAAA
-------------------
BBBBBBBBBBBBBBBBBBB
-------------------
CCCCCCCCCCCCCCCCCCC
-------------------
DDDDDDDDDDDDDDDDDDD
-------------------
EEEEEEEEEEEEEEEEEEE
-------------------
FFFFFFFFFFFFFFFFFFF
-------------------
GGGGGGGGGGGGGGGGGGG
-------------------
HHHHHHHHHHHHHH...

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 64ms
memory: 5516kb

input:

19 19
ZAZZZZZZZZZZZZZZZZZ
x-xxxxxxxxxxxxxxxxx
ZZZZZZZZBZZZZZZZZZZ
xxxxxxxx-xxxxxxxxxx
ZZZZZZZZZZZZZZCZZZZ
xxxxxxxxxxxxxx-xxxx
ZZDZZZZZZZZZZZZZZZZ
xx-xxxxxxxxxxxxxxxx
ZZZZZZZZZZZZZEZZZZZ
xxxxxxxxxxxxx-xxxxx
ZZZZZZZZZZZZZZZFZZZ
xxxxxxxxxxxxxxx-xxx
ZZZZZZZZZZZGZZZZZZZ
xxxxxxxxxxx-xxxxxxx
ZZZZZZZZZZZZZZ...

output:

143269517

result:

ok 1 number(s): "143269517"

Test #16:

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

input:

1 3
PYP
xxx

output:

13824

result:

ok 1 number(s): "13824"

Test #17:

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

input:

3 3
ENP
xxx
PJK
xxx
BZL
xxx

output:

5832

result:

ok 1 number(s): "5832"

Test #18:

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

input:

5 3
LLK
xxx
WUQ
xxx
RDR
xxx
EUZ
xxx
FBU
xxx

output:

3375

result:

ok 1 number(s): "3375"

Test #19:

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

input:

10 3
PKX
xxx
FBB
xxx
JSZ
xxx
RGB
xxx
BOS
x-x
OPG
Oxx
SHW
xxx
RDM
xxx
LHO
xx-
NBP
xxx

output:

81

result:

ok 1 number(s): "81"

Test #20:

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

input:

15 3
DCJ
xxx
NCW
xxx
WDE
xxx
MAO
xOO
JXC
xxx
OBO
xxO
ALB
-xx
JWZ
xxx
QXK
xxx
FZW
xxx
VAJ
xOx
VHL
xxx
AZG
-x-
BWQ
xxx
GWB
Oxx

output:

1

result:

ok 1 number(s): "1"

Test #21:

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

input:

20 3
FPR
xxx
FHF
xxx
WBH
xxx
XGA
xx-
QAC
x-x
JYS
xxx
ARR
Oxx
AAF
Oxx
LDY
xxx
ESD
xxx
QMB
xxx
EMS
xxx
UFT
xx-
JCK
xxO
YBH
xxx
KEN
-xx
FVL
xxx
PJP
xxx
DRB
xxx
UDL
xxx

output:

1

result:

ok 1 number(s): "1"

Test #22:

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

input:

10000 3
XIX
xxx
RRY
xxx
RJB
xxx
XUT
x-x
BQB
xxx
RDP
xxx
EEX
xxx
DYJ
xxx
NHI
-xx
VMD
xxx
IVU
xxO
VBR
xxx
CJE
Oxx
BCF
x-x
WSS
xxx
ARP
xxx
HYR
xxx
YTO
xxx
NLJ
-xx
NMU
-xO
GUY
x-x
KAC
xx-
UYQ
-xx
OBU
xxO
ANA
xOx
HCK
x-x
GOX
xxx
ZNU
xOO
LSH
xxx
COM
Oxx
OAM
xxx
HNF
xOx
VOX
xxx
CZM
Oxx
KXM
xxx
MAN
xx-
RUG
...

output:

1

result:

ok 1 number(s): "1"

Test #23:

score: -100
Wrong Answer
time: 1ms
memory: 3732kb

input:

1 5
VYQWB
x-xxx

output:

777924

result:

wrong answer 1st numbers differ - expected: '835275', found: '777924'