#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;
long long dp[12][12][12][360];
vector<tuple<string, int, int, int>> bnormal, blast;
void init() {
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= 10 - i; j++) {
string V = "";
if (i == 10) V = "x-";
else if (i + j == 10) V = to_string(i) + "/";
else V = to_string(i) + to_string(j);
bnormal.push_back(make_tuple(V, i, j, 0));
}
}
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k <= 10; k++) {
if (i + j > 10 && i != 10) continue;
if (i == 10) {
if (j + k > 10 && j != 10) continue;
}
string V = "";
if (i == 10 && j == 10 && k == 10) V = "xxx";
else if (i == 10 && j == 10) V = "xx" + to_string(k);
else if (i == 10 && j + k == 10) V = "x" + to_string(j) + "/";
else if (i == 10) V = "x" + to_string(j) + to_string(k);
else if (i + j == 10 && k == 10) V += to_string(i) + "/x";
else if (i + j == 10) V += to_string(i) + "/" + to_string(k);
else V += to_string(i) + to_string(j) + "-";
blast.push_back(make_tuple(V, i, j, k));
}
}
}
sort(bnormal.begin(), bnormal.end()); bnormal.erase(unique(bnormal.begin(), bnormal.end()), bnormal.end());
sort(blast.begin(), blast.end()); blast.erase(unique(blast.begin(), blast.end()), blast.end());
return;
}
long long solve(string S, vector<int>vec) {
for (int i = 0; i < 12 * 12; i++) {
for (int j = 0; j < 12 * 360; j++) dp[i / 12][i % 12][j / 360][j % 360] = 0;
}
for (int i = 0; i < blast.size(); i++) {
bool flag = true;
for (int j = 0; j < 3; j++) { if (S[j + (int)(vec.size() - 1) * 2] != '?' && S[j + (int)(vec.size() - 1) * 2] != get<0>(blast[i])[j]) flag = false; }
if (flag == true) {
for (int j = 0; j <= 330; j++) {
if (vec[vec.size() - 1] != -1 && vec[vec.size() - 1] != j) continue;
int G1 = get<1>(blast[i]) + get<2>(blast[i]) + get<3>(blast[i]);
if (j >= G1) {
dp[vec.size() - 1][get<1>(blast[i])][get<2>(blast[i])][j - G1] = 1;
}
}
}
}
for (int i = (int)vec.size() - 2; i >= 0; i--) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k <= 10; k++) {
for (int l = 0; l <= 330; l++) {
if (vec[i] != -1 && l != vec[i]) dp[i + 1][j][k][l] = 0;
if (dp[i + 1][j][k][l] == 0) continue;
for (int m = 0; m < bnormal.size(); m++) {
bool flag = true;
for (int n = 0; n < 2; n++) { if (S[i * 2 + n] != '?' && S[i * 2 + n] != get<0>(bnormal[m])[n]) flag = false; }
if (flag == true) {
int G1 = get<1>(bnormal[m]) + get<2>(bnormal[m]);
int G2 = 0;
if (get<0>(bnormal[m])[1] == '/') G2 = j; // 1 回前
if (get<0>(bnormal[m])[0] == 'x') G2 = j + k; // 2 回前
int v1 = get<1>(bnormal[m]), v2 = get<2>(bnormal[m]);
if (v1 == 10) { v2 = j; }
if (l >= G1 + G2) {
dp[i][v1][v2][l - (G1 + G2)] += dp[i + 1][j][k][l];
}
}
}
}
}
}
}
long long sum = 0;
for (int i = 0; i <= 10; i++) { for (int j = 0; j <= 10; j++) sum += dp[0][i][j][0]; }
return sum;
}
int main() {
init();
int Q, N; string str;
cin >> Q;
for (int i = 1; i <= Q; i++) {
cin >> N >> str; vector<int>A(N, 0);
for (int j = 0; j < N; j++) cin >> A[j];
cout << solve(str, A) << endl;
}
return 0;
}
Compilation message
bow.cpp: In function 'long long int solve(std::__cxx11::string, std::vector<int>)':
bow.cpp:50:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < blast.size(); i++) {
~~^~~~~~~~~~~~~~
bow.cpp:70:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int m = 0; m < bnormal.size(); m++) {
~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
5376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
5248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
5248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
5248 KB |
Output is correct |
2 |
Correct |
138 ms |
5348 KB |
Output is correct |
3 |
Correct |
187 ms |
5376 KB |
Output is correct |
4 |
Correct |
164 ms |
5248 KB |
Output is correct |
5 |
Correct |
133 ms |
5368 KB |
Output is correct |
6 |
Correct |
114 ms |
5368 KB |
Output is correct |
7 |
Correct |
137 ms |
5360 KB |
Output is correct |
8 |
Correct |
115 ms |
5248 KB |
Output is correct |
9 |
Correct |
129 ms |
5248 KB |
Output is correct |
10 |
Correct |
488 ms |
5364 KB |
Output is correct |
11 |
Correct |
471 ms |
5328 KB |
Output is correct |
12 |
Correct |
449 ms |
5364 KB |
Output is correct |
13 |
Correct |
485 ms |
5248 KB |
Output is correct |
14 |
Correct |
123 ms |
5248 KB |
Output is correct |
15 |
Correct |
100 ms |
5248 KB |
Output is correct |
16 |
Correct |
113 ms |
5248 KB |
Output is correct |
17 |
Correct |
109 ms |
5248 KB |
Output is correct |
18 |
Correct |
53 ms |
5436 KB |
Output is correct |
19 |
Correct |
65 ms |
5248 KB |
Output is correct |
20 |
Correct |
69 ms |
5248 KB |
Output is correct |
21 |
Correct |
61 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
5376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |