Submission #709351

#TimeUsernameProblemLanguageResultExecution timeMemory
709351vjudge1Homework (CEOI22_homework)C++17
23 / 100
125 ms23116 KiB
#include<bits/stdc++.h> #define x first #define y second #define sz(v) (int)v.size() #define pb push_back #define nl "\n" using namespace std; const int N = (int)1e6 + 7; const int inf = (int)1e9 + 7; int n, sz[900], e[N], mn[900][1 << 16], mx[900][1 << 16], L[900], R[900]; int timer = 1; vector<int> bv[20]; string s; void calc(int v, int l, int r) { fill(mn[v], mn[v] + (1 << n), inf); if(l == r) { sz[v] = 1; for(int i = 0; i < n; ++i) { mx[v][1 << i] = mn[v][1 << i] = i; } return; } bool tp = (s[l + 1] == 'a'); int mid = e[l]; L[v] = ++timer; calc(L[v], l + 4, mid - 1); R[v] = ++timer; calc(R[v], mid + 1, r - 1); sz[v] += sz[L[v]]; sz[v] += sz[R[v]]; for(int mask : bv[sz[L[v]]]) { int msk = (((1 << n) - 1) ^ mask); for(int s = msk; s; s = (s - 1) & msk) { if(tp) { mx[v][mask | s] = max(mx[v][mask | s], max(mx[L[v]][mask], mx[R[v]][s])); mn[v][mask | s] = min(mn[v][mask | s], max(mn[L[v]][mask], mn[R[v]][s])); } else { mx[v][mask | s] = max(mx[v][mask | s], min(mx[L[v]][mask], mx[R[v]][s])); mn[v][mask | s] = min(mn[v][mask | s], min(mn[L[v]][mask], mn[R[v]][s])); } } } } int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cin >> s; for(int i = 0; i < sz(s); ++i) { if(s[i] == '?') { n++; } } stack<int> st; for(int i = 0; i < sz(s); ++i) { if(s[i] == 'm') st.push(i); if(s[i] == ',') { assert(!st.empty()); e[st.top()] = i; st.pop(); } } for(int mask = 0; mask < (1 << n); ++mask) { int x = __builtin_popcount(mask); bv[x].pb(mask); } calc(1, 0, sz(s) - 1); cout << mx[1][(1 << n) - 1] - mn[1][(1 << n) - 1] + 1 << nl; return 0; }
#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...