Submission #838938

#TimeUsernameProblemLanguageResultExecution timeMemory
838938nononoHomework (CEOI22_homework)C++14
100 / 100
262 ms239196 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 5000005; string s; int n; vector<vector<int>> adj(mxN); int type[mxN]; int _min[mxN], _max[mxN]; void dfs(int u) { if(type[u] == -1) { _min[u] = 1; _max[u] = 1; return ; } int vL = adj[u][0]; int vR = adj[u][1]; dfs(vL); dfs(vR); if(type[u] == 0) { _min[u] = min(_min[vL], _min[vR]); _max[u] = _max[vL] + _max[vR]; } if(type[u] == 1) { _min[u] = _min[vL] + _min[vR]; _max[u] = min(_max[vL], _max[vR]); } } signed main() { #define taskname "" if(fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); cin >> s; n = s.size(); vector<int> qu; int vertex = 0, node = 0; for(int i = 1; i <= n; i ++) { if(s[n - i] == ')') { vertex ++ ; qu.push_back(vertex); } if(s[n - i] == '?') { vertex ++ ; node ++ ; qu.push_back(vertex); type[vertex] = -1; } if(s[n - i] == '(') { //for(int x : qu) cout << x << " "; cout << "\n"; int vL = qu.back(); qu.pop_back(); int vR = qu.back(); qu.pop_back(); int u = qu.back(); adj[u].push_back(vL); adj[u].push_back(vR); if(s.substr(n - i - 3, 3) == "min") type[u] = 0; if(s.substr(n - i - 3, 3) == "max") type[u] = 1; } } dfs(1); cout << (node - _max[1] + 1) - _min[1] + 1 << "\n"; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(taskname".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...