Submission #1088040

# Submission time Handle Problem Language Result Execution time Memory
1088040 2024-09-13T18:25:21 Z _8_8_ Homework (CEOI22_homework) C++17
10 / 100
1000 ms 134984 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int  N = 2e6 + 12, MOD = 998244353;

string s;
int m, n, col, val[N];
vector<int> st, g[N];
bool ok[N];
int dfs(int v) {
    if(v <= col) return val[v];
    if(ok[v]) {
        return max(dfs(g[v][0]), dfs(g[v][1]));
    } 
    return min(dfs(g[v][0]), dfs(g[v][1]));
}
void test() {
    cin >> s;
    m = (int)s.size();
    for(int i = 0; i < m; i++) {
        if(s[i] == '?') {
            col++;
        }
    }
    n = col;
    for(int i = 0; i < m; i++) {
        if(s[i] == '(') {
            if(!st.empty()) {
                g[st.back()].push_back(n + 1);
            }
            st.push_back(++n);
            if(s[i - 1] == 'x') {
                ok[n] = 1;
            } 
        } else if(s[i] == ')') {
            st.pop_back();
        }
    }
    int it = 0;
    for(int i = col + 1; i <= n; i++) {
        int f = (int)g[i].size();
        for(int j = 0; j < 2 - f; j++) {
            g[i].push_back(++it);
        }
    }
    vector<int> p(col);
    iota(p.begin(), p.end(), 1);
    set<int> s;
    do{
        for(int i = 0; i < col; i++) {
            val[i + 1] = p[i];
        }
        s.insert(dfs(col + 1));
    }while(next_permutation(p.begin(), p.end()));
    cout << (int)s.size() << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); 

    int t = 1; 
    // cin >> t;

    while(t--) 
        test();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47196 KB Output is correct
