QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317568 | #8170. $N^a (\log N)^b$ | ucup-team197# | Compile Error | / | / | C++20 | 3.0kb | 2024-01-29 05:53:15 | 2024-01-29 05:53:17 |
Judging History
This is the latest submission verdict.
- [2024-01-29 05:53:17]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-01-29 05:53:15]
- Submitted
answer
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
typedef long long BigInt;
typedef long long ll;
struct Node{
pair<BigInt, BigInt> plus_num, mult_num, active_num;
bool log_node = false;
Node(bool log_node = false){
plus_num = mult_num = active_num = {0, 0};
this->log_node = log_node;
}
};
string s;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> s;
s += ")";
stack<Node> st;
st.push(Node());
st.push(Node());
BigInt curr_num = 0;
bool exists_curr_num = false;
bool is_n = false, is_log = false;
for(int i = 0; i < s.size(); ++i){
if(isdigit(s[i])){
curr_num *= 10;
curr_num += s[i] - '0';
exists_curr_num = true;
continue;
}
if(exists_curr_num){
if(st.top().active_num == pair<BigInt, BigInt>{1, 0}){
st.top().active_num = {curr_num, 0};
}
else if(st.top().active_num == pair<BigInt, BigInt>{0, 1}){
st.top().active_num = {0, curr_num};
}
exists_curr_num = false;
curr_num = 0;
}
if(s[i] == 'N'){
st.top().active_num = {1, 0};
continue;
}
if(s[i] == 'l'){
st.push(Node(true));
i += 3;
continue;
}
if(s[i] == '('){
st.push(Node());
continue;
}
if(s[i] == '^'){
continue;
}
if(s[i] == ')'){
auto &t = st.top();
t.mult_num.first += t.active_num.first;
t.mult_num.second += t.active_num.second;
t.plus_num = max(t.plus_num, t.mult_num);
auto p_num = t.plus_num;
if(t.log_node){
if(p_num.first || p_num.second){
p_num = pair<BigInt, BigInt>{0, 1};
}
else{
p_num = pair<BigInt, BigInt>{0, 0};
}
}
st.pop();
st.top().active_num = p_num;
continue;
}
if(s[i] == '+'){
auto &t = st.top();
t.mult_num.first += t.active_num.first;
t.mult_num.second += t.active_num.second;
t.active_num = pair<BigInt, BigInt>{0, 0};
t.plus_num = max(t.plus_num, t.mult_num);
t.mult_num = pair<BigInt, BigInt>{0, 0};
continue;
}
if(s[i] == '*'){
auto &t = st.top();
t.mult_num.first += t.active_num.first;
t.mult_num.second += t.active_num.second;
t.active_num = pair<BigInt, BigInt>{0, 0};
continue;
}
}
assert(st.size() == 1);
auto ans = st.top().active_num;
cout << ans.first << " " << ans.second << "\n";
}
Details
answer.code: In function ‘int main()’: answer.code:107:5: error: ‘assert’ was not declared in this scope 107 | assert(st.size() == 1); | ^~~~~~ answer.code:5:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’? 4 | #include <vector> +++ |+#include <cassert> 5 |