Submission #947374

#TimeUsernameProblemLanguageResultExecution timeMemory
947374TAhmed33Homework (CEOI22_homework)C++98
10 / 100
1104 ms234536 KiB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 25;
string s; deque <char> a7a;
int cnt;
vector <int> adj[MAXN];
int type[MAXN];
stack <int> cur;
vector <int> dd;
vector <int> ll2;
int dfs (int pos, int par = -1) {
	if (type[pos] == 3) {
		auto z = ll2.back(); ll2.pop_back();
		return z;
	}
	vector <int> p;
	for (auto j : adj[pos]) p.push_back(dfs(j, pos));
	if (type[pos] == 2) return *max_element(p.begin(), p.end());
	else return *min_element(p.begin(), p.end());
}
int main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> s; 
	for (auto i : s) a7a.push_back(i); int n = 0;
	while (!a7a.empty()) {
		if (a7a.front() == ',' || a7a.front() == '(') {
			a7a.pop_front(); continue;
		}
		if (a7a.front() == ')') {
			a7a.pop_front(); cur.pop(); continue;
		}
		if (a7a[0] == 'm' && a7a[1] == 'i' && a7a[2] == 'n') {
			++cnt; if (!cur.empty()) adj[cur.top()].push_back(cnt);
			cur.push(cnt); a7a.pop_front(); a7a.pop_front(); a7a.pop_front();
			type[cnt] = 1;
			continue;
		}
		if (a7a[0] == 'm' && a7a[1] == 'a' && a7a[2] == 'x') {
			++cnt; if (!cur.empty()) adj[cur.top()].push_back(cnt);
			cur.push(cnt); a7a.pop_front(); a7a.pop_front(); a7a.pop_front();
			type[cnt] = 2;
			continue;
		}
		if (a7a[0] == '?') {
			n++;
			++cnt; if (!cur.empty()) adj[cur.top()].push_back(cnt);
			type[cnt] = 3; a7a.pop_front(); continue;
		}
	}
	for (int i = 1; i <= n; i++) dd.push_back(i);
	set <int> ans;
	do {
		ll2 = dd;
		ans.insert(dfs(1));
	} while (next_permutation(dd.begin(), dd.end()));
	cout << (int)ans.size() << '\n';
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:24:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   24 |  for (auto i : s) a7a.push_back(i); int n = 0;
      |  ^~~
Main.cpp:24:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   24 |  for (auto i : s) a7a.push_back(i); int n = 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...