QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505289#5066. String-dle Counthos_lyricAC ✓69ms5592kbC++146.1kb2024-08-05 01:14:512024-08-05 01:14:52

Judging History

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

  • [2024-08-05 01:14:52]
  • 评测
  • 测评结果:AC
  • 用时:69ms
  • 内存:5592kb
  • [2024-08-05 01:14:51]
  • 提交

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, K);
    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;
        }
      }
// cerr<<"dp = "<<dp<<endl;
      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: 1ms
memory: 3772kb

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

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

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

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

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: 5316kb

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: 68ms
memory: 5264kb

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: 5336kb

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: 5292kb

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: 68ms
memory: 5528kb

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: 3788kb

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: 68ms
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: 3800kb

input:

1 3
PYP
xxx

output:

13824

result:

ok 1 number(s): "13824"

Test #17:

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

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: 4016kb

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: 3868kb

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: 3788kb

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: 3780kb

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: 3ms
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: 0
Accepted
time: 0ms
memory: 3800kb

input:

1 5
VYQWB
x-xxx

output:

835275

result:

ok 1 number(s): "835275"

Test #24:

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

input:

3 5
UFJVJ
xxxxx
XAHKG
x-Oxx
ITJDN
--xxx

output:

150

result:

ok 1 number(s): "150"

Test #25:

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

input:

5 5
QJUFA
-xOxx
BDVNF
xxxxx
TABZV
xxxxx
KSFCQ
xxxx-
PFZOQ
xxxx-

output:

2783

result:

ok 1 number(s): "2783"

Test #26:

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

input:

10 5
DOBUN
xxxxx
POMVH
xxOxx
PNCJB
xxxxx
GCWID
xxx-x
XPPHR
xxxxx
ZMXCW
xOxxx
CBSKY
xxxxO
GTHGA
xxxx-
IIHSL
Oxxxx
TBRSZ
xxxxx

output:

1

result:

ok 1 number(s): "1"

Test #27:

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

input:

15 5
GZULJ
xxx-x
AXDPU
xxx-x
BWJIU
xxxxx
NKIND
xxxxx
YXMQF
xxxxx
RGAUS
xxxxx
VXZEJ
xxx-x
ITBNY
x-xxx
HJXRL
xxxx-
IHDML
xxxx-
GHHPP
xxxxO
PFZNR
-xxxx
MOMTI
x-x-x
UNJHO
xxxx-
EPIPE
O-xxx

output:

1

result:

ok 1 number(s): "1"

Test #28:

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

input:

20 5
WSHYB
-xx-x
CAVYO
Oxx-x
ADNZR
xxxxx
DRNVU
xxxx-
YEHWB
-xx-x
MVHPW
xxxx-
NJALD
xxx-x
SGNTS
xxxxx
DKHHP
xxxxx
GYDKZ
x-xxx
KSRVD
xxxxx
DYGKH
x-xxx
DNSME
xxxxx
DDUUJ
xxxOx
EPQGV
xxxxx
TFXTG
xxxxx
SGXNC
xxxx-
JOVUX
xxxOx
EHBYU
xxx--
LCZYD
--x-x

output:

3

result:

ok 1 number(s): "3"

Test #29:

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

input:

10000 5
UERNA
xxxx-
KIWJZ
xxxxx
LPMLP
xxxxx
WVPCT
x-xx-
SLFMH
xxxxx
HTZGM
xOxxx
GFTSP
xx-xx
PRBTN
xxx-x
XCOWY
xxxxx
EAHPE
x-xxx
XWFLX
xxxxx
ZHSVX
xxx-x
YQHKK
x-xxx
QWKNH
-xxxx
LBKBU
xxxxx
TCMXG
-xxxx
PQUMQ
x-xxx
JFWSJ
xxxxx
JSQFA
xx-x-
OXKVR
xxx-x
OWMXL
xxxxx
WJETS
xxx-x
BPNFO
xxxxx
BFLCW
xxxxx
EWAQ...

output:

1

result:

ok 1 number(s): "1"

Test #30:

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

input:

1 10
UZWZMLRBON
-xxxx-x--x

output:

