Submission #803041

#TimeUsernameProblemLanguageResultExecution timeMemory
803041ezdpHomework (CEOI22_homework)C++14
100 / 100
225 ms174840 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #define endl '\n' #define pb push_back #define fr first #define sc second #define ll long long int #define ld long double #define lsb(idx) idx&(-idx) #define bin(x) bitset<32>(x).to_string() #define all(A) A.begin(), A.end() #define de(x) cout << #x << " = " << x << endl; using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T> using matrix = vector<vector<T>>; // find_by_order(x) -> x-th element in the set // order_of_key(x) -> how many elements are less than x // insert(x) -> inserts x into the set const int MAXN = 2e7; int T = 1, type[MAXN + 5]; tuple<int, int, int> interval[MAXN + 5]; matrix<int> G; void dfs(int u = 1){ if(type[u] == 'l'){ interval[u] = {1, 1, 1}; return; } for(auto v : G[u]) dfs(v); auto [l1, r1, s1] = interval[G[u][0]]; auto [l2, r2, s2] = interval[G[u][1]]; if(type[u] == 'n'){ interval[u] = {min(l1, l2), r1 + r2 - 1, s1 + s2}; return; } if(type[u] == 'x'){ interval[u] = {l1 + l2, max(r1 + s2, s1 + r2), s1 + s2}; return; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("filename.in" , "r", stdin); // freopen("filename.out", "w", stdout); string t; cin >> t; stack<int> st; G.resize(1); for(int i = 0; i < t.size(); i ++){ if(t[i] == '(' || t[i] == '?'){ G.pb(vector<int>()); type[T] = (t[i] == '(' ? t[i - 1] : 'l'); if(!st.empty()){ G[st.top()].pb(T); } if(t[i] == '(') st.push(T); ++ T; } if(t[i] == ')'){ st.pop(); } } dfs(); cout << get<1>(interval[1]) - get<0>(interval[1]) + 1 << endl; } /** */

Compilation message (stderr)

Main.cpp: In function 'void dfs(int)':
Main.cpp:37:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |  auto [l1, r1, s1] = interval[G[u][0]];
      |       ^
Main.cpp:38:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |  auto [l2, r2, s2] = interval[G[u][1]];
      |       ^
Main.cpp: In function 'int main()':
Main.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for(int i = 0; i < t.size(); i ++){
      |                 ~~^~~~~~~~~~
#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...