답안 #641357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641357 2022-09-16T14:21:49 Z andrei_boaca Homework (CEOI22_homework) C++14
100 / 100
284 ms 213796 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
stack<int> stiva;
vector<int> nr,poz;
string s;
bool possible(string op,int cnt1,int cnt2, pii p1, pii p2,int x)
{
    if(op=="max")
    {
        if(p1.first+p2.first<=x)
        {
            int val=cnt1+p2.second;
            if(x<=val)
                return 1;
            val=cnt2+p1.second;
            if(x<=val)
                return 1;
        }
        return 0;
    }
    else
    {
        int have=cnt1-p1.second+1;
        have+=cnt2-p2.second+1;
        if(cnt1+cnt2-x+1>=have)
            {
                int val=cnt1+cnt2-p2.first+1;
                if(cnt1+cnt2-val+1<=x)
                    return 1;
                val=cnt2+cnt1-p1.first+1;
                if(cnt1+cnt2-val+1<=x)
                    return 1;
            }
        return 0;
    }
}
pii solve(int l,int r)
{
    int initl=l,initr=r;
    if(r-l+1<3)
        return {1,1};
    string op;
    for(int i=l;i<l+3;i++)
        op.push_back(s[i]);
    l=l+3;
    pii p1,p2;
    int cnt1=0,cnt2=0;
    if(isalpha(s[l+1]))
    {
        int lft=l+1;
        int rgt=poz[l+4];
        p1=solve(lft,rgt);
        cnt1=nr[rgt];
        if(lft>0)
            cnt1-=nr[lft-1];
        l=rgt+2;
    }
    else
    {
        int lft=l+1;
        int rgt=l+1;
        p1=solve(lft,rgt);
        cnt1=nr[rgt];
        if(lft>0)
            cnt1-=nr[lft-1];
        l=rgt+2;
    }
    int lft=l;
    int rgt=r-1;
    p2=solve(lft,rgt);
    cnt2=nr[rgt];
    if(lft>0)
        cnt2-=nr[lft-1];
    int cnt=nr[initr];
    if(initl>0)
        cnt-=nr[initl-1];
    int st=1;
    int dr=cnt;
    int valmin=1e9,valmax=0;
    if(op=="max")
    {
        valmin=p1.first+p2.first;
        valmax=max(cnt1+p2.second,cnt2+p1.second);
    }
    if(op=="min")
    {
        int have=cnt1-p1.second+1;
        have+=cnt2-p2.second+1;
        valmax=cnt1+cnt2-have+1;
        int val=max(cnt1+cnt2-p2.first+1,cnt2+cnt1-p1.first+1);
        valmin=cnt1+cnt2-val+1;
    }
    return {valmin,valmax};
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int lg=s.size();
    nr.resize(lg+5);
    poz.resize(lg+5);
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='(')
        {
            stiva.push(i);
        }
        if(s[i]==')')
        {
            int p=stiva.top();
            poz[p]=i;
            stiva.pop();
        }
        if(i>0)
            nr[i]=nr[i-1];
        nr[i]+=(s[i]=='?');
    }
    pii x=solve(0,s.size()-1);
    //cout<<x.first<<' '<<x.second;
    cout<<x.second-x.first+1;
    return 0;
}

Compilation message

Main.cpp: In function 'pii solve(int, int)':
Main.cpp:79:9: warning: unused variable 'st' [-Wunused-variable]
   79 |     int st=1;
      |         ^~
Main.cpp:80:9: warning: unused variable 'dr' [-Wunused-variable]
   80 |     int dr=cnt;
      |         ^~
Main.cpp: In function 'int main()':
Main.cpp:105:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 236 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 260 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 236 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 260 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 252 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 284 ms 206900 KB Output is correct
2 Correct 243 ms 212300 KB Output is correct
3 Correct 281 ms 211916 KB Output is correct
4 Correct 224 ms 213540 KB Output is correct
5 Correct 257 ms 213288 KB Output is correct
6 Correct 244 ms 213524 KB Output is correct
7 Correct 260 ms 212844 KB Output is correct
8 Correct 233 ms 213060 KB Output is correct
9 Correct 278 ms 212216 KB Output is correct
10 Correct 232 ms 211736 KB Output is correct
11 Correct 212 ms 213796 KB Output is correct
12 Correct 206 ms 212200 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 236 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 260 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 252 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 0 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 0 ms 468 KB Output is correct
73 Correct 0 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 1 ms 384 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 388 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 236 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 260 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 252 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 284 ms 206900 KB Output is correct
58 Correct 243 ms 212300 KB Output is correct
59 Correct 281 ms 211916 KB Output is correct
60 Correct 224 ms 213540 KB Output is correct
61 Correct 257 ms 213288 KB Output is correct
62 Correct 244 ms 213524 KB Output is correct
63 Correct 260 ms 212844 KB Output is correct
64 Correct 233 ms 213060 KB Output is correct
65 Correct 278 ms 212216 KB Output is correct
66 Correct 232 ms 211736 KB Output is correct
67 Correct 212 ms 213796 KB Output is correct
68 Correct 206 ms 212200 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 0 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 0 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 0 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 0 ms 468 KB Output is correct
86 Correct 0 ms 468 KB Output is correct
87 Correct 1 ms 468 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 384 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 1 ms 388 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 181 ms 68700 KB Output is correct
101 Correct 169 ms 67836 KB Output is correct
102 Correct 142 ms 67796 KB Output is correct
103 Correct 135 ms 67932 KB Output is correct
104 Correct 147 ms 66956 KB Output is correct
105 Correct 204 ms 115636 KB Output is correct
106 Correct 226 ms 115192 KB Output is correct
107 Correct 171 ms 115524 KB Output is correct
108 Correct 156 ms 116220 KB Output is correct
109 Correct 204 ms 116612 KB Output is correct
110 Correct 148 ms 68844 KB Output is correct
111 Correct 150 ms 67888 KB Output is correct
112 Correct 183 ms 68280 KB Output is correct
113 Correct 183 ms 67656 KB Output is correct
114 Correct 149 ms 68204 KB Output is correct
115 Correct 264 ms 213476 KB Output is correct
116 Correct 246 ms 212588 KB Output is correct
117 Correct 218 ms 213308 KB Output is correct
118 Correct 237 ms 212472 KB Output is correct
119 Correct 239 ms 212384 KB Output is correct
120 Correct 167 ms 68404 KB Output is correct
121 Correct 135 ms 68488 KB Output is correct
122 Correct 171 ms 68300 KB Output is correct
123 Correct 145 ms 68452 KB Output is correct
124 Correct 212 ms 141148 KB Output is correct
125 Correct 178 ms 140896 KB Output is correct
126 Correct 174 ms 140408 KB Output is correct
127 Correct 179 ms 141244 KB Output is correct
128 Correct 95 ms 36192 KB Output is correct
129 Correct 104 ms 35860 KB Output is correct
130 Correct 96 ms 36116 KB Output is correct
131 Correct 1 ms 320 KB Output is correct