結果
問題 |
No.3040 Aoiスコア
|
ユーザー |
![]() |
提出日時 | 2025-03-01 19:07:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 122 ms / 1,000 ms |
コード長 | 3,325 bytes |
コンパイル時間 | 2,716 ms |
コンパイル使用メモリ | 283,864 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 21:02:45 |
合計ジャッジ時間 | 4,019 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).end() #define LB(v, x) (int)(lower_bound(ALL(v), x) - v.begin()) #define UQ(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()) #define IO ios::sync_with_stdio(false), cin.tie(nullptr); #define chmax(a, b) (a) = (a) < (b) ? (b) : (a) #define chmin(a, b) (a) = (a) < (b) ? (a) : (b) using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; template <ll MOD> struct ModInt { ll value; ModInt(ll x = 0) { value = (x >= 0 ? x % MOD : MOD - (-x) % MOD); } ModInt operator-() const { return ModInt(-value); } ModInt operator+() const { return ModInt(*this); } ModInt& operator+=(const ModInt& other) { value += other.value; if (value >= MOD) value -= MOD; return *this; } ModInt& operator-=(const ModInt& other) { value += MOD - other.value; if (value >= MOD) value -= MOD; return *this; } ModInt& operator*=(const ModInt other) { value = value * other.value % MOD; return *this; } ModInt& operator/=(ModInt other) { (*this) *= other.inv(); return *this; } ModInt operator+(const ModInt& other) const { return ModInt(*this) += other; } ModInt operator-(const ModInt& other) const { return ModInt(*this) -= other; } ModInt operator*(const ModInt& other) const { return ModInt(*this) *= other; } ModInt operator/(const ModInt& other) const { return ModInt(*this) /= other; } ModInt pow(ll x) const { ModInt ret(1), mul(value); while (x) { if (x & 1) ret *= mul; mul *= mul; x >>= 1; } return ret; } ModInt inv() const { return pow(MOD - 2); } bool operator==(const ModInt& other) const { return value == other.value; } bool operator!=(const ModInt& other) const { return value != other.value; } friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.value; } friend istream& operator>>(istream& is, ModInt& x) { ll v; is >> v; x = ModInt<MOD>(v); return is; } static constexpr ll get_mod() { return MOD; } }; using Mod998 = ModInt<998244353>; using Mod107 = ModInt<1000000007>; using mint = Mod998; int main() { int N, M; string S; cin >> N >> M >> S; vector<vector<int>> G(N); for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; u--, v--; G[u].push_back(v), G[v].push_back(u); } vector<mint> po(N + 1); po[0] = 1; for (int i = 1; i <= N; i++) po[i] = po[i - 1] * 26; int q = count(ALL(S), '?'); mint ans = 0; for (int i = 0; i < N; i++) { if (S[i] == 'o' || S[i] == '?') { int d = ssize(G[i]); for (int j = 0; j < d; j++) { int a = G[i][j]; if (S[a] == 'a' || S[a] == '?') { for (int k = 0; k < d; k++) { int b = G[i][k]; if (S[b] == 'i' || (S[b] == '?' && a != b)) { int r = (S[a] == '?') + (S[i] == '?') + (S[b] == '?'); ans += po[q - r]; } } } } } } cout << ans << endl; }