Submission #865537

#TimeUsernameProblemLanguageResultExecution timeMemory
865537mychecksedadHomework (CEOI22_homework)C++17
100 / 100
173 ms205152 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 3e6+100, M = 1e5+10, K = 52, MX = 30; vector<int> g[N]; vector<int> tp; int sz[N]; pair<int, int> dfs(int v){ sz[v] = tp[v] == 2; if(tp[v] == 2) return {1, 1}; pair<int, int> x = dfs(g[v][0]); pair<int, int> y = dfs(g[v][1]); // cout << g[v][0] << ": " << x.first << ' ' << x.second << '|' << g[v][1] << ": " << y.first << ' ' << y.second << '\n'; sz[v] += sz[g[v][0]]; sz[v] += sz[g[v][1]]; if(tp[v] == 0) return {min(x.first, y.first), x.second + y.second - 1}; return {x.first + y.first, max(sz[g[v][0]] + y.second, x.second + sz[g[v][1]])}; } string s; void solve(){ cin >> s; int n = 0, mx = 0, mn = 0; int cur = 1; tp.resize(s.size()+2); vector<int> last; for(int i = 0 ; i < s.length(); ++i){ if(s[i] == '?'){ tp[cur] = 2; if(!last.empty()){ g[last.back()].pb(cur); } ++cur; }else if(s[i] == '('){ if(!last.empty()){ g[last.back()].pb(cur); } if(s[i - 1] == 'n') tp[cur] = 0; else if(s[i - 1] == 'x') tp[cur] = 1; last.pb(cur); ++cur; }else if(s[i] == ')'){ last.pop_back(); } } auto R = dfs(1); cout << R.second-R.first+1; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin >> tt; while(tt--){ solve(); // en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 0 ; i < s.length(); ++i){
      |                   ~~^~~~~~~~~~~~
Main.cpp:30:7: warning: unused variable 'n' [-Wunused-variable]
   30 |   int n = 0, mx = 0, mn = 0;
      |       ^
Main.cpp:30:14: warning: unused variable 'mx' [-Wunused-variable]
   30 |   int n = 0, mx = 0, mn = 0;
      |              ^~
Main.cpp:30:22: warning: unused variable 'mn' [-Wunused-variable]
   30 |   int n = 0, mx = 0, mn = 0;
      |                      ^~
Main.cpp: In function 'int main()':
Main.cpp:62:15: warning: unused variable 'aa' [-Wunused-variable]
   62 |   int tt = 1, aa;
      |               ^~
#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...