답안 #1014501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014501 2024-07-05T04:48:30 Z vjudge1 Homework (CEOI22_homework) C++17
100 / 100
208 ms 194192 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,l,r) for(int i=l; i<r; i++)
#define all(x) x.begin(),x.end()
#define len(x) (int)x.size();
#define fi first
#define se second
#define elif else if
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
constexpr ll LINF=1001001001001001001LL;
constexpr ll MINF=1001001001001LL;
constexpr int INF=1001001001;

constexpr int MAX_N=1001001;
string S;
int sz;
vector<vector<int>> comma(MAX_N);
array<int,3> calc(int lf,int ri,int lv){
    if(ri-lf==1)return {0,1,1};
    int cp=*lower_bound(all(comma[lv]),lf);
    array<int,3> left=calc(lf+4,cp,lv+1);
    array<int,3> right=calc(cp+1,ri-1,lv+1);
    array<int,3> ret={0,0,left[2]+right[2]};
    if(S[lf+1]=='i'){
        tie(left[0],left[1])=pii{left[2]-left[1],left[2]-left[0]};
        tie(right[0],right[1])=pii{right[2]-right[1],right[2]-right[0]};
    }
    //TODO:make_max
    ret[0]=left[0]+right[0]+1;
    ret[1]=max(left[2]+right[1],right[2]+left[1]);
    if(S[lf+1]=='i'){
        tie(ret[0],ret[1])=pii{ret[2]-ret[1],ret[2]-ret[0]};
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>S;
    sz=len(S);
    int level=0;
    rep(i,sz){
        if(S[i]=='(')level++;
        elif(S[i]==')')level--;
        elif(S[i]==',')comma[level-1].emplace_back(i);
    }
    array<int,3> ans=calc(0,sz,0);
    cout<<ans[1]-ans[0]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23896 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23776 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 24152 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 11 ms 23720 KB Output is correct
13 Correct 11 ms 23896 KB Output is correct
14 Correct 10 ms 23896 KB Output is correct
15 Correct 10 ms 23896 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 12 ms 23912 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 13 ms 23924 KB Output is correct
24 Correct 10 ms 23896 KB Output is correct
25 Correct 14 ms 23888 KB Output is correct
26 Correct 10 ms 23900 KB Output is correct
27 Correct 15 ms 23880 KB Output is correct
28 Correct 10 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23896 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23776 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 24152 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 11 ms 23720 KB Output is correct
13 Correct 11 ms 23896 KB Output is correct
14 Correct 10 ms 23896 KB Output is correct
15 Correct 10 ms 23896 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 12 ms 23912 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 13 ms 23924 KB Output is correct
24 Correct 10 ms 23896 KB Output is correct
25 Correct 14 ms 23888 KB Output is correct
26 Correct 10 ms 23900 KB Output is correct
27 Correct 15 ms 23880 KB Output is correct
28 Correct 10 ms 23900 KB Output is correct
29 Correct 10 ms 23900 KB Output is correct
30 Correct 9 ms 23900 KB Output is correct
31 Correct 9 ms 23900 KB Output is correct
32 Correct 10 ms 23900 KB Output is correct
33 Correct 10 ms 23900 KB Output is correct
34 Correct 10 ms 24064 KB Output is correct
35 Correct 11 ms 23900 KB Output is correct
36 Correct 10 ms 23900 KB Output is correct
37 Correct 10 ms 23800 KB Output is correct
38 Correct 10 ms 23824 KB Output is correct
39 Correct 10 ms 23896 KB Output is correct
40 Correct 10 ms 23896 KB Output is correct
41 Correct 11 ms 23900 KB Output is correct
42 Correct 11 ms 23760 KB Output is correct
43 Correct 9 ms 23900 KB Output is correct
44 Correct 10 ms 23896 KB Output is correct
45 Correct 10 ms 23900 KB Output is correct
46 Correct 10 ms 23896 KB Output is correct
47 Correct 12 ms 23900 KB Output is correct
48 Correct 11 ms 23900 KB Output is correct
49 Correct 10 ms 23800 KB Output is correct
50 Correct 11 ms 23896 KB Output is correct
51 Correct 11 ms 23900 KB Output is correct
52 Correct 10 ms 23900 KB Output is correct
53 Correct 14 ms 23900 KB Output is correct
54 Correct 11 ms 23796 KB Output is correct
55 Correct 10 ms 23900 KB Output is correct
56 Correct 11 ms 23720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 193992 KB Output is correct
2 Correct 208 ms 194192 KB Output is correct
3 Correct 189 ms 193996 KB Output is correct
4 Correct 163 ms 194064 KB Output is correct
5 Correct 206 ms 194140 KB Output is correct
6 Correct 187 ms 194052 KB Output is correct
7 Correct 185 ms 194192 KB Output is correct
8 Correct 180 ms 194088 KB Output is correct
9 Correct 193 ms 194124 KB Output is correct
10 Correct 180 ms 194024 KB Output is correct
11 Correct 183 ms 194060 KB Output is correct
12 Correct 189 ms 194092 KB Output is correct
13 Correct 11 ms 23972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23896 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23776 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 24152 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 11 ms 23720 KB Output is correct
13 Correct 11 ms 23896 KB Output is correct
14 Correct 10 ms 23896 KB Output is correct
15 Correct 10 ms 23896 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 12 ms 23912 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 13 ms 23924 KB Output is correct
24 Correct 10 ms 23896 KB Output is correct
25 Correct 14 ms 23888 KB Output is correct
26 Correct 10 ms 23900 KB Output is correct
27 Correct 15 ms 23880 KB Output is correct
28 Correct 10 ms 23900 KB Output is correct
29 Correct 10 ms 23900 KB Output is correct
30 Correct 9 ms 23900 KB Output is correct
31 Correct 9 ms 23900 KB Output is correct
32 Correct 10 ms 23900 KB Output is correct
33 Correct 10 ms 23900 KB Output is correct
34 Correct 10 ms 24064 KB Output is correct
35 Correct 11 ms 23900 KB Output is correct
36 Correct 10 ms 23900 KB Output is correct
37 Correct 10 ms 23800 KB Output is correct
38 Correct 10 ms 23824 KB Output is correct
39 Correct 10 ms 23896 KB Output is correct
40 Correct 10 ms 23896 KB Output is correct
41 Correct 11 ms 23900 KB Output is correct
42 Correct 11 ms 23760 KB Output is correct
43 Correct 9 ms 23900 KB Output is correct
44 Correct 10 ms 23896 KB Output is correct
45 Correct 10 ms 23900 KB Output is correct
46 Correct 10 ms 23896 KB Output is correct
47 Correct 12 ms 23900 KB Output is correct
48 Correct 11 ms 23900 KB Output is correct
49 Correct 10 ms 23800 KB Output is correct
50 Correct 11 ms 23896 KB Output is correct
51 Correct 11 ms 23900 KB Output is correct
52 Correct 10 ms 23900 KB Output is correct
53 Correct 14 ms 23900 KB Output is correct
54 Correct 11 ms 23796 KB Output is correct
55 Correct 10 ms 23900 KB Output is correct
56 Correct 11 ms 23720 KB Output is correct
57 Correct 13 ms 23900 KB Output is correct
58 Correct 10 ms 23896 KB Output is correct
59 Correct 10 ms 23812 KB Output is correct
60 Correct 10 ms 23900 KB Output is correct
61 Correct 14 ms 23900 KB Output is correct
62 Correct 10 ms 23884 KB Output is correct
63 Correct 15 ms 23852 KB Output is correct
64 Correct 11 ms 23900 KB Output is correct
65 Correct 10 ms 23900 KB Output is correct
66 Correct 12 ms 23924 KB Output is correct
67 Correct 10 ms 23900 KB Output is correct
68 Correct 10 ms 23900 KB Output is correct
69 Correct 15 ms 23980 KB Output is correct
70 Correct 11 ms 23896 KB Output is correct
71 Correct 10 ms 23900 KB Output is correct
72 Correct 10 ms 23900 KB Output is correct
73 Correct 10 ms 23900 KB Output is correct
74 Correct 14 ms 23984 KB Output is correct
75 Correct 10 ms 23896 KB Output is correct
76 Correct 11 ms 23900 KB Output is correct
77 Correct 10 ms 23900 KB Output is correct
78 Correct 13 ms 23900 KB Output is correct
79 Correct 10 ms 23976 KB Output is correct
80 Correct 14 ms 23896 KB Output is correct
81 Correct 10 ms 23864 KB Output is correct
82 Correct 9 ms 23900 KB Output is correct
83 Correct 10 ms 23816 KB Output is correct
84 Correct 11 ms 23904 KB Output is correct
85 Correct 10 ms 23900 KB Output is correct
86 Correct 10 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23896 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 11 ms 23900 KB Output is correct
6 Correct 10 ms 23776 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 11 ms 24152 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23896 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 11 ms 23720 KB Output is correct
13 Correct 11 ms 23896 KB Output is correct
14 Correct 10 ms 23896 KB Output is correct
15 Correct 10 ms 23896 KB Output is correct
16 Correct 11 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 12 ms 23912 KB Output is correct
19 Correct 11 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 10 ms 23896 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 13 ms 23924 KB Output is correct
24 Correct 10 ms 23896 KB Output is correct
25 Correct 14 ms 23888 KB Output is correct
26 Correct 10 ms 23900 KB Output is correct
27 Correct 15 ms 23880 KB Output is correct
28 Correct 10 ms 23900 KB Output is correct
29 Correct 10 ms 23900 KB Output is correct
30 Correct 9 ms 23900 KB Output is correct
31 Correct 9 ms 23900 KB Output is correct
32 Correct 10 ms 23900 KB Output is correct
33 Correct 10 ms 23900 KB Output is correct
34 Correct 10 ms 24064 KB Output is correct
35 Correct 11 ms 23900 KB Output is correct
36 Correct 10 ms 23900 KB Output is correct
37 Correct 10 ms 23800 KB Output is correct
38 Correct 10 ms 23824 KB Output is correct
39 Correct 10 ms 23896 KB Output is correct
40 Correct 10 ms 23896 KB Output is correct
41 Correct 11 ms 23900 KB Output is correct
42 Correct 11 ms 23760 KB Output is correct
43 Correct 9 ms 23900 KB Output is correct
44 Correct 10 ms 23896 KB Output is correct
45 Correct 10 ms 23900 KB Output is correct
46 Correct 10 ms 23896 KB Output is correct
47 Correct 12 ms 23900 KB Output is correct
48 Correct 11 ms 23900 KB Output is correct
49 Correct 10 ms 23800 KB Output is correct
50 Correct 11 ms 23896 KB Output is correct
51 Correct 11 ms 23900 KB Output is correct
52 Correct 10 ms 23900 KB Output is correct
53 Correct 14 ms 23900 KB Output is correct
54 Correct 11 ms 23796 KB Output is correct
55 Correct 10 ms 23900 KB Output is correct
56 Correct 11 ms 23720 KB Output is correct
57 Correct 167 ms 193992 KB Output is correct
58 Correct 208 ms 194192 KB Output is correct
59 Correct 189 ms 193996 KB Output is correct
60 Correct 163 ms 194064 KB Output is correct
61 Correct 206 ms 194140 KB Output is correct
62 Correct 187 ms 194052 KB Output is correct
63 Correct 185 ms 194192 KB Output is correct
64 Correct 180 ms 194088 KB Output is correct
65 Correct 193 ms 194124 KB Output is correct
66 Correct 180 ms 194024 KB Output is correct
67 Correct 183 ms 194060 KB Output is correct
68 Correct 189 ms 194092 KB Output is correct
69 Correct 11 ms 23972 KB Output is correct
70 Correct 13 ms 23900 KB Output is correct
71 Correct 10 ms 23896 KB Output is correct
72 Correct 10 ms 23812 KB Output is correct
73 Correct 10 ms 23900 KB Output is correct
74 Correct 14 ms 23900 KB Output is correct
75 Correct 10 ms 23884 KB Output is correct
76 Correct 15 ms 23852 KB Output is correct
77 Correct 11 ms 23900 KB Output is correct
78 Correct 10 ms 23900 KB Output is correct
79 Correct 12 ms 23924 KB Output is correct
80 Correct 10 ms 23900 KB Output is correct
81 Correct 10 ms 23900 KB Output is correct
82 Correct 15 ms 23980 KB Output is correct
83 Correct 11 ms 23896 KB Output is correct
84 Correct 10 ms 23900 KB Output is correct
85 Correct 10 ms 23900 KB Output is correct
86 Correct 10 ms 23900 KB Output is correct
87 Correct 14 ms 23984 KB Output is correct
88 Correct 10 ms 23896 KB Output is correct
89 Correct 11 ms 23900 KB Output is correct
90 Correct 10 ms 23900 KB Output is correct
91 Correct 13 ms 23900 KB Output is correct
92 Correct 10 ms 23976 KB Output is correct
93 Correct 14 ms 23896 KB Output is correct
94 Correct 10 ms 23864 KB Output is correct
95 Correct 9 ms 23900 KB Output is correct
96 Correct 10 ms 23816 KB Output is correct
97 Correct 11 ms 23904 KB Output is correct
98 Correct 10 ms 23900 KB Output is correct
99 Correct 10 ms 23900 KB Output is correct
100 Correct 122 ms 43472 KB Output is correct
101 Correct 108 ms 43324 KB Output is correct
102 Correct 92 ms 43532 KB Output is correct
103 Correct 96 ms 43248 KB Output is correct
104 Correct 93 ms 43212 KB Output is correct
105 Correct 122 ms 90140 KB Output is correct
106 Correct 111 ms 90108 KB Output is correct
107 Correct 109 ms 90112 KB Output is correct
108 Correct 102 ms 90112 KB Output is correct
109 Correct 100 ms 90064 KB Output is correct
110 Correct 108 ms 43296 KB Output is correct
111 Correct 107 ms 43368 KB Output is correct
112 Correct 101 ms 43480 KB Output is correct
113 Correct 106 ms 43260 KB Output is correct
114 Correct 107 ms 43476 KB Output is correct
115 Correct 162 ms 194004 KB Output is correct
116 Correct 157 ms 193996 KB Output is correct
117 Correct 166 ms 194024 KB Output is correct
118 Correct 165 ms 193992 KB Output is correct
119 Correct 204 ms 194032 KB Output is correct
120 Correct 105 ms 43468 KB Output is correct
121 Correct 122 ms 43036 KB Output is correct
122 Correct 140 ms 43528 KB Output is correct
123 Correct 115 ms 43496 KB Output is correct
124 Correct 134 ms 118880 KB Output is correct
125 Correct 131 ms 118736 KB Output is correct
126 Correct 129 ms 118732 KB Output is correct
127 Correct 129 ms 118988 KB Output is correct
128 Correct 50 ms 32964 KB Output is correct
129 Correct 49 ms 33036 KB Output is correct
130 Correct 47 ms 32988 KB Output is correct
131 Correct 11 ms 23900 KB Output is correct