QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#315556 | #8170. $N^a (\log N)^b$ | ucup-team087# | WA | 3ms | 14176kb | C++14 | 3.4kb | 2024-01-27 14:14:52 | 2024-01-27 14:14:52 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
char S[100'010];
int cur;
void eat(char tar) {
if (S[cur] != tar) cerr << "[eat] FAIL " << cur << " " << S[cur] << " " << tar << endl;
assert(S[cur] == tar);
++cur;
}
/*
⟨expr⟩ ::= ⟨term⟩ | ⟨expr⟩ ‘+’ ⟨term⟩
⟨term⟩ ::= ⟨factor⟩ | ⟨term⟩ ‘*’ ⟨factor⟩
⟨factor⟩ ::= ‘N’ | ‘N^’ ⟨number⟩ | ‘log(’ ⟨expr⟩ ‘)’ | ‘log(’ ⟨expr⟩ ‘)^’ ⟨number⟩ | ‘(’ ⟨expr⟩ ‘)’
⟨number⟩ ::= ⟨nonzero_digit⟩ | ⟨nonzero_digit⟩⟨digit_string⟩
⟨digit_string⟩ ::= ⟨digit⟩ | ⟨digit⟩⟨digit_string⟩
⟨nonzero_digit⟩ ::= ‘1’ | ‘2’ | ‘3’ | ‘4’ | ‘5’ | ‘6’ | ‘7’ | ‘8’ | ‘9’
⟨digit⟩ ::= ‘0’ | ⟨nonzero_digit⟩
*/
using P = pair<Int, pair<Int, Int>>;
P expr();
P term();
P factor();
Int number();
P expr() {
P ret = term();
for (; S[cur] == '+'; ) {
eat('+');
const P tmp = term();
chmax(ret, tmp);
}
return ret;
}
P term() {
P ret = factor();
for (; S[cur] == '*'; ) {
eat('*');
const P tmp = factor();
ret.first += tmp.first;
ret.second.first += tmp.second.first;
ret.second.second += tmp.second.second;
}
return ret;
}
P factor() {
P ret;
if (S[cur] == 'N') {
eat('N');
Int e;
if (S[cur] == '^') {
eat('^');
e = number();
} else {
e = 1;
}
ret = P(e, make_pair(0, 0));
} else if (S[cur] == 'l') {
eat('l');
eat('o');
eat('g');
eat('(');
const P tmp = expr();
eat(')');
Int e;
if (S[cur] == '^') {
eat('^');
e = number();
} else {
e = 1;
}
ret = P(0, make_pair(tmp.first ? e : 0, (tmp.second.first + tmp.second.second) ? 1 : 0));
} else {
eat('(');
ret = expr();
eat(')');
}
return ret;
}
Int number() {
Int x = 0;
for (; isdigit(S[cur]); ) {
(x *= 10) += (S[cur++] - '0');
}
return x;
}
int main() {
for (; ~scanf("%s", S); ) {
cur = 0;
const auto ans = expr();
printf("%lld %lld\n", ans.first, ans.second.first + ans.second.second);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3908kb
input:
N*log(N^2)*log(N)+N+log(N^1+N)^2*N
output:
1 2
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3928kb
input:
N*log(log(N))
output:
1 1
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
(((N))*N^234567890+N^2)
output:
234567891 0
result:
ok 2 tokens
Test #4:
score: 0
Accepted
time: 1ms
memory: 4008kb
input:
log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)+log(N)...
output:
0 1
result:
ok 2 tokens
Test #5:
score: 0
Accepted
time: 1ms
memory: 4012kb
input:
log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)*log(N)...
output:
0 14285
result:
ok 2 tokens
Test #6:
score: 0
Accepted
time: 3ms
memory: 7984kb
input:
log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(log(...
output:
0 1
result:
ok 2 tokens
Test #7:
score: 0
Accepted
time: 0ms
memory: 14176kb
input:
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
0 1
result:
ok 2 tokens
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 4020kb
input:
log(log(N^39187693)^548521633+log(log(N*N^2+N*N^71962925)+log(N*N+N)*log(N+N)+log((log(log(N)^8))*log(log(N*N*N))))*log((N+log(N)*N+N*log(N)^958544341))^978444210)+log((log(N)^573073630)*log(log(N)^857299008)*(N+N^3+log(N))*log(N)+log(log(N^5943+((N*N)*N^3371597)+N*N*(N)*N^3732602)^195356379)^910014...
output:
0 706139984
result:
wrong answer 2nd words differ - expected: '706139983', found: '706139984'