108066093

result:

ok 1 number(s): "108066093"

Test #31:

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

input:

3 10
CYGFEKBVZY
xxx-xxxxxx
KNRFGBVTVK
x-x-xxx-xx
RRSEPXGYLJ
xxxx--xxxx

output:

322428370

result:

ok 1 number(s): "322428370"

Test #32:

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

input:

5 10
VSVMKIMLTX
OxxxOxxx-x
QKDDMDRUCB
x-xxxx-xxx
UNQAFDUZQX
xxxxxxx-xx
VUUSNBQTFE
Oxxxxxx-x-
NKAXCIVSFD
x-xxxx-xxx

output:

7078784

result:

ok 1 number(s): "7078784"

Test #33:

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

input:

10 10
ZNASODMTHF
xxxx-xxO-x
AGKLZJSLIC
xx-xxxxx-x
WJVQUIBCPS
-xx-x--xxx
KHVLHJGWLM
-xxxOxx-xx
UOJUVRJXKT
xOxxxxx---
GXTGEQBJPZ
x--xx--xxx
YQZQWBCTYH
x-xx-OxOx-
FCPCTHSSUK
xxxx--xxx-
WUQKPNYQWL
xx--xxxxOx
JREXWEWTJA
xxxO-xxOxx

output:

15

result:

ok 1 number(s): "15"

Test #34:

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

input:

15 10
BSRHUHFKDB
xx---xxxxx
IYWQJKDFBK
xxxx-xxxxx
EEDAEFQMMQ
xxx-xxx-xx
OQBUXEEWXL
xxx--xxxxx
BHPKFDWCPR
x--xxxx-x-
WRWYCQTWDF
x-xx-xxxxx
FBOTDYYMGO
xxxxxxx--x
SGLWOYFWZY
x-xxxxxxxx
BKXJGXUTDI
xxxO-O-xxx
WKFDXQRCEZ
xxxx-x--xx
WZQYEIXVGV
xxxxxx-x-x
VYFIAADRIB
xxxx-xx-xx
CLZGWKNRIH
-xx-xxx-x-
HGRDECGM...

output:

833

result:

ok 1 number(s): "833"

Test #35:

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

input:

20 10
FCCKSZOJLC
xxx---xx-x
GGEDVVPNOV
xxOxxxxxxx
SGGDAIAHIP
-xxx-xxxxx
GGVAULXPGP
xxx--Oxxxx
DLLQSWLEVI
x-x--xO-xx
DUWRFTNQQA
x-xxxxx-x-
MHTFMAYJDN
xxxxx-xxxx
FUYVYGXIUL
x-xxxxxx--
NJSBZWRJKT
xx-x-xxxOx
DMSYQXGEXZ
xx-xOxx-xO
OEUFRLYPSE
x--xxOxx-x
BFNSAKQXSL
xxx----xx-
XWKTQTTAVG
xx-xOxxOxx
TUQXRAMR...

output:

1

result:

ok 1 number(s): "1"

Test #36:

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

input:

10000 10
BGRKIVRKRM
x-xx-xxxxx
AXLWMNNVMG
x-xxxxxxx-
SGMZGJEHXG
--xxxxxx-x
LBBGPZSSMA
xxx-xx-xxx
JLJIMZDICO
xxx-xxxx--
CMHSOVCTHE
-xxO-xx-xx
HGIOECKNRW
x---xOxxxx
XYLTHEQOYJ
-Ox-xxxO-x
XDJTYRPWUU
-xx-Oxxxxx
AEZWRFDCVC
xxxxxxx-xx
SVPTXBOTUL
-xx--x-xxx
RBSTIWRDIM
xx---xxxxx
ILHDJAVREH
-xxxxxxxxx
EZNBI...

output:

1

result:

ok 1 number(s): "1"

Test #37:

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

input:

1 15
QVUWVUTBXUITDRS
-x--xx--xxxx-xx

output:

577051591

result:

ok 1 number(s): "577051591"

Test #38:

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

input:

3 15
PGKQCHEFVTGTEPE
xx-Ox--xx-x-xxx
ZRNMLMDFULGZUMO
x-x-xxxx-xxxxxx
HZVTASECXFSDFSH
-xx--x-xxxxxxxx