2 Correct 30 ms 47196 KB Output is correct
3 Correct 30 ms 47192 KB Output is correct
4 Correct 31 ms 47416 KB Output is correct
5 Correct 32 ms 47192 KB Output is correct
6 Correct 31 ms 47196 KB Output is correct
7 Correct 32 ms 47192 KB Output is correct
8 Correct 34 ms 47428 KB Output is correct
9 Correct 29 ms 47196 KB Output is correct
10 Correct 32 ms 47196 KB Output is correct
11 Correct 31 ms 47240 KB Output is correct
12 Correct 38 ms 47196 KB Output is correct
13 Correct 30 ms 47264 KB Output is correct
14 Correct 31 ms 47440 KB Output is correct
15 Correct 50 ms 47192 KB Output is correct
16 Correct 34 ms 47420 KB Output is correct
17 Correct 40 ms 47416 KB Output is correct
18 Correct 33 ms 47192 KB Output is correct
19 Correct 32 ms 47196 KB Output is correct
20 Correct 33 ms 47196 KB Output is correct
21 Correct 31 ms 47196 KB Output is correct
22 Correct 29 ms 47196 KB Output is correct
23 Correct 33 ms 47196 KB Output is correct
24 Correct 32 ms 47192 KB Output is correct
25 Correct 21 ms 47196 KB Output is correct
26 Correct 19 ms 47452 KB Output is correct
27 Correct 20 ms 47304 KB Output is correct
28 Correct 18 ms 47196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47196 KB Output is correct
2 Correct 30 ms 47196 KB Output is correct
3 Correct 30 ms 47192 KB Output is correct
4 Correct 31 ms 47416 KB Output is correct
5 Correct 32 ms 47192 KB Output is correct
6 Correct 31 ms 47196 KB Output is correct
7 Correct 32 ms 47192 KB Output is correct
8 Correct 34 ms 47428 KB Output is correct
9 Correct 29 ms 47196 KB Output is correct
10 Correct 32 ms 47196 KB Output is correct
11 Correct 31 ms 47240 KB Output is correct
12 Correct 38 ms 47196 KB Output is correct
13 Correct 30 ms 47264 KB Output is correct
14 Correct 31 ms 47440 KB Output is correct
15 Correct 50 ms 47192 KB Output is correct
16 Correct 34 ms 47420 KB Output is correct
17 Correct 40 ms 47416 KB Output is correct
18 Correct 33 ms 47192 KB Output is correct
19 Correct 32 ms 47196 KB Output is correct
20 Correct 33 ms 47196 KB Output is correct
21 Correct 31 ms 47196 KB Output is correct
22 Correct 29 ms 47196 KB Output is correct
23 Correct 33 ms 47196 KB Output is correct
24 Correct 32 ms 47192 KB Output is correct
25 Correct 21 ms 47196 KB Output is correct
26 Correct 19 ms 47452 KB Output is correct
27 Correct 20 ms 47304 KB Output is correct
28 Correct 18 ms 47196 KB Output is correct
29 Execution timed out 1074 ms 47196 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 134984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47196 KB Output is correct
2 Correct 30 ms 47196 KB Output is correct
3 Correct 30 ms 47192 KB Output is correct
4 Correct 31 ms 47416 KB Output is correct
5 Correct 32 ms 47192 KB Output is correct
6 Correct 31 ms 47196 KB Output is correct
7 Correct 32 ms 47192 KB Output is correct
8 Correct 34 ms 47428 KB Output is correct
9 Correct 29 ms 47196 KB Output is correct
10 Correct 32 ms 47196 KB Output is correct
11 Correct 31 ms 47240 KB Output is correct
12 Correct 38 ms 47196 KB Output is correct
13 Correct 30 ms 47264 KB Output is correct
14 Correct 31 ms 47440 KB Output is correct
15 Correct 50 ms 47192 KB Output is correct
16 Correct 34 ms 47420 KB Output is correct
17 Correct 40 ms 47416 KB Output is correct
18 Correct 33 ms 47192 KB Output is correct
19 Correct 32 ms 47196 KB Output is correct
20 Correct 33 ms 47196 KB Output is correct
21 Correct 31 ms 47196 KB Output is correct
22 Correct 29 ms 47196 KB Output is correct
23 Correct 33 ms 47196 KB Output is correct
24 Correct 32 ms 47192 KB Output is correct
25 Correct 21 ms 47196 KB Output is correct
26 Correct 19 ms 47452 KB Output is correct
27 Correct 20 ms 47304 KB Output is correct
28 Correct 18 ms 47196 KB Output is correct
29 Execution timed out 1074 ms 47196 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47196 KB Output is correct
2 Correct 30 ms 47196 KB Output is correct
3 Correct 30 ms 47192 KB Output is correct
4 Correct 31 ms 47416 KB Output is correct
5 Correct 32 ms 47192 KB Output is correct
6 Correct 31 ms 47196 KB Output is correct
7 Correct 32 ms 47192 KB Output is correct
8 Correct 34 ms 47428 KB Output is correct
9 Correct 29 ms 47196 KB Output is correct
10 Correct 32 ms 47196 KB Output is correct
11 Correct 31 ms 47240 KB Output is correct
12 Correct 38 ms 47196 KB Output is correct
13 Correct 30 ms 47264 KB Output is correct
14 Correct 31 ms 47440 KB Output is correct
15 Correct 50 ms 47192 KB Output is correct
16 Correct 34 ms 47420 KB Output is correct
17 Correct 40 ms 47416 KB Output is correct
18 Correct 33 ms 47192 KB Output is correct
19 Correct 32 ms 47196 KB Output is correct
20 Correct 33 ms 47196 KB Output is correct
21 Correct 31 ms 47196 KB Output is correct
22 Correct 29 ms 47196 KB Output is correct
23 Correct 33 ms 47196 KB Output is correct
24 Correct 32 ms 47192 KB Output is correct
25 Correct 21 ms 47196 KB Output is correct
26 Correct 19 ms 47452 KB Output is correct
27 Correct 20 ms 47304 KB Output is correct
28 Correct 18 ms 47196 KB Output is correct
29 Execution timed out 1074 ms 47196 KB Time limit exceeded
30 Halted 0 ms 0 KB -