QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#705775 | #9536. Athlete Welcome Ceremony | ucup-team3584# | WA | 1ms | 3760kb | C++23 | 5.4kb | 2024-11-03 01:31:15 | 2024-11-03 01:31:15 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
template <int mod> struct static_modint {
using mint = static_modint;
int x;
static_modint() : x(0) {}
static_modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
mint &operator+=(const mint &rhs) {
if ((x += rhs.x) >= mod) x -= mod;
return *this;
}
mint &operator-=(const mint &rhs) {
if ((x += mod - rhs.x) >= mod) x -= mod;
return *this;
}
mint &operator*=(const mint &rhs) {
x = (int)(1LL * x * rhs.x % mod);
return *this;
}
mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); }
mint pow(long long n) const {
mint _x = *this, r = 1;
while (n) {
if (n & 1) r *= _x;
_x *= _x;
n >>= 1;
}
return r;
}
mint inv() const { return pow(mod - 2); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
friend bool operator==(const mint &lhs, const mint &rhs) { return lhs.x == rhs.x; }
friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs.x != rhs.x; }
friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
friend istream &operator>>(istream &is, mint &a) {
int64_t t;
is >> t;
a = static_modint<mod>(t);
return (is);
}
};
const unsigned int mod = 1e9 + 7;
using modint = static_modint<mod>;
modint mod_pow(ll n, ll x) { return modint(n).pow(x); }
modint mod_pow(modint n, ll x) { return n.pow(x); }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
string s;
cin >> s;
vector<vector<modint>> dp[3];
for (auto &i : dp) {
i.resize(n + 1, vector<modint>(n + 1, 0));
}
if (s[0] == '?') {
dp[0][1][0] = 1;
dp[1][0][1] = 1;
dp[2][0][0] = 1;
} else {
dp[s[0] - 'a'][0][0] = 1;
}
for (int i = 1; i < n; i++) {
vector<vector<modint>> ndp[3];
for (auto &j : ndp) {
j.resize(n + 1, vector<modint>(n + 1, 0));
}
if (s[i] != '?') {
for (int j = 0; j < 3; ++j) {
if (j == (s[i] - 'a')) continue;
for (int k = 0; k <= n; ++k) {
for (int l = 0; l <= n; ++l) {
ndp[s[i] - 'a'][k][l] += dp[j][k][l];
}
}
}
} else {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k <= n; ++k) {
for (int l = 0; l <= n; ++l) {
if (dp[j][k][l] == 0) continue;
for (int m = 0; m < 3; ++m) {
if (m == j) continue;
if (m == 0) {
ndp[0][k + 1][l] += dp[j][k][l];
} else if (m == 1) {
ndp[1][k][l + 1] += dp[j][k][l];
} else {
ndp[2][k][l] += dp[j][k][l];
}
}
}
}
}
}
swap(dp, ndp);
}
int cnt = 0;
for (char c : s) {
if (c == '?') cnt++;
}
vector<vector<modint>> sum(n + 1, vector<modint>(n + 1, 0));
vector<vector<modint>> ab(n + 1, vector<modint>(n + 1, 0));
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
sum[i][j] = dp[0][i][j] + dp[1][i][j] + dp[2][i][j];
if (sum[i][j] != 0) {
ab[i + j][i] += sum[i][j];
}
if (j) sum[i][j] += sum[i][j - 1];
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
sum[j][i] += sum[j - 1][i];
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
ab[i][j] += ab[i][j - 1];
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
ab[j][i] += ab[j - 1][i];
}
}
while (q--) {
int a, b, c;
cin >> a >> b >> c;
a = min(a, n);
b = min(b, n);
c = min(c, n);
modint res = sum[a][b];
for (int i = 0; i <= n; ++i) {
if (i + c >= cnt) break;
int l = 0, r = min(i, a);
l = max(l, i - b);
if (l <= r) {
res -= ab[i][r] - (l ? ab[i][l - 1] : 0);
}
}
cout << res << "\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 0ms
memory: 3524kb
input:
6 3 ?????? 2 2 2 2 3 3 3 3 3
output:
30 72 96
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
10 10 acab?cbaca 0 2 0 1 1 2 4 2 3 1 1 1 3 5 1 0 5 2 2 2 0 1 2 5 4 3 0 1 1 3
output:
0 1 1 1 1 0 1 1 1 1
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
10 10 ?c?c?cbac? 10 5 1 5 8 7 9 2 6 5 7 1 5 2 6 5 6 5 5 10 3 9 1 10 2 5 9 1 2 9
output:
16 16 11 16 11 16 16 5 11 0
result:
ok 10 lines
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3672kb
input:
50 100 ?abacbacab?cbcbcb?acabcbabcbcacbababc?caba?acacbca 8 3 8 2 4 8 8 7 3 0 9 2 10 8 7 7 6 5 4 10 2 6 9 3 3 6 6 9 10 8 2 5 8 8 1 0 3 5 0 1 0 6 5 0 8 6 5 5 1 7 9 7 7 10 4 7 5 6 6 4 10 1 2 4 1 7 10 0 8 7 6 3 1 9 1 4 7 2 8 4 0 8 6 1 5 10 4 5 8 2 5 8 4 4 5 9 5 2 1 1 10 9 4 10 1 8 4 3 8 9 9 8 0 1 0 8 0...
output:
8 8 8 0 8 8 6 8 8 8 8 1000000006 999999999 0 1 8 4 8 8 8 2 4 1 8 0 6 999999999 0 8 6 8 8 1000000006 4 0 8 8 0 0 8 0 0 8 8 8 4 8 8 8 8 0 0 1000000003 4 8 8 1 8 7 6 7 0 8 8 8 0 4 7 8 4 1000000003 8 0 4 8 8 8 7 8 4 7 0 8 8 8 0 0 2 8 8 8 4 4 999999999 8 999999999 8 8 1 1000000006
result:
wrong answer 12th lines differ - expected: '0', found: '1000000006'