output:

250741371

result:

ok 1 number(s): "250741371"

Test #39:

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

input:

5 15
KQBFFVASLNITBAQ
xx--x--x-xxxx-x
CVMHXVRGIYTZDUT
O-xxxx-xxxx---x
MZVFQMRTLGAVJKM
x---xx-x-x-xxxx
FFTQJAPDYAJYFBF
-xxxx-x-x-xxx-x
CBWRGNWIGOHKBPB
O-x-xxxxx-xxxxx

output:

297257451

result:

ok 1 number(s): "297257451"

Test #40:

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

input:

10 15
JZNPISWDTIWUNNR
---xxxxx-xxxxxx
NNRYEPCJZLIIERN
-xxx-x---Oxxxxx
ZXULUHHYMEJJGHC
--x-xxxxx--x-x-
VJNBWOGXJJEYKJZ
x---x-OOxx-x-x-
JYXVOMPPBNHJAYI
-x-x-xxx--xx-xx
KDSITFHFUSDZXGQ
-xxxOxxxxxx----
SIXKCUYHBSITUYC
xx---xxx-xxOxxx
PSTIIRYIMCYOHSB
xx-xxxxxx-x-xx-
JDXKVANYLRBMAHU
-x--x--x-x-xxxx
YOPTVR...

output:

7938

result:

ok 1 number(s): "7938"

Test #41:

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

input:

15 15
VSVTJJPPGOYELZA
-xx--xxx---x--x
JAZIWUIBWRMUSWZ
-x----x-xxxxxxx
QRUBSAWHQSNALQI
xx--xx-xxxxx-x-
UCQXYHYOTPPJDHG
-xx--xO--xx-xx-
FVUZVRTKVFMWEED
---Oxx-xxxx-xxx
WBVIGOVHXTPTGMZ
------xx--xxxx-
ZDXFUOHLXIYNTRJ
-x----x-x--x-xO
GXCRJBOHDTPGREI
--xx-O-xx-xxxx-
ZDRUNDNIDWKXSDA
-xx-xxx-x-x-xxx
LXZYXU...

output:

3560

result:

ok 1 number(s): "3560"

Test #42:

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

input:

20 15
FAUPGDEXPEAJGUT
-O-xx--xx--xxx-
XGCLSBXVAMAPIGA
xxx-xxxx-x-xxxx
BKRGJCWZAIGMJAR
x-xxxx-x-xxxx-x
FGQUTOGJGOWPAXP
-xx--xxxxx-x-xx
HUGXVIDUQTYHVQR
--xxxx-xx--xxxx
ARMAVNBXQSFULHS
Oxx-x-xxxx----x
ZOLGUOYLIRFOOYW
xx-x-x-xxx-xx--
MMSBNDXGWYORCRO
xxxx--xx-Oxxxxx
FMZOULBTOJMZTMN
-xxx--x-xxxxxx-
NPEKXE...

output:

4

result:

ok 1 number(s): "4"

Test #43:

score: 0
Accepted
time: 9ms
memory: 4160kb

input:

10000 15
ADZIQJSZEVTTOKW
xxxxxx-x--xx-xx
BKIHMBBOHHJBKMZ
-xxx-xx-xxxxxxx
TCMMTZSPARRDNZF
xx-xxx-xxxxx-xx
NXBRJXDQYSJOIHH
-x-xxxxxxOx-xxx
JGOKDILOAYDHBQP
xO-xxx-xxxxx-xx
LUDWCEYLABQNEBY
--xxx-xxx-x--xx
KPBWFKHBWXRISXA
xx-xxxxxxxxxOxx
CWXCNPCMMPVKVFZ
xxxx-xx-xx-xxxx
MHNURAZEPAXGUIJ
-x--xxx-xxx-xxx
QUQ...

output:

1

result:

ok 1 number(s): "1"

Test #44:

score: 0
Accepted
time: 2ms
memory: 5384kb

input:

1 19
IEIMSENQDSTNAPVSNAN
x-xx-x-xxxx-xOxxxxx

output:

337065816

result:

ok 1 number(s): "337065816"

Test #45:

score: 0
Accepted
time: 6ms
memory: 5520kb

input:

3 19
HRXRMZDQERFUBORITOO
-x-xxx---O---xx--xx
PZZRQQGGARUXFOTYABP
xxxxOxxx-O-O-x--x-x
DIGUVSFNJVSLCTXIDCB
--xOx--x-xx-x--xxx-

output:

417344546

result:

ok 1 number(s): "417344546"

Test #46:

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

input:

5 19
KFXDGBBMEXVXJIBGYGM
-OxOxxOxxx-xx-xx-xx
CNMRHGAXWNFNRARAEFD
x-xx-x-x-x-xxxxxx--
HOLWTUDCHGSXCAPMMMX
-xx----xxx-xx--xxxx
HMRTNFVGNLBHJEGEPOC
-xx-x--xOx-xxxxx-xx
LVJQXEYHFDBRKMVKHNY
x-xxxx-----x-x-xx-x

output:

121474019

result:

ok 1 number(s): "121474019"

Test #47:

score: 0
Accepted
time: 15ms
memory: 5380kb

input:

10 19
SCTWOSTURDAMARVNENO
x-x-xxx-O-xxx--x-xx
TMBEMRYFMULRYJOFCAY
xxx-x--xx---x-xx-xx
MLBWXOPOETUFLDTNPCA
x-x--x-x-x-xxOxxx-x
XVWYJGVAZHSOHLAXFUW
-----xxxxxxxx-xxx-O
PCAQXZKNYVVZJYTYWGU
--xx-x-x--xx-xxxOx-
TWZGXNVEGFLQQWBLXJI
x-xx-x--xx-xx-xxx--
BKWYQSWEGXGOIDKUNXJ
x---xx--x-xx-Ox-xx-
KNQVTEZOJSYMXW...

output:

404122654

result:

ok 1 number(s): "404122654"

Test #48:

score: 0
Accepted
time: 2ms
memory: 5300kb

input:

15 19
OTMWXBRFLAFQOVFCXXY
x--Oxxxxx-x-x-x-xxx
QGFMSWKLJUXLFXYRIWD
Oxx----x--xxxxxxxxO
JGZMRJHRAUHTRHAFSNW
-xx-xO-x--x-xxxx-x-
UOVFVYYRQYFOMGMVMYN
-x-xxxxx-xxx-x-xOxx
DUCXYILKABZYKTLKMFY
---xxxxO-xxxx-xxOxx
OUUJPCQJPKIXUWTCOBS
x-x-----x-xxx--xxx-
QVPYBYSHXSXSVFYVKHX
O--xxx--xxxxxxxx-xx
MTAUHSPTUQYVHX...

output:

51

result:

ok 1 number(s): "51"

Test #49:

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

input:

20 19
XNTIKSCKCNYDTCFXDMX
--xxx-xxxx-xxx--xxx
YBXHLGTAGNGBHGYXQUF
---O-xxxx-xx-x---x-
PIQTQJHTZFCCQNYDETY
-x-xxx-x--xxx--xxx-
XITBMLDXWYUBHMQHHQY
-xx-x-x---xx-x--xx-
YASMJTIYZTGJXUPKZBE
-x-xxxx--xxx-x-xx-x
POQEXPWYFUPHEUHLRQH
---x-x---xx-xx--xxx
WXRZOLRPHNRFXIDZXNT
--xx--x---xO-xxOxxx
DFVETBZWUJSMLX...

output:

40644

result:

ok 1 number(s): "40644"

Test #50:

score: 0
Accepted
time: 11ms
memory: 5592kb

input:

10000 19
ZTLLZAQQFLFITIAWEMY
-x---x-x-xxxxxxxx--
BWKXGMFNCMMQMBOPLTK
-x-xx----xx-x-xx-xO
PLWAMBWCNCFCUIFKSKA
x-xx--x--x-xxxx-x-x
FEKJAUYVKDNDKSAOUEE
-x-xxx-x-x-x-xxxxxx
XPYSGAXIPVSKNOSKJWX
xx-xxxxxxxx--xx-xxx
VNPIVLMLCVYSJAXRUFA
x-xxx----x-xxxxxx-x
JEYYBUSAFHSXDSVVUMY
xx-x-xxx--xxxxxxx-x
DQWXXZYVLGU...

output:

1

result:

ok 1 number(s): "1"

Test #51:

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

input:

2 19
ZZZZZZZZZZZZZZZZZZA
OOOOOOOOOOOOOOOOOOx
YAAAAAAAAAAAAAAAAAA
-xxxxxxxxxxxxxxxxxx

output:

1

result:

ok 1 number(s): "1"

Test #52:

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

input:

1 19
QZAMSYSPMFXBGNAVJGW
x--xxOxxxxxxx--xxx-

output:

7597869

result:

ok 1 number(s): "7597869"

Test #53:

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

input:

1 19
KQQPBXAMBCMPBEKIOAF
x-xxx--xxxxxxxx-xx-

output:

961982430

result:

ok 1 number(s): "961982430"

Test #54:

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

input:

1 19
JLFJWSINIGWRRRZJWMK
-x--xxx-xxOOxx-xxx-

output:

16277388

result:

ok 1 number(s): "16277388"

Test #55:

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

input:

1 19
ABDQNNUOBCKXZARWEGT
-xx-xxxxxxOOx-x-xx-

output:

381502553

result:

ok 1 number(s): "381502553"

Test #56:

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

input:

1 19
VKTXJIPMMHYHUVFJMVC
---xx--xxx-xxx-xxxx

output:

845767424

result:

ok 1 number(s): "845767424"

Test #57:

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

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #58:

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

input:

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

output:

802932781

result:

ok 1 number(s): "802932781"

Test #59:

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

input:

2 2
AA
Ox
BB
Ox

output:

0

result:

ok 1 number(s): "0"

Test #60:

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

input:

3 2
AA
-x
BB
-x
CC
-x

output:

0

result:

ok 1 number(s): "0"

Test #61:

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

input:

26 1
A
x
B
x
C
x
D
x
E
x
F
x
G
x
H
x
I
x
J
x
K
x
L
x
M
x
N
x
O
x
P
x
Q
x
R
x
S
x
T
x
U
x
V
x
W
x
X
x
Y
x
Z
x

output:

0

result:

ok 1 number(s): "0"

Test #62:

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

input:

2 1
A
O
A
x

output:

0

result:

ok 1 number(s): "0"

Test #63:

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

input:

2 1
A
O
A
-

output:

0

result:

ok 1 number(s): "0"

Test #64:

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

input:

2 1
A
x
A
-

output:

0

result:

ok 1 number(s): "0"

Test #65:

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

input:

25 1
A
x
B
x
C
x
D
x
E
x
F
x
G
x
H
x
I
x
J
x
K
x
L
x
M
x
N
x
O
x
P
x
Q
x
R
x
S
x
T
x
U
x
V
x
W
x
X
x
Y
x

output:

1

result:

ok 1 number(s): "1"

Test #66:

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

input:

1 1
A
-

output:

0

result:

ok 1 number(s): "0"

Test #67:

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

input:

1 3
AAA
-xO

output:

0

result:

ok 1 number(s): "0"

Test #68:

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

input:

1 3
AAA
-Ox

output:

0

result:

ok 1 number(s): "0"

Test #69:

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

input:

1 3
AAA
O-x

output:

0

result:

ok 1 number(s): "0"

Test #70:

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

input:

1 3
AAA
Ox-

output:

0

result:

ok 1 number(s): "0"

Test #71:

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

input:

1 3
AAA
x-O

output:

0

result:

ok 1 number(s): "0"

Test #72:

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

input:

1 3
AAA
xO-

output:

0

result:

ok 1 number(s): "0"

Test #73:

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

input:

2 9
AAAZZZZZZ
-xxxxxxxx
AAAZZZZZZ
--xxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #74:

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

input:

2 9
AAAAAAZZZ
-xxxxxxxx
AAAAAAZZZ
xxxxOOxxx

output:

0

result:

ok 1 number(s): "0"