Submission #1235063

#TimeUsernameProblemLanguageResultExecution timeMemory
1235063avighnaHomework (CEOI22_homework)C++20
0 / 100
350 ms312808 KiB
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string s; std::cin >> s; if (s[0] != 'm') { std::cout << "1\n"; return 0; } std::vector<std::vector<int>> at_depths; for (int i = 0, depth = 0; i < s.length(); ++i) { depth += s[i] == '('; depth -= s[i] == ')'; if (s[i] == ',') { if (at_depths.size() <= depth) { at_depths.resize(depth + 1); } at_depths[depth].push_back(i); } } std::vector<std::vector<int>> adj; std::vector<bool> is_max; // 0 == min, 1 == max int node = 0; auto make = [&](auto &&self, int l, int r, int d) -> int { int cur = node++; while (adj.size() <= cur) { adj.push_back({}); is_max.push_back(false); } if (s[l] == '?') { return cur; } is_max[cur] = s[l + 1] == 'a'; int prev = l + 4; for (auto it = std::lower_bound(at_depths[d].begin(), at_depths[d].end(), l); it != at_depths[d].end() and *it <= r; ++it) { int u = self(self, prev, *it - 1, d + 1); adj[cur].push_back(u); prev = *it + 1; } int u = self(self, prev, r - 1, d + 1); adj[cur].push_back(u); return cur; }; make(make, 0, s.length() - 1, 1); const int n = std::count(s.begin(), s.end(), '?'); std::vector<int> min_cnt(node), max_cnt(node); auto dfs = [&](auto &&self, int u) { if (adj[u].empty()) { return; } min_cnt[u] += !is_max[u]; max_cnt[u] += is_max[u]; for (auto &i : adj[u]) { self(self, i); min_cnt[u] += min_cnt[i]; max_cnt[u] += max_cnt[i]; } }; dfs(dfs, 0); if (s[1] == 'i') { std::cout << max_cnt[0] + 1 << '\n'; } else { std::cout << min_cnt[0] + 1 << '\n'; } }
#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...