Submission #995018

# Submission time Handle Problem Language Result Execution time Memory
995018 2024-06-08T10:40:45 Z Huseyn123 Homework (CEOI22_homework) C++17
100 / 100
381 ms 323392 KB
#include <bits/stdc++.h>
//#define int ll
#define MAX 2000005
#define INF INT_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second 
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define outputar(a,b){\
    for(int i=0;i<b;i++){\
        cout << a[i] << " ";\
    }\
    cout << endl;\
}
#define outputvec(a){\
    for(auto x:a){\
        cout << (int)x << " ";\
    }\
    cout << endl;\
}
#define reset(a,n,v){\
    for(int i=0;i<n;i++){\
        a[i]=v;\
    }\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
int n,q,t=1,m,k,x,y,z,x2,y2,z2,a[MAX],b[MAX],mgl[MAX],mg[MAX],ml[MAX];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//string s[MAX],str[MAX];
//int e[1001][1001];
string s1,s2,s3;
const int mod = 998244353;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int cnt,cnt1;
vector<vector<int>> g,g1;
pii dfs(int x){
    cnt++;
    int num=cnt;
    g.pb({});
    g1.pb({});
    //cout << cnt << " " << x << "\n";
    if(s1[x]=='?'){
        cnt1++;
        return {x,cnt};
    }
    if(s1[x+1]=='i'){
        a[cnt]=1;
    }
    else{
        a[cnt]=2;
    }
    x+=4;
    pii p=dfs(x);
    x=p.ff;
    g[p.ss].pb(num);
    g1[num].pb(p.ss);
    b[num]++;
    x++;
    while(s1[x]!='?' && s1[x]!='m'){
        x++;
    }
    p=dfs(x);
    x=p.ff;
    g[p.ss].pb(num);
    g1[num].pb(p.ss);
    b[num]++;
    return {x,num};
}
void solve(){
    cin >> s1;
    g.clear();
    g1.clear();
    n=(int)s1.size();
    cnt=-1;
    cnt1=0;
    dfs(0);
    queue<int> q;
    for(int i=0;i<=cnt;i++){
        if(b[i]==0){
            q.push(i);
        }
    }
    while(!q.empty()){
        int v=q.front();
        q.pop();
        int l,r;
        if(a[v]!=0){
            l=g1[v][0];
            r=g1[v][1];
        }
        if(a[v]==1){
            mgl[v]=min(mgl[l]+mg[r]+1,mgl[r]+mg[l]+1);
            mg[v]=mg[l]+mg[r]+1;
            ml[v]=min(ml[l],ml[r]);
        }
        else if(a[v]==2){
            mgl[v]=min(mgl[l]+ml[r]+1,mgl[r]+ml[l]+1);
            ml[v]=ml[l]+ml[r]+1;
            mg[v]=min(mg[l],mg[r]);
        }
        for(auto x:g[v]){
            b[x]--;
            if(b[x]==0){
                q.push(x);
            }
        }
        //cout << v << " " << mgl[v] << " " << mg[v] << " " << ml[v] << "\n";
    }
    cout << max(cnt1-mgl[0],0) << "\n";
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input13.txt","r",stdin);
    //cin >> t;
    ll cnt1=1;
    while(t--){
        solve();
        cnt1++; 
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6744 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6744 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6556 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6504 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 6496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 296 ms 312736 KB Output is correct
2 Correct 309 ms 321180 KB Output is correct
3 Correct 303 ms 319184 KB Output is correct
4 Correct 381 ms 322024 KB Output is correct
5 Correct 332 ms 323112 KB Output is correct
6 Correct 297 ms 321696 KB Output is correct
7 Correct 294 ms 320820 KB Output is correct
8 Correct 299 ms 319200 KB Output is correct
9 Correct 300 ms 319416 KB Output is correct
10 Correct 294 ms 319668 KB Output is correct
11 Correct 277 ms 321188 KB Output is correct
12 Correct 290 ms 319628 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6744 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6556 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6504 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 6496 KB Output is correct
57 Correct 1 ms 6744 KB Output is correct
58 Correct 1 ms 6748 KB Output is correct
59 Correct 1 ms 6748 KB Output is correct
60 Correct 1 ms 6748 KB Output is correct
61 Correct 1 ms 6748 KB Output is correct
62 Correct 1 ms 6748 KB Output is correct
63 Correct 1 ms 6748 KB Output is correct
64 Correct 1 ms 6748 KB Output is correct
65 Correct 1 ms 6748 KB Output is correct
66 Correct 1 ms 6748 KB Output is correct
67 Correct 1 ms 6748 KB Output is correct
68 Correct 1 ms 6748 KB Output is correct
69 Correct 1 ms 6748 KB Output is correct
70 Correct 1 ms 6748 KB Output is correct
71 Correct 1 ms 6748 KB Output is correct
72 Correct 1 ms 6748 KB Output is correct
73 Correct 1 ms 6748 KB Output is correct
74 Correct 1 ms 6748 KB Output is correct
75 Correct 1 ms 6748 KB Output is correct
76 Correct 1 ms 6748 KB Output is correct
77 Correct 1 ms 6748 KB Output is correct
78 Correct 1 ms 6748 KB Output is correct
79 Correct 1 ms 6748 KB Output is correct
80 Correct 1 ms 6748 KB Output is correct
81 Correct 1 ms 6748 KB Output is correct
82 Correct 1 ms 6748 KB Output is correct
83 Correct 1 ms 6600 KB Output is correct
84 Correct 2 ms 6492 KB Output is correct
85 Correct 1 ms 6492 KB Output is correct
86 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6744 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6556 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6492 KB Output is correct
46 Correct 1 ms 6492 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 1 ms 6492 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 1 ms 6492 KB Output is correct
51 Correct 1 ms 6504 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 6492 KB Output is correct
54 Correct 1 ms 6492 KB Output is correct
55 Correct 1 ms 6492 KB Output is correct
56 Correct 1 ms 6496 KB Output is correct
57 Correct 296 ms 312736 KB Output is correct
58 Correct 309 ms 321180 KB Output is correct
59 Correct 303 ms 319184 KB Output is correct
60 Correct 381 ms 322024 KB Output is correct
61 Correct 332 ms 323112 KB Output is correct
62 Correct 297 ms 321696 KB Output is correct
63 Correct 294 ms 320820 KB Output is correct
64 Correct 299 ms 319200 KB Output is correct
65 Correct 300 ms 319416 KB Output is correct
66 Correct 294 ms 319668 KB Output is correct
67 Correct 277 ms 321188 KB Output is correct
68 Correct 290 ms 319628 KB Output is correct
69 Correct 1 ms 6488 KB Output is correct
70 Correct 1 ms 6744 KB Output is correct
71 Correct 1 ms 6748 KB Output is correct
72 Correct 1 ms 6748 KB Output is correct
73 Correct 1 ms 6748 KB Output is correct
74 Correct 1 ms 6748 KB Output is correct
75 Correct 1 ms 6748 KB Output is correct
76 Correct 1 ms 6748 KB Output is correct
77 Correct 1 ms 6748 KB Output is correct
78 Correct 1 ms 6748 KB Output is correct
79 Correct 1 ms 6748 KB Output is correct
80 Correct 1 ms 6748 KB Output is correct
81 Correct 1 ms 6748 KB Output is correct
82 Correct 1 ms 6748 KB Output is correct
83 Correct 1 ms 6748 KB Output is correct
84 Correct 1 ms 6748 KB Output is correct
85 Correct 1 ms 6748 KB Output is correct
86 Correct 1 ms 6748 KB Output is correct
87 Correct 1 ms 6748 KB Output is correct
88 Correct 1 ms 6748 KB Output is correct
89 Correct 1 ms 6748 KB Output is correct
90 Correct 1 ms 6748 KB Output is correct
91 Correct 1 ms 6748 KB Output is correct
92 Correct 1 ms 6748 KB Output is correct
93 Correct 1 ms 6748 KB Output is correct
94 Correct 1 ms 6748 KB Output is correct
95 Correct 1 ms 6748 KB Output is correct
96 Correct 1 ms 6600 KB Output is correct
97 Correct 2 ms 6492 KB Output is correct
98 Correct 1 ms 6492 KB Output is correct
99 Correct 1 ms 6492 KB Output is correct
100 Correct 343 ms 246936 KB Output is correct
101 Correct 346 ms 246172 KB Output is correct
102 Correct 340 ms 247960 KB Output is correct
103 Correct 323 ms 247052 KB Output is correct
104 Correct 337 ms 247960 KB Output is correct
105 Correct 351 ms 272216 KB Output is correct
106 Correct 360 ms 275868 KB Output is correct
107 Correct 353 ms 273064 KB Output is correct
108 Correct 363 ms 272224 KB Output is correct
109 Correct 347 ms 275916 KB Output is correct
110 Correct 353 ms 247508 KB Output is correct
111 Correct 361 ms 246424 KB Output is correct
112 Correct 356 ms 246944 KB Output is correct
113 Correct 364 ms 245656 KB Output is correct
114 Correct 351 ms 247284 KB Output is correct
115 Correct 301 ms 321416 KB Output is correct
116 Correct 305 ms 322268 KB Output is correct
117 Correct 301 ms 323392 KB Output is correct
118 Correct 292 ms 323228 KB Output is correct
119 Correct 284 ms 318880 KB Output is correct
120 Correct 347 ms 248036 KB Output is correct
121 Correct 343 ms 248472 KB Output is correct
122 Correct 353 ms 246848 KB Output is correct
123 Correct 360 ms 247452 KB Output is correct
124 Correct 300 ms 289300 KB Output is correct
125 Correct 297 ms 287828 KB Output is correct
126 Correct 305 ms 285724 KB Output is correct
127 Correct 298 ms 285688 KB Output is correct
128 Correct 152 ms 134988 KB Output is correct
129 Correct 159 ms 134904 KB Output is correct
130 Correct 183 ms 135080 KB Output is correct
131 Correct 1 ms 6488 KB Output is correct