Submission #1099655

#TimeUsernameProblemLanguageResultExecution timeMemory
1099655Zero_OPHomework (CEOI22_homework)C++14
100 / 100
220 ms214472 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i) #define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i) #define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i) #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define sz(v) (int)v.size() #define dbg(x) "[" #x " = " << (x) << "]" template<typename T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; } using ll = long long; using ld = long double; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); } template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); } const int MAX = 4e6 + 5; int len, n; string s; int sz[MAX], l[MAX], r[MAX]; bitset<MAX> is_leaf, is_min; vector<int> adj[MAX]; void dfs(int u){ if(is_leaf[u]){ l[u] = r[u] = 1; sz[u] = 1; return; } int v1 = adj[u][0]; int v2 = adj[u][1]; dfs(v1); dfs(v2); sz[u] = sz[v1] + sz[v2]; if(is_min[u]){ l[u] = min(l[v1], l[v2]); r[u] = r[v1] + r[v2] - 1; } else{ l[u] = l[v1] + l[v2]; r[u] = max(sz[v1] + r[v2], sz[v2] + r[v1]); } } void testcase(){ cin >> s; len = sz(s); stack<int> st; rep(i, 0, len){ if(s[i] == '('){ ++n; if(!st.empty()){ adj[st.top()].push_back(n); } st.push(n); is_min[n] = (s[i - 1] == 'n'); } else if(s[i] == ')'){ st.pop(); } else if(s[i] == '?'){ ++n; is_leaf[n] = true; adj[st.top()].push_back(n); } } dfs(1); cout << r[1] - l[1] + 1 << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define filename "task" if(fopen(filename".inp", "r")){ freopen(filename".inp", "r", stdin); freopen(filename".out", "w", stdout); } int T = 1; //cin >> T; while(T--) testcase(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'bool minimize(T&, const T&)':
Main.cpp:15:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |     if(a > b) return a = b, true; return false;
      |     ^~
Main.cpp:15:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |     if(a > b) return a = b, true; return false;
      |                                   ^~~~~~
Main.cpp: In function 'bool maximize(T&, const T&)':
Main.cpp:20:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   20 |     if(a < b) return a = b, true; return false;
      |     ^~
Main.cpp:20:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   20 |     if(a < b) return a = b, true; return false;
      |                                   ^~~~~~
Main.cpp: In function 'int main()':
Main.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(filename".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(filename".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...