QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#703490 | #9536. Athlete Welcome Ceremony | ucup-team3691# | WA | 19ms | 434016kb | C++20 | 3.3kb | 2024-11-02 17:53:02 | 2024-11-02 17:53:04 |
Judging History
answer
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <random>
#include <ctime>
#include <cstdlib>
#include <chrono>
using namespace std;
const int MOD = 1e9 + 7;
struct imod {
imod() : x(0) {}
imod(int x) : x(x) {}
imod operator + (imod &r) {
imod ans;
ans.x = x + r.x;
if (ans.x >= MOD)
ans.x -= MOD;
return ans;
}
imod operator - (const imod &r) {
imod ans;
ans.x = x - r.x + MOD;
if (ans.x >= MOD)
ans.x -= MOD;
return ans;
}
imod operator * (const imod &r) {
imod ans;
ans.x = 1LL * x * r.x % MOD;
return ans;
}
imod& operator = (int x) {
this->x = x;
return *this;
}
int x;
};
imod dp[302][302][302][3];
imod sp[302][302][302];
int convert(char ch) {
if (ch == 'a')
return 0;
if (ch == 'b')
return 1;
return 2;
}
void solve() {
int n, q;
string s;
cin >> n >> q;
cin >> s;
s = " " + s;
if (s[1] != '?') {
dp[s[1] == 'a'][s[1] == 'b'][s[1] == 'c'][convert(s[1])] = 1;
} else {
dp[1][0][0][0] = 1;
dp[0][1][0][1] = 1;
dp[0][0][1][2] = 1;
}
for (int x = 0; x <= n; ++x) {
for (int y = 0; y <= n; ++y) {
for (int z = 0; z <= n; ++z) {
int p = x + y + z;
if (x + y + z >= n) {
if (x > 0)
sp[x][y][z] = sp[x][y][z] + sp[x - 1][y][z];
if (y > 0)
sp[x][y][z] = sp[x][y][z] + sp[x][y - 1][z];
if (z > 0)
sp[x][y][z] = sp[x][y][z] + sp[x][y][z - 1];
if (x > 0 && y > 0)
sp[x][y][z] = sp[x][y][z] - sp[x - 1][y - 1][z];
if (y > 0 && z > 0)
sp[x][y][z] = sp[x][y][z] - sp[x][y - 1][z - 1];
if (x > 0 && z > 0)
sp[x][y][z] = sp[x][y][z] - sp[x - 1][y][z - 1];
if (x > 0 && y > 0 && z > 0)
sp[x][y][z] = sp[x][y][z] + sp[x - 1][y - 1][z - 1];
}
if (p <= 1)
continue;
if (p > n)
continue;
if (x > 0 && (s[p] == 'a' || s[p] == '?')) {
dp[x][y][z][0] = dp[x - 1][y][z][1] + dp[x - 1][y][z][2];
}
if (y > 0 && (s[p] == 'b' || s[p] == '?')) {
dp[x][y][z][1] = dp[x][y - 1][z][0] + dp[x][y - 1][z][2];
}
if (z > 0 && (s[p] == 'c' || s[p] == '?')) {
dp[x][y][z][2] = dp[x][y][z - 1][1] + dp[x][y][z - 1][0];
}
if (x + y + z == n) {
sp[x][y][z] = sp[x][y][z] + dp[x][y][z][0] + dp[x][y][z][1] + dp[x][y][z][2];
}
//if (sp[x][y][z].x != 0) {
// cout << x << " " << y << " " << z << " " << sp[x][y][z].x << "\n";
//}
}
}
}
int na, nb, nc;
na = nb = nc = 0;
for (auto it : s) {
if (it == 'a')
++na;
else if (it == 'b')
++nb;
else if (it == 'c')
++nc;
}
while (q--) {
int x, y, z;
cin >> x >> y >> z;
cout << sp[x + na][y + nb][z + nc].x << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 434016kb
input:
6 3 a?b??c 2 2 2 1 1 1 1 0 2
output:
3 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 19ms
memory: 434016kb
input:
6 3 ?????? 2 2 2 2 3 3 3 3 3
output:
30 72 96
result:
ok 3 lines
Test #3:
score: -100
Wrong Answer
time: 15ms
memory: 433956kb
input:
1 1 ? 0 1 1
output:
0
result:
wrong answer 1st lines differ - expected: '2', found: '0'