#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (c it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "
using ld = long double;
using ll = long long;
constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;
void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }
template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }
using ull = unsigned long long;
constexpr int MaxScore = 400;
constexpr int nax = 15;
bool Matches(const string& a, const string& b) {
if (a.size() != b.size()) return false;
for (int i = 0; i < (int) a.size(); i++) {
if (a[i] != '?' and b[i] != '?' and a[i] != b[i]) {
return false;
}
}
return true;
}
int n;
string napis[nax];
int score[nax];
#define empty empty83299832dskjflkdsajfkalkfasfasf
constexpr int empty = 11;
ull dp[nax][MaxScore][12][12];
void algos() {
debug() << imie(n);
debug() << range(napis + 1, napis + n + 1);
debug() << range(score + 1, score + n + 1);
for (int i = 0; i <= n + 1; i++) {
for (int s = 0; s < MaxScore; s++) {
for (int jed = 0; jed <= empty; jed++) {
for (int dwa = 0; dwa <= empty; dwa++) {
dp[i][s][jed][dwa] = 0;
}
}
}
}
dp[0][0][empty][empty] = 1;
auto Dorzuc = [](int i, const string& what, int s, int jed, int dwa, ull ile) -> void {
assert(0 < ile);
assert(0 <= s and s < MaxScore);
assert(0 <= jed and jed <= empty);
assert(0 <= dwa and dwa <= empty);
if (score[i] == -1 or score[i] == s) {
if (Matches(what, napis[i])) {
dp[i][s][jed][dwa] += ile;
}
}
};
for (int i = 1; i < n; i++) {
for (int s = 0; s < MaxScore; s++) {
for (int jed = 0; jed <= 10; jed++) {
for (int dwa = 0; dwa <= 10; dwa++) {
const ull ile = dp[i - 1][s][jed][dwa] + dp[i - 1][s][jed][empty] + dp[i - 1][s][empty][dwa] + dp[i - 1][s][empty][empty];
if (!ile) continue;
debug() << "dp[" << i << "][" << s << "][" << jed << "][" << dwa << "] = " << ile;
// x-
if (jed == 10) {
for (int trzy = 0; trzy <= 10; trzy++) {
Dorzuc(i, "x-", s + 10 + dwa + trzy, dwa, trzy, ile);
}
}
// A/
if (jed < 10 and jed + dwa == 10) {
for (int trzy = 0; trzy <= 10; trzy++) {
Dorzuc(i, to_string(jed) + "/", s + 10 + trzy, trzy, empty, ile);
}
}
// AB
if (jed + dwa < 10) {
Dorzuc(i, to_string(jed) + to_string(dwa), s + jed + dwa, empty, empty, ile);
}
}
}
}
}
ull wynik = 0;
auto DorzucN = [&wynik](string what, int s, ull ile) -> void {
assert(0 < ile);
assert(0 <= s and s < MaxScore);
if (Matches(what, napis[n])) {
if (score[n] == -1 or score[n] == s) {
wynik += ile;
}
}
};
for (int s = 0; s < MaxScore; s++) {
for (int jed = 0; jed <= 10; jed++) {
for (int dwa = 0; dwa <= 10; dwa++) {
const ull ile = dp[n - 1][s][jed][dwa] + dp[n - 1][s][jed][empty] + dp[n - 1][s][empty][dwa] + dp[n - 1][s][empty][empty];
if (!ile) continue;
// xxx
if (jed == 10 and dwa == 10) {
DorzucN("xxx", s + 30, ile);
}
// xxA"
if (jed == 10 and dwa == 10) {
for (int a = 0; a <= 9; a++) {
DorzucN("xx" + to_string(a), s + 20 + a, ile);
}
}
// xA/"
if (jed == 10 and dwa < 10) {
DorzucN("x" + to_string(dwa) + "/", s + 20, ile);
}
// xAB"
if (jed == 10 and dwa < 10) {
for (int trzy = 0; dwa + trzy < 10; trzy++) {
DorzucN("x" + to_string(dwa) + to_string(trzy), s + 10 + dwa + trzy, ile);
}
}
// A/x
if (jed < 10 and jed + dwa == 10) {
DorzucN(to_string(jed) + "/x", s + 20, ile);
}
// A/B
if (jed < 10 and jed + dwa == 10) {
for (int trzy = 0; trzy < 10; trzy++) {
DorzucN(to_string(jed) + "/" + to_string(trzy), s + 10 + trzy, ile);
}
}
// AB-"
if (jed + dwa < 10) {
DorzucN(to_string(jed) + to_string(dwa) + "-", s + jed + dwa, ile);
}
}
}
}
printf("%llu\n", wynik);
}
void przyp() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char c;
if (i == 1) scanf(" %c", &c);
else scanf("%c", &c);
napis[i].clear();
napis[i].push_back(c);
scanf("%c", &c);
napis[i].push_back(c);
if (i == n) {
scanf("%c", &c);
napis[i].push_back(c);
}
}
for (int i = 1; i <= n; i++) {
scanf("%d", &score[i]);
}
algos();
}
int main() {
int t;
scanf("%d", &t);
while (t--) przyp();
return 0;
}
Compilation message
bow.cpp: In function 'void przyp()':
bow.cpp:190:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
bow.cpp:193:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
if (i == 1) scanf(" %c", &c);
~~~~~^~~~~~~~~~~
bow.cpp:194:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
else scanf("%c", &c);
~~~~~^~~~~~~~~~
bow.cpp:197:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c", &c);
~~~~~^~~~~~~~~~
bow.cpp:200:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c", &c);
~~~~~^~~~~~~~~~
bow.cpp:205:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &score[i]);
~~~~~^~~~~~~~~~~~~~~~~
bow.cpp: In function 'int main()':
bow.cpp:212:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &t);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5752 KB |
Output is correct |
2 |
Correct |
33 ms |
5752 KB |
Output is correct |
3 |
Correct |
26 ms |
5752 KB |
Output is correct |
4 |
Correct |
40 ms |
5836 KB |
Output is correct |
5 |
Correct |
32 ms |
5900 KB |
Output is correct |
6 |
Correct |
37 ms |
5960 KB |
Output is correct |
7 |
Correct |
120 ms |
6060 KB |
Output is correct |
8 |
Correct |
74 ms |
6060 KB |
Output is correct |
9 |
Correct |
68 ms |
6060 KB |
Output is correct |
10 |
Correct |
75 ms |
6068 KB |
Output is correct |
11 |
Correct |
60 ms |
6092 KB |
Output is correct |
12 |
Correct |
30 ms |
6092 KB |
Output is correct |
13 |
Correct |
9 ms |
6092 KB |
Output is correct |
14 |
Correct |
37 ms |
6092 KB |
Output is correct |
15 |
Correct |
12 ms |
6092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
6140 KB |
Output is correct |
2 |
Correct |
69 ms |
6140 KB |
Output is correct |
3 |
Correct |
72 ms |
6140 KB |
Output is correct |
4 |
Correct |
59 ms |
6212 KB |
Output is correct |
5 |
Correct |
58 ms |
6212 KB |
Output is correct |
6 |
Correct |
62 ms |
6300 KB |
Output is correct |
7 |
Correct |
81 ms |
6300 KB |
Output is correct |
8 |
Correct |
95 ms |
6356 KB |
Output is correct |
9 |
Correct |
55 ms |
6356 KB |
Output is correct |
10 |
Correct |
141 ms |
6356 KB |
Output is correct |
11 |
Correct |
152 ms |
6356 KB |
Output is correct |
12 |
Correct |
125 ms |
6356 KB |
Output is correct |
13 |
Correct |
133 ms |
6356 KB |
Output is correct |
14 |
Correct |
66 ms |
6356 KB |
Output is correct |
15 |
Correct |
67 ms |
6356 KB |
Output is correct |
16 |
Correct |
66 ms |
6356 KB |
Output is correct |
17 |
Correct |
68 ms |
6356 KB |
Output is correct |
18 |
Correct |
296 ms |
6356 KB |
Output is correct |
19 |
Correct |
281 ms |
6372 KB |
Output is correct |
20 |
Correct |
274 ms |
6380 KB |
Output is correct |
21 |
Correct |
230 ms |
6380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
6380 KB |
Output is correct |
2 |
Correct |
57 ms |
6380 KB |
Output is correct |
3 |
Correct |
51 ms |
6380 KB |
Output is correct |
4 |
Correct |
33 ms |
6380 KB |
Output is correct |
5 |
Correct |
36 ms |
6380 KB |
Output is correct |
6 |
Correct |
47 ms |
6380 KB |
Output is correct |
7 |
Correct |
49 ms |
6380 KB |
Output is correct |
8 |
Correct |
62 ms |
6380 KB |
Output is correct |
9 |
Correct |
69 ms |
6420 KB |
Output is correct |
10 |
Correct |
77 ms |
6420 KB |
Output is correct |
11 |
Correct |
59 ms |
6420 KB |
Output is correct |
12 |
Correct |
53 ms |
6420 KB |
Output is correct |
13 |
Correct |
51 ms |
6420 KB |
Output is correct |
14 |
Correct |
94 ms |
6436 KB |
Output is correct |
15 |
Correct |
79 ms |
6436 KB |
Output is correct |
16 |
Correct |
89 ms |
6436 KB |
Output is correct |
17 |
Correct |
62 ms |
6436 KB |
Output is correct |
18 |
Correct |
61 ms |
6436 KB |
Output is correct |
19 |
Correct |
61 ms |
6456 KB |
Output is correct |
20 |
Correct |
61 ms |
6456 KB |
Output is correct |
21 |
Correct |
90 ms |
6456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
279 ms |
6468 KB |
Output is correct |
2 |
Correct |
77 ms |
6468 KB |
Output is correct |
3 |
Correct |
127 ms |
6476 KB |
Output is correct |
4 |
Correct |
117 ms |
6476 KB |
Output is correct |
5 |
Correct |
93 ms |
6476 KB |
Output is correct |
6 |
Correct |
84 ms |
6488 KB |
Output is correct |
7 |
Correct |
80 ms |
6488 KB |
Output is correct |
8 |
Correct |
72 ms |
6488 KB |
Output is correct |
9 |
Correct |
90 ms |
6488 KB |
Output is correct |
10 |
Correct |
277 ms |
6500 KB |
Output is correct |
11 |
Correct |
278 ms |
6540 KB |
Output is correct |
12 |
Correct |
233 ms |
6540 KB |
Output is correct |
13 |
Correct |
250 ms |
6540 KB |
Output is correct |
14 |
Correct |
137 ms |
6552 KB |
Output is correct |
15 |
Correct |
96 ms |
6556 KB |
Output is correct |
16 |
Correct |
100 ms |
6556 KB |
Output is correct |
17 |
Correct |
129 ms |
6556 KB |
Output is correct |
18 |
Correct |
65 ms |
6556 KB |
Output is correct |
19 |
Correct |
68 ms |
6556 KB |
Output is correct |
20 |
Correct |
95 ms |
6556 KB |
Output is correct |
21 |
Correct |
53 ms |
6556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5752 KB |
Output is correct |
2 |
Correct |
33 ms |
5752 KB |
Output is correct |
3 |
Correct |
26 ms |
5752 KB |
Output is correct |
4 |
Correct |
40 ms |
5836 KB |
Output is correct |
5 |
Correct |
32 ms |
5900 KB |
Output is correct |
6 |
Correct |
37 ms |
5960 KB |
Output is correct |
7 |
Correct |
120 ms |
6060 KB |
Output is correct |
8 |
Correct |
74 ms |
6060 KB |
Output is correct |
9 |
Correct |
68 ms |
6060 KB |
Output is correct |
10 |
Correct |
75 ms |
6068 KB |
Output is correct |
11 |
Correct |
60 ms |
6092 KB |
Output is correct |
12 |
Correct |
30 ms |
6092 KB |
Output is correct |
13 |
Correct |
9 ms |
6092 KB |
Output is correct |
14 |
Correct |
37 ms |
6092 KB |
Output is correct |
15 |
Correct |
12 ms |
6092 KB |
Output is correct |
16 |
Correct |
144 ms |
6140 KB |
Output is correct |
17 |
Correct |
69 ms |
6140 KB |
Output is correct |
18 |
Correct |
72 ms |
6140 KB |
Output is correct |
19 |
Correct |
59 ms |
6212 KB |
Output is correct |
20 |
Correct |
58 ms |
6212 KB |
Output is correct |
21 |
Correct |
62 ms |
6300 KB |
Output is correct |
22 |
Correct |
81 ms |
6300 KB |
Output is correct |
23 |
Correct |
95 ms |
6356 KB |
Output is correct |
24 |
Correct |
55 ms |
6356 KB |
Output is correct |
25 |
Correct |
141 ms |
6356 KB |
Output is correct |
26 |
Correct |
152 ms |
6356 KB |
Output is correct |
27 |
Correct |
125 ms |
6356 KB |
Output is correct |
28 |
Correct |
133 ms |
6356 KB |
Output is correct |
29 |
Correct |
66 ms |
6356 KB |
Output is correct |
30 |
Correct |
67 ms |
6356 KB |
Output is correct |
31 |
Correct |
66 ms |
6356 KB |
Output is correct |
32 |
Correct |
68 ms |
6356 KB |
Output is correct |
33 |
Correct |
296 ms |
6356 KB |
Output is correct |
34 |
Correct |
281 ms |
6372 KB |
Output is correct |
35 |
Correct |
274 ms |
6380 KB |
Output is correct |
36 |
Correct |
230 ms |
6380 KB |
Output is correct |
37 |
Correct |
74 ms |
6380 KB |
Output is correct |
38 |
Correct |
57 ms |
6380 KB |
Output is correct |
39 |
Correct |
51 ms |
6380 KB |
Output is correct |
40 |
Correct |
33 ms |
6380 KB |
Output is correct |
41 |
Correct |
36 ms |
6380 KB |
Output is correct |
42 |
Correct |
47 ms |
6380 KB |
Output is correct |
43 |
Correct |
49 ms |
6380 KB |
Output is correct |
44 |
Correct |
62 ms |
6380 KB |
Output is correct |
45 |
Correct |
69 ms |
6420 KB |
Output is correct |
46 |
Correct |
77 ms |
6420 KB |
Output is correct |
47 |
Correct |
59 ms |
6420 KB |
Output is correct |
48 |
Correct |
53 ms |
6420 KB |
Output is correct |
49 |
Correct |
51 ms |
6420 KB |
Output is correct |
50 |
Correct |
94 ms |
6436 KB |
Output is correct |
51 |
Correct |
79 ms |
6436 KB |
Output is correct |
52 |
Correct |
89 ms |
6436 KB |
Output is correct |
53 |
Correct |
62 ms |
6436 KB |
Output is correct |
54 |
Correct |
61 ms |
6436 KB |
Output is correct |
55 |
Correct |
61 ms |
6456 KB |
Output is correct |
56 |
Correct |
61 ms |
6456 KB |
Output is correct |
57 |
Correct |
90 ms |
6456 KB |
Output is correct |
58 |
Correct |
279 ms |
6468 KB |
Output is correct |
59 |
Correct |
77 ms |
6468 KB |
Output is correct |
60 |
Correct |
127 ms |
6476 KB |
Output is correct |
61 |
Correct |
117 ms |
6476 KB |
Output is correct |
62 |
Correct |
93 ms |
6476 KB |
Output is correct |
63 |
Correct |
84 ms |
6488 KB |
Output is correct |
64 |
Correct |
80 ms |
6488 KB |
Output is correct |
65 |
Correct |
72 ms |
6488 KB |
Output is correct |
66 |
Correct |
90 ms |
6488 KB |
Output is correct |
67 |
Correct |
277 ms |
6500 KB |
Output is correct |
68 |
Correct |
278 ms |
6540 KB |
Output is correct |
69 |
Correct |
233 ms |
6540 KB |
Output is correct |
70 |
Correct |
250 ms |
6540 KB |
Output is correct |
71 |
Correct |
137 ms |
6552 KB |
Output is correct |
72 |
Correct |
96 ms |
6556 KB |
Output is correct |
73 |
Correct |
100 ms |
6556 KB |
Output is correct |
74 |
Correct |
129 ms |
6556 KB |
Output is correct |
75 |
Correct |
65 ms |
6556 KB |
Output is correct |
76 |
Correct |
68 ms |
6556 KB |
Output is correct |
77 |
Correct |
95 ms |
6556 KB |
Output is correct |
78 |
Correct |
53 ms |
6556 KB |
Output is correct |
79 |
Correct |
213 ms |
6556 KB |
Output is correct |
80 |
Correct |
117 ms |
6556 KB |
Output is correct |
81 |
Correct |
100 ms |
6560 KB |
Output is correct |
82 |
Correct |
62 ms |
6560 KB |
Output is correct |
83 |
Correct |
55 ms |
6560 KB |
Output is correct |
84 |
Correct |
52 ms |
6624 KB |
Output is correct |
85 |
Correct |
57 ms |
6624 KB |
Output is correct |
86 |
Correct |
47 ms |
6624 KB |
Output is correct |
87 |
Correct |
58 ms |
6624 KB |
Output is correct |
88 |
Correct |
144 ms |
6624 KB |
Output is correct |
89 |
Correct |
177 ms |
6624 KB |
Output is correct |
90 |
Correct |
144 ms |
6624 KB |
Output is correct |
91 |
Correct |
185 ms |
6624 KB |
Output is correct |
92 |
Correct |
86 ms |
6624 KB |
Output is correct |
93 |
Execution timed out |
1029 ms |
6676 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |