Submission #2586714
Source Code Expand
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define show(x) cout << #x << " = " << x << endl; using namespace std; using ll = long long; using pii = pair<int,int>; /* <expr> ::= number | "("<expr>","<expr>")" | "("<expr>"*"<expr>")" <number> ::= <digit> | <number><digit> <digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" */ ll mod = 998244353; string s; int pos = 0; struct A{ ll x,y; bool f; A(ll a,ll b){ x = a; y = b; f = true; } A(ll a){ x = a; y = 0; f = false; } }; A operator*(A &X,A &Y){ if(X.f == Y.f){ return A((X.x*Y.x+X.y*Y.y)%mod); }else{ if(X.f){ return A((X.x*Y.x)%mod,(X.y*Y.x)%mod); }else{ return A((Y.x*X.x)%mod,(Y.y*X.x)%mod); } } } A number(){ ll res = 0; while(isdigit(s[pos])){ res *= 10; res += s[pos] -'0'; res %= mod; pos++; } return A(res); } A cal(){ if(isdigit(s[pos])){ return number(); } assert(s[pos] == '('); pos++; A a = cal(); char op = s[pos]; pos++; A b = cal(); assert(s[pos] == ')'); pos++; if(op == ','){ assert(!a.f and !b.f); return A(a.x,b.x); }else{ assert(op == '*'); return a*b; } } int main(){ cin >> s; A ans = cal(); cout << ans.x << endl; }
Submission Info
Submission Time | |
---|---|
Task | E - ベクトル式 |
User | polyomino |
Language | C++14 (GCC 5.4.1) |
Score | 1 |
Code Size | 1939 Byte |
Status | AC |
Exec Time | 6 ms |
Memory | 512 KB |
Judge Result
Set Name | sample | all | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1 / 1 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt, sample-03.txt |
all | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 1 ms | 256 KB |
01-02.txt | AC | 1 ms | 256 KB |
01-03.txt | AC | 1 ms | 256 KB |
01-04.txt | AC | 2 ms | 256 KB |
01-05.txt | AC | 5 ms | 512 KB |
01-06.txt | AC | 5 ms | 512 KB |
01-07.txt | AC | 5 ms | 512 KB |
01-08.txt | AC | 5 ms | 512 KB |
01-09.txt | AC | 1 ms | 256 KB |
01-10.txt | AC | 6 ms | 512 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |
sample-03.txt | AC | 1 ms | 256 KB |