Submission #679470

# Submission time Handle Problem Language Result Execution time Memory
679470 2023-01-08T11:02:42 Z eli82 Homework (CEOI22_homework) C++14
53 / 100
97 ms 24696 KB
/* in the name of god */
/* be name khoda */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fs first
#define cs second
#define be_fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pii pair<ll, ll>
#define all_g(x) x.begin(), x.end(), greater<int>()
#define all(x) x.begin(), x.end()
const ll MAX_N = 1e4 + 24, mod1 = 998244353, mod2 = 1e9 + 7, lg = 21;
/// too gold . . .
/// is
string h;
vector<int>adj[MAX_N];
set<int>dp[MAX_N];
int mark[MAX_N];
vector<int>baga;
int cnt[MAX_N];

int dfs(int a){
    if(h[a] == '?'){
        baga.pb(a);
        cnt[a] = 1;
        return a;
    }
    h[a + 1] == 'i'? mark[a] = 1: mark[a] = 2;
    adj[a].pb(a + 4);
    int x = dfs(a + 4);
    adj[a].pb(x + 2);
    int xx = dfs(x + 2);
    cnt[a] = cnt[a + 4] + cnt[x + 2];
    return xx + 1;
} 

void solve(int a){
    if(h[a] == '?')
        return;
    for(int k :  adj[a]){
        solve(k);
    }
    int u = adj[a][0];
    int v = adj[a][1];
    if(mark[a] == 1){
        for(int i = 1; i <= cnt[a]; i++){
            auto x = (dp[u].upper_bound(i));
            if(x == dp[u].begin())
                continue;
            x--;
            int xx = *x;
            auto p = dp[v].end(); p--;
            int r = cnt[v] - *p + 1;
            r += cnt[u] - xx;
            if(r <= cnt[a] - i){
                dp[a].insert(i);
            }
        }
        for(int i = 1; i <= cnt[a]; i++){
            auto x = (dp[v].upper_bound(i));
            if(x == dp[v].begin())
                continue;
            x--;
            int xx = *x;
            auto p = dp[u].end(); p--;
            int r = cnt[u] - *p + 1;
            r += cnt[v] - xx;
            if(r <= cnt[a] - i){
                dp[a].insert(i);
            }
        }
    }

    else{
        for(int i = 1; i <= cnt[a]; i++){
            int x = *dp[v].begin();
            x = i - x;
            if(x < 0)continue;
            auto p = dp[u].upper_bound(x);
            if(p == dp[u].begin())
                continue;
            p--;
            if(cnt[a] - i >= cnt[u] - *p){
                dp[a].insert(i);
            }
        }
        for(int i = 1; i <= cnt[a]; i++){
            int x = *dp[u].begin();
            x = i - x;
            if(x < 0)continue;
            auto p = dp[v].upper_bound(x);
            if(p == dp[v].begin())
                continue;
            p--;
            if(cnt[a] - i >= cnt[v] - *p){
                dp[a].insert(i);
            }
        }
    }
    return;
}

