結果
問題 | No.1677 mæx |
ユーザー | sapphire__15 |
提出日時 | 2021-09-10 22:44:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 5,260 bytes |
コンパイル時間 | 1,567 ms |
コンパイル使用メモリ | 116,288 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-06-12 02:08:41 |
合計ジャッジ時間 | 2,035 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 13 ms
6,608 KB |
testcase_05 | AC | 13 ms
6,624 KB |
testcase_06 | AC | 13 ms
6,616 KB |
testcase_07 | AC | 12 ms
6,528 KB |
testcase_08 | AC | 13 ms
6,748 KB |
testcase_09 | AC | 12 ms
6,764 KB |
testcase_10 | AC | 12 ms
6,616 KB |
testcase_11 | AC | 12 ms
6,656 KB |
testcase_12 | AC | 12 ms
6,636 KB |
testcase_13 | AC | 12 ms
6,588 KB |
testcase_14 | AC | 12 ms
6,652 KB |
testcase_15 | AC | 13 ms
6,644 KB |
testcase_16 | AC | 12 ms
6,528 KB |
testcase_17 | AC | 13 ms
6,656 KB |
testcase_18 | AC | 12 ms
6,784 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 14 ms
8,192 KB |
ソースコード
#include <iostream> #include <map> #include <vector> #include <algorithm> #include <numeric> #include <cassert> #include <cmath> #include <queue> #include <set> #include <unordered_map> #include <unordered_set> #include <functional> #define rep(i,n,s) for(int i = (s); i < int(n); i++) #define MM << " " << #define all(x) x.begin(), x.end() template<class T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; using ll = long long; using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>; template<class T> bool chmin(T& a, const T b) { if(a > b) { a = b; return true; } else { return false; } } template<class T> bool chmax(T& a, const T b) { if(a < b) { a = b; return true; } else { return false; } } template<class T> void vdeb(std::vector<T> &da) { auto n = da.size(); for(size_t i = 0; i < n; i++) { if(i == n-1) std::cout << da[i] << std::endl; else std::cout << da[i] << " "; } } template<> void vdeb(std::vector<std::string> &da) { auto n = da.size(); for(size_t i = 0; i < n; i++) { std::cout << da[i] << std::endl; } } struct modint { long long num; const static long long p = 998244353; constexpr static long long pow(long long n, long long k) {//n^k(mod p) long long ret = 1; while(k) { if(k&1) ret = ret * n % p; n = n * n % p; k >>= 1; } return ret; } // a*A + b*B = 1 constexpr static void euclid(long long &a, long long &b) { // a>=b A*b+B*(a-a/b*b)=1 if (a == 1) { a = 1; } else { long long A = b, B = a % b; euclid(A, B); b = (A - (p + a / b) % p * B % p + p) % p; a = B; } } constexpr static long long rev(const long long n) {// n*x-p*y=1 //long long q = p; //euclid(p, n, p); //return n % q; return pow(n,p-2); } constexpr modint() : num(0) {} constexpr modint(long long x) : num(x%p < 0 ? x%p+p : x%p) {} constexpr modint inv() const {return rev(num);} modint operator-() const {return modint(p-num);} modint& operator+=(const modint &other){ num = (num + other.num) % p; return *this; } modint& operator-=(const modint &other){ num = (num - other.num + p) % p; return *this; } modint& operator*=(const modint &other){ num = (num * other.num) % p; return *this; } modint& operator/=(const modint &other){ (*this) *= other.inv(); return *this; } modint& operator+=(const long long &other){ num = (num + other) % p; return *this; } modint& operator-=(const long long &other){ num = (num - other + p) % p; return *this; } modint& operator*=(const long long &other){ num = (num * other) % p; return *this; } modint& operator/=(const long long &other){ (*this) *= rev(other); return *this; } modint& operator++(){return *this += 1;} modint& operator--(){return *this -= 1;} modint& operator=(const long long &other){return (*this) = modint(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 operator/(const modint &other) const{return modint(*this) /= other;} modint operator+(const long long &other) const{return modint(*this) += other;} modint operator-(const long long &other) const{return modint(*this) -= other;} modint operator*(const long long &other) const{return modint(*this) *= other;} modint operator/(const long long &other) const{return modint(*this) /= other;} bool operator==(const modint &other) const{return num == other.num;} }; std::istream& operator>>(std::istream &is, modint x) { is >> x.num; return is; } std::ostream& operator<<(std::ostream &os, const modint &x){ os << x.num; return os; } using namespace std; using sitr = string::iterator; int mymax[3][3] = {{0, 1, 2}, {1, 1, 2}, {2, 2, 2}}; int mymex[3][3] = {{1, 2, 1}, {2, 0, 0}, {1, 0, 0}}; vector<modint> parser(sitr &itr) { vector<modint> ret(3); if(*itr == '?') { ret[0] += 1; ret[1] += 1; ret[2] += 1; ++itr; return ret; } else if('0' <= *itr && *itr <= '2') { ret[*itr - '0'] += 1; ++itr; return ret; } bool a = false, e = false; ++itr; switch(*itr) { case 'a': a = true; break; case 'e': e = true; break; default: a = e = true; } advance(itr, 3); auto lhs = parser(itr); ++itr; auto rhs = parser(itr); ++itr; rep(i,3,0) rep(j,3,0) { if(a) ret[mymax[i][j]] += lhs[i]*rhs[j]; if(e) ret[mymex[i][j]] += lhs[i]*rhs[j]; } return ret; } int main() { string s; cin >> s; int k; cin >> k; auto itr = s.begin(); auto ans = parser(itr); cout << ans[k] << endl; }