結果
問題 | No.1677 mæx |
ユーザー | 夜 |
提出日時 | 2021-11-19 20:28:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,657 bytes |
コンパイル時間 | 1,194 ms |
コンパイル使用メモリ | 102,860 KB |
実行使用メモリ | 21,544 KB |
最終ジャッジ日時 | 2024-06-10 06:10:33 |
合計ジャッジ時間 | 5,415 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
14,904 KB |
testcase_01 | AC | 4 ms
7,876 KB |
testcase_02 | AC | 4 ms
7,980 KB |
testcase_03 | AC | 4 ms
7,980 KB |
testcase_04 | AC | 38 ms
8,404 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 12 ms
8,428 KB |
testcase_08 | AC | 32 ms
8,336 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 3 ms
8,032 KB |
testcase_20 | AC | 4 ms
7,940 KB |
testcase_21 | TLE | - |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; string s; int k; int e[3][3] = { {1,2,1},{2,0,0},{1,0,0} }; int a[3][3] = { {0,1,2},{1,1,2},{2,2,2} }; vector<tuple<long long, long long, long long>> mem(200020); long long mod = 998244353; tuple<long long,long long,long long> expression(int i) { if (mem[i] != make_tuple(-1, -1, -1)) { return mem[i]; } int i2 = i; if (s[i] == 'm') { i++; tuple<long long, long long, long long> ans = { 0, 0, 0 }; long long ans1[3] = { 0,0,0 }; int i1 = i; if (s[i1] == 'e' || s[i1] == '?') { tuple<long long, long long, long long> t = expression(i + 3); if (s[i + 3] == 'm') { i += 7; int now = 1; while (now != 0) { if (s[i] == '(') { now++; } if (s[i] == ')') { now--; } i++; } } else { i += 2; } tuple<long long, long long, long long> t1 = expression(i + 1); long long u[3] = { get<0>(t),get<1>(t),get<2>(t) }; long long u1[3] = { get<0>(t1),get<1>(t1),get<2>(t1) }; for (int k = 0; k < 3; k++) { for (int j = 0; j < 3; j++) { ans1[e[k][j]] += u[k] * u1[j] % mod; ans1[e[k][j]] %= mod; } } } if (s[i1] == 'a' || s[i1] == '?') { tuple<long long, long long, long long> t = expression(i1 + 3); if (s[i1 + 3] == 'm') { i1 += 7; int now = 1; while (now != 0) { if (s[i1] == '(') { now++; } if (s[i1] == ')') { now--; } i1++; } } else { i1 += 2; } tuple<long long, long long, long long> t1 = expression(i1 + 1); long long u[3] = { get<0>(t),get<1>(t),get<2>(t) }; long long u1[3] = { get<0>(t1),get<1>(t1),get<2>(t1) }; for (int k = 0; k < 3; k++) { for (int j = 0; j < 3; j++) { ans1[a[k][j]] += u[k] * u1[j] % mod; ans1[a[k][j]] %= mod; } } } ans = { ans1[0],ans1[1],ans1[2] }; mem[i2] = ans; return ans; } else { if (s[i] == '0') { mem[i2] = { 1,0,0 }; return { 1,0,0 }; } else if (s[i] == '1') { mem[i2] = { 0,1,0 }; return { 0,1,0 }; } else if (s[i] == '2') { mem[i2] = { 0,0,1 }; return { 0,0,1 }; } else { mem[i2] = { 1,1,1 }; return { 1,1,1 }; } } } int main() { cin >> s >> k; for (int i = 0; i < s.size(); i++) { mem[i] = { -1,-1,-1 }; } tuple<long long, long long, long long> ans1 = expression(0); long long ans[3] = { get<0>(ans1),get<1>(ans1),get<2>(ans1) }; cout << ans[k] << endl; }