int main(){
    be_fast 
    cin >> h;
    dfs(0);
    for(int i : baga){
        dp[i].insert(1);
    }
    solve(0);
    cout << dp[0].size() << endl; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1040 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1040 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1036 KB Output is correct
14 Correct 1 ms 1040 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1044 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1040 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1040 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1040 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1036 KB Output is correct
14 Correct 1 ms 1040 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1044 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1040 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 1040 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 1 ms 980 KB Output is correct
35 Correct 1 ms 980 KB Output is correct
36 Correct 1 ms 980 KB Output is correct
37 Correct 1 ms 980 KB Output is correct
38 Correct 1 ms 1036 KB Output is correct
39 Correct 1 ms 980 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 1 ms 980 KB Output is correct
42 Correct 1 ms 980 KB Output is correct
43 Correct 1 ms 980 KB Output is correct
44 Correct 1 ms 1036 KB Output is correct
45 Correct 1 ms 980 KB Output is correct
46 Correct 1 ms 1040 KB Output is correct
47 Correct 1 ms 1036 KB Output is correct
48 Correct 1 ms 980 KB Output is correct
49 Correct 1 ms 980 KB Output is correct
50 Correct 1 ms 980 KB Output is correct
51 Correct 1 ms 1040 KB Output is correct
52 Correct 1 ms 980 KB Output is correct
53 Correct 1 ms 980 KB Output is correct
54 Correct 1 ms 980 KB Output is correct
55 Correct 1 ms 1040 KB Output is correct
56 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 22212 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1040 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1040 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1036 KB Output is correct
14 Correct 1 ms 1040 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1044 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1040 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 1040 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 1 ms 980 KB Output is correct
35 Correct 1 ms 980 KB Output is correct
36 Correct 1 ms 980 KB Output is correct
37 Correct 1 ms 980 KB Output is correct
38 Correct 1 ms 1036 KB Output is correct
39 Correct 1 ms 980 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 1 ms 980 KB Output is correct
42 Correct 1 ms 980 KB Output is correct
43 Correct 1 ms 980 KB Output is correct
44 Correct 1 ms 1036 KB Output is correct
45 Correct 1 ms 980 KB Output is correct
46 Correct 1 ms 1040 KB Output is correct
47 Correct 1 ms 1036 KB Output is correct
48 Correct 1 ms 980 KB Output is correct
49 Correct 1 ms 980 KB Output is correct
50 Correct 1 ms 980 KB Output is correct
51 Correct 1 ms 1040 KB Output is correct
52 Correct 1 ms 980 KB Output is correct
53 Correct 1 ms 980 KB Output is correct
54 Correct 1 ms 980 KB Output is correct
55 Correct 1 ms 1040 KB Output is correct
56 Correct 2 ms 980 KB Output is correct
57 Correct 3 ms 1492 KB Output is correct
58 Correct 3 ms 1608 KB Output is correct
59 Correct 2 ms 1296 KB Output is correct
60 Correct 2 ms 1300 KB Output is correct
61 Correct 2 ms 1492 KB Output is correct
62 Correct 32 ms 8596 KB Output is correct
63 Correct 35 ms 9548 KB Output is correct
64 Correct 33 ms 8824 KB Output is correct
65 Correct 31 ms 8916 KB Output is correct
66 Correct 40 ms 9036 KB Output is correct
67 Correct 3 ms 1620 KB Output is correct
68 Correct 3 ms 1620 KB Output is correct
69 Correct 4 ms 1492 KB Output is correct
70 Correct 2 ms 1424 KB Output is correct
71 Correct 3 ms 1620 KB Output is correct
72 Correct 97 ms 24696 KB Output is correct
73 Correct 95 ms 24664 KB Output is correct
74 Correct 93 ms 24352 KB Output is correct
75 Correct 91 ms 24340 KB Output is correct
76 Correct 96 ms 24640 KB Output is correct
77 Correct 1 ms 1176 KB Output is correct
78 Correct 1 ms 1108 KB Output is correct
79 Correct 3 ms 1748 KB Output is correct
80 Correct 3 ms 1648 KB Output is correct
81 Correct 67 ms 18812 KB Output is correct
82 Correct 69 ms 18892 KB Output is correct
83 Correct 1 ms 1236 KB Output is correct
84 Correct 1 ms 1168 KB Output is correct
85 Correct 1 ms 1236 KB Output is correct
86 Correct 1 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1040 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1040 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1036 KB Output is correct
14 Correct 1 ms 1040 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 1044 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1040 KB Output is correct
23 Correct 1 ms 980 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 1040 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 1 ms 980 KB Output is correct
35 Correct 1 ms 980 KB Output is correct
36 Correct 1 ms 980 KB Output is correct
37 Correct 1 ms 980 KB Output is correct
38 Correct 1 ms 1036 KB Output is correct
39 Correct 1 ms 980 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 1 ms 980 KB Output is correct
42 Correct 1 ms 980 KB Output is correct
43 Correct 1 ms 980 KB Output is correct
44 Correct 1 ms 1036 KB Output is correct
45 Correct 1 ms 980 KB Output is correct
46 Correct 1 ms 1040 KB Output is correct
47 Correct 1 ms 1036 KB Output is correct
48 Correct 1 ms 980 KB Output is correct
49 Correct 1 ms 980 KB Output is correct
50 Correct 1 ms 980 KB Output is correct
51 Correct 1 ms 1040 KB Output is correct
52 Correct 1 ms 980 KB Output is correct
53 Correct 1 ms 980 KB Output is correct
54 Correct 1 ms 980 KB Output is correct
55 Correct 1 ms 1040 KB Output is correct
56 Correct 2 ms 980 KB Output is correct
57 Runtime error 24 ms 22212 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -