QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#710012 | #9536. Athlete Welcome Ceremony | kinoko777 | WA | 88ms | 240660kb | C++23 | 8.1kb | 2024-11-04 17:57:39 | 2024-11-04 17:57:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> p11;
typedef pair<string, int> ps1;
typedef pair<ll, ll> p1111;
#define vv vector
#define pb emplace_back
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define endl '\n'
#define Endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define per(a, b, c) for(int a = b; a <= c; a ++)
#define iper(a, b, c) for(int a = b; a < c; a ++)
#define rep(a, b, c) for(int a = b; a >= c; a --)
#define irep(a, b, c) for(int a = b; a > c; a --)
#define aper(A) for(auto i : A) cout << i << ' ';cout << '\n'
#define lowbit(x) ((x) & (-x))
#define debug(x) cout << (x) << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define PAI acos(-1)
using ll = long long;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<class T> void umin(T &x,T y){if(x>y)x=y;}
template<class T> void umax(T &x,T y){if(x<y)x=y;}
const int mod = 1e9 + 7, inf = 1e18;
const double eps = 1e-9;
void pre_work(){}
using ll = long long;
template <class T>
constexpr T power(T a, ll b)
{
T res = 1;
for (; b; b /= 2, a *= a)
{
if (b % 2)
{
res *= a;
}
}
return res;
}
constexpr ll mul(ll a, ll b, ll p)
{
ll res = a * b - ll(1.L * a * b / p) * p;
res %= p;
if (res < 0)
{
res += p;
}
return res;
}
template <int P>
struct MInt
{
int x;
constexpr MInt() : x{} {}
constexpr MInt(ll x) : x{norm(x % getMod())} {}
static int Mod;
constexpr static int getMod()
{
if (P > 0)
{
return P;
}
else
{
return Mod;
}
}
constexpr static void setMod(int Mod_)
{
Mod = Mod_;
}
constexpr int norm(int x) const
{
if (x < 0)
{
x += getMod();
}
if (x >= getMod())
{
x -= getMod();
}
return x;
}
constexpr int val() const
{
return x;
}
explicit constexpr operator int() const
{
return x;
}
constexpr MInt operator-() const
{
MInt res;
res.x = norm(getMod() - x);
return res;
}
constexpr MInt inv() const
{
assert(x != 0);
return power(*this, getMod() - 2);
}
constexpr MInt &operator*=(MInt rhs) &
{
x = 1LL * x * rhs.x % getMod();
return *this;
}
constexpr MInt &operator+=(MInt rhs) &
{
x = norm(x + rhs.x);
return *this;
}
constexpr MInt &operator-=(MInt rhs) &
{
x = norm(x - rhs.x);
return *this;
}
constexpr MInt &operator/=(MInt rhs) &
{
return *this *= rhs.inv();
}
friend constexpr MInt operator*(MInt lhs, MInt rhs)
{
MInt res = lhs;
res *= rhs;
return res;
}
friend constexpr MInt operator+(MInt lhs, MInt rhs)
{
MInt res = lhs;
res += rhs;
return res;
}
friend constexpr MInt operator-(MInt lhs, MInt rhs)
{
MInt res = lhs;
res -= rhs;
return res;
}
friend constexpr MInt operator/(MInt lhs, MInt rhs)
{
MInt res = lhs;
res /= rhs;
return res;
}
friend constexpr std::istream &operator>>(std::istream &is, MInt &a)
{
ll v;
is >> v;
a = MInt(v);
return is;
}
friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a)
{
return os << a.val();
}
friend constexpr bool operator==(MInt lhs, MInt rhs)
{
return lhs.val() == rhs.val();
}
friend constexpr bool operator!=(MInt lhs, MInt rhs)
{
return lhs.val() != rhs.val();
}
friend constexpr bool operator<(MInt lhs, MInt rhs)
{
return lhs.val() < rhs.val();
}
friend constexpr bool operator<=(MInt lhs, MInt rhs)
{
return lhs.val() <= rhs.val();
}
friend constexpr bool operator>(MInt lhs, MInt rhs)
{
return lhs.val() > rhs.val();
}
friend constexpr bool operator>=(MInt lhs, MInt rhs)
{
return lhs.val() >= rhs.val();
}
};
template <>
int MInt<0>::Mod = 998244353;
template <int V, int P>
constexpr MInt<P> CInv = MInt<P>(V).inv();
constexpr int P = 1e9 + 7;
using Z = MInt<P>;
struct Comb
{
int n;
std::vector<Z> _fac;
std::vector<Z> _invfac;
std::vector<Z> _inv;
Comb() : n{0}, _fac{1}, _invfac{1}, _inv{0} {}
Comb(int n) : Comb()
{
init(n);
}
void init(int m)
{
m = std::min(m, Z::getMod() - 1);
if (m <= n)
return;
_fac.resize(m + 1);
_invfac.resize(m + 1);
_inv.resize(m + 1);
for (int i = n + 1; i <= m; i++)
{
_fac[i] = _fac[i - 1] * i;
}
_invfac[m] = _fac[m].inv();
for (int i = m; i > n; i--)
{
_invfac[i - 1] = _invfac[i] * i;
_inv[i] = _invfac[i] * _fac[i - 1];
}
n = m;
}
Z fac(int m)
{
if (m > n)
init(2 * m);
return _fac[m];
}
Z invfac(int m)
{
if (m > n)
init(2 * m);
return _invfac[m];
}
Z inv(int m)
{
if (m > n)
init(2 * m);
return _inv[m];
}
Z binom(int n, int m)
{
if (n < m || m < 0)
return 0;
return fac(n) * invfac(m) * invfac(n - m);
}
} comb;
const int N = 310;
Z dp[N][N][N][3];
Z cnt[N][N][N];
int n, m;
void solve()
{
dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 1;
cin >> n >> m;
string s;
cin >> s;
s = ' ' + s;
int c = 0;
per(i, 1, n)
c += s[i] == '?';
int cnt1 = 0;
per(i, 1, n)
{
cnt1 += s[i] == '?';
per(j, 0, 300)
per(k, 0, 300)
{
if(s[i] == 'a')
dp[i][j][k][0] = dp[i - 1][j][k][1] + dp[i - 1][j][k][2];
else if(s[i] == 'b')
dp[i][j][k][1] = dp[i - 1][j][k][0] + dp[i - 1][j][k][2];
else if(s[i] == 'c')
dp[i][j][k][2] = dp[i - 1][j][k][0] + dp[i - 1][j][k][1];
else if(s[i] == '?')
{
if(j) dp[i][j][k][0] = dp[i - 1][j - 1][k][1] + dp[i - 1][j - 1][k][2];
if(k) dp[i][j][k][1] = dp[i - 1][j][k - 1][0] + dp[i - 1][j][k - 1][2];
dp[i][j][k][2] = dp[i - 1][j][k][0] + dp[i - 1][j][k][1];
}
}
}
for (int x = 0; x <= 3; x++)
for (int y = 0; y <= 3; y++)
for (int k = 0; k < 3; k++)
cout << dp[n][x][y][k] << " \n"[k == 2];
per(i, 0, 300)
per(j, 0, 300)
if(c - i - j >= 0)
cnt[i][j][c - i - j] = dp[n][i][j][0] + dp[n][i][j][1] + dp[n][i][j][2];
per(i, 0, 300)
per(j, 0, 300)
per(k, 1, 300)
cnt[i][j][k] = cnt[i][j][k] + cnt[i][j][k - 1];
per(i, 0, 300)
per(j, 1, 300)
per(k, 0, 300)
cnt[i][j][k] = cnt[i][j][k] + cnt[i][j - 1][k];
per(i, 1, 300)
per(j, 0, 300)
per(k, 0, 300)
cnt[i][j][k] = cnt[i][j][k] + cnt[i - 1][j][k];
while(m -- )
{
int x, y, z;
cin >> x >> y >> z;
cout << cnt[x][y][z] / 2 << endl;
}
}
signed main()
{
#ifdef LOCAL
freopen("oo.in", "r", stdin);
freopen("oo.out", "w", stdout);
#endif
IOS;
int tt = 1;
// cin >> tt;
pre_work();
while(tt --)
{
solve();
}
return 0;
}
/*
3 1
1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 88ms
memory: 240660kb
input:
6 3 a?b??c 2 2 2 1 1 1 1 0 2
output:
0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 1
result:
wrong answer 1st lines differ - expected: '3', found: '0 0 0'