답안 #724423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724423 2023-04-15T08:29:16 Z cig32 Homework (CEOI22_homework) C++17
100 / 100
391 ms 210852 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e6 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
string s;
vector<int> adj[MAXN];
char tag[MAXN];
int n;
int ma[MAXN], mi[MAXN];
int sz[MAXN];
void dfs(int node) {
  sz[node] = (node < n);
  for(int x: adj[node]) {
    dfs(x);
    sz[node] += sz[x];
  }
}
void dpf(int node) {
  if(adj[node].empty()) {
    ma[node] = mi[node] = 1;
    return;
  }
  for(int x: adj[node]) dpf(x);
  if(tag[node] == 'a') {
    for(int x: adj[node]) ma[node] = max(ma[node], sz[node] - (sz[x] - ma[x]));
    for(int x: adj[node]) mi[node] += mi[x];
  }
  else {
    for(int x: adj[node]) ma[node] += ma[x] - 1;
    ma[node] += 1;
    mi[node] = 1e9;
    for(int x: adj[node]) mi[node] = min(mi[node], mi[x]);
  }
}
void solve(int tc) {
  cin >> s;
  n = 0;
  for(char c: s) n += (c == '?');
  vector<int> t;
  int o = 0;
  for(char c: s) {
    if(c == '?') t.push_back(o++);
    else if(c == '(') t.push_back(-1);
    else if(c == ')') t.push_back(-2);
    else if(c == ',') t.push_back(-3);
    else if(c == 'm') t.push_back(-4);
    else if(c == 'a') t.push_back(-5);
    else if(c == 'x') t.push_back(-6);
    else if(c == 'i') t.push_back(-7);
    else t.push_back(-8);
  }
  vector<int> wow;
  for(int i=0; i<t.size(); i++) {
    if(t[i] != -2) wow.push_back(t[i]);
    else {
      //max(?,?)
      //       ^ i
      //^ i-7
      int len = wow.size();
      int ch1 = wow[len-1];
      int ch2 = wow[len-3];
      int cur = o++;
      adj[cur].push_back(ch1);
      adj[cur].push_back(ch2);
      //cout << cur << " " << ch1 << "\n";
      //cout << cur << " " << ch2 << "\n";
      tag[cur] = (wow[len-5] == -6 ? 'a' : 'i');
      for(int j=len-1; j>=len-7; j--) wow.pop_back();
      wow.push_back(cur);
    }
  }
  int rt = o - 1;
  dfs(rt);
  dpf(rt);
  cout << ma[rt] - mi[rt] + 1 << "\n";
  //for(int i=0; i<=rt; i++) cout << "[" << mi[i] << ", " << ma[i] << "]\n";
} 
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// I don't know geometry.
// Teaming is unfair.

/*

*/

Compilation message

Main.cpp: In function 'void solve(int)':
Main.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int i=0; i<t.size(); i++) {
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47324 KB Output is correct
2 Correct 25 ms 47292 KB Output is correct
3 Correct 24 ms 47308 KB Output is correct
4 Correct 26 ms 47288 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 25 ms 47208 KB Output is correct
7 Correct 26 ms 47316 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47224 KB Output is correct
10 Correct 25 ms 47316 KB Output is correct
11 Correct 25 ms 47280 KB Output is correct
12 Correct 25 ms 47316 KB Output is correct
13 Correct 25 ms 47336 KB Output is correct
14 Correct 25 ms 47316 KB Output is correct
15 Correct 24 ms 47316 KB Output is correct
16 Correct 25 ms 47316 KB Output is correct
17 Correct 24 ms 47188 KB Output is correct
18 Correct 25 ms 47320 KB Output is correct
19 Correct 25 ms 47288 KB Output is correct
20 Correct 25 ms 47212 KB Output is correct
21 Correct 27 ms 47316 KB Output is correct
22 Correct 25 ms 47296 KB Output is correct
23 Correct 25 ms 47280 KB Output is correct
24 Correct 26 ms 47204 KB Output is correct
25 Correct 25 ms 47296 KB Output is correct
26 Correct 26 ms 47216 KB Output is correct
27 Correct 26 ms 47284 KB Output is correct
28 Correct 25 ms 47296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47324 KB Output is correct
2 Correct 25 ms 47292 KB Output is correct
3 Correct 24 ms 47308 KB Output is correct
4 Correct 26 ms 47288 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 25 ms 47208 KB Output is correct
7 Correct 26 ms 47316 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47224 KB Output is correct
10 Correct 25 ms 47316 KB Output is correct
11 Correct 25 ms 47280 KB Output is correct
12 Correct 25 ms 47316 KB Output is correct
13 Correct 25 ms 47336 KB Output is correct
14 Correct 25 ms 47316 KB Output is correct
15 Correct 24 ms 47316 KB Output is correct
16 Correct 25 ms 47316 KB Output is correct
17 Correct 24 ms 47188 KB Output is correct
18 Correct 25 ms 47320 KB Output is correct
19 Correct 25 ms 47288 KB Output is correct
20 Correct 25 ms 47212 KB Output is correct
21 Correct 27 ms 47316 KB Output is correct
22 Correct 25 ms 47296 KB Output is correct
23 Correct 25 ms 47280 KB Output is correct
24 Correct 26 ms 47204 KB Output is correct
25 Correct 25 ms 47296 KB Output is correct
26 Correct 26 ms 47216 KB Output is correct
27 Correct 26 ms 47284 KB Output is correct
28 Correct 25 ms 47296 KB Output is correct
29 Correct 25 ms 47304 KB Output is correct
30 Correct 27 ms 47300 KB Output is correct
31 Correct 25 ms 47256 KB Output is correct
32 Correct 26 ms 47180 KB Output is correct
33 Correct 26 ms 47180 KB Output is correct
34 Correct 25 ms 47316 KB Output is correct
35 Correct 24 ms 47208 KB Output is correct
36 Correct 24 ms 47292 KB Output is correct
37 Correct 24 ms 47240 KB Output is correct
38 Correct 24 ms 47296 KB Output is correct
39 Correct 24 ms 47196 KB Output is correct
40 Correct 25 ms 47308 KB Output is correct
41 Correct 26 ms 47292 KB Output is correct
42 Correct 26 ms 47316 KB Output is correct
43 Correct 28 ms 47260 KB Output is correct
44 Correct 25 ms 47316 KB Output is correct
45 Correct 29 ms 47276 KB Output is correct
46 Correct 26 ms 47444 KB Output is correct
47 Correct 25 ms 47280 KB Output is correct
48 Correct 25 ms 47180 KB Output is correct
49 Correct 28 ms 47184 KB Output is correct
50 Correct 28 ms 47316 KB Output is correct
51 Correct 25 ms 47316 KB Output is correct
52 Correct 25 ms 47236 KB Output is correct
53 Correct 26 ms 47320 KB Output is correct
54 Correct 27 ms 47188 KB Output is correct
55 Correct 26 ms 47316 KB Output is correct
56 Correct 26 ms 47276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 210668 KB Output is correct
2 Correct 308 ms 210612 KB Output is correct
3 Correct 313 ms 210584 KB Output is correct
4 Correct 315 ms 210592 KB Output is correct
5 Correct 298 ms 210696 KB Output is correct
6 Correct 298 ms 210692 KB Output is correct
7 Correct 294 ms 210580 KB Output is correct
8 Correct 313 ms 210668 KB Output is correct
9 Correct 296 ms 210608 KB Output is correct
10 Correct 295 ms 210628 KB Output is correct
11 Correct 291 ms 210620 KB Output is correct
12 Correct 289 ms 210640 KB Output is correct
13 Correct 25 ms 47316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47324 KB Output is correct
2 Correct 25 ms 47292 KB Output is correct
3 Correct 24 ms 47308 KB Output is correct
4 Correct 26 ms 47288 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 25 ms 47208 KB Output is correct
7 Correct 26 ms 47316 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47224 KB Output is correct
10 Correct 25 ms 47316 KB Output is correct
11 Correct 25 ms 47280 KB Output is correct
12 Correct 25 ms 47316 KB Output is correct
13 Correct 25 ms 47336 KB Output is correct
14 Correct 25 ms 47316 KB Output is correct
15 Correct 24 ms 47316 KB Output is correct
16 Correct 25 ms 47316 KB Output is correct
17 Correct 24 ms 47188 KB Output is correct
18 Correct 25 ms 47320 KB Output is correct
19 Correct 25 ms 47288 KB Output is correct
20 Correct 25 ms 47212 KB Output is correct
21 Correct 27 ms 47316 KB Output is correct
22 Correct 25 ms 47296 KB Output is correct
23 Correct 25 ms 47280 KB Output is correct
24 Correct 26 ms 47204 KB Output is correct
25 Correct 25 ms 47296 KB Output is correct
26 Correct 26 ms 47216 KB Output is correct
27 Correct 26 ms 47284 KB Output is correct
28 Correct 25 ms 47296 KB Output is correct
29 Correct 25 ms 47304 KB Output is correct
30 Correct 27 ms 47300 KB Output is correct
31 Correct 25 ms 47256 KB Output is correct
32 Correct 26 ms 47180 KB Output is correct
33 Correct 26 ms 47180 KB Output is correct
34 Correct 25 ms 47316 KB Output is correct
35 Correct 24 ms 47208 KB Output is correct
36 Correct 24 ms 47292 KB Output is correct
37 Correct 24 ms 47240 KB Output is correct
38 Correct 24 ms 47296 KB Output is correct
39 Correct 24 ms 47196 KB Output is correct
40 Correct 25 ms 47308 KB Output is correct
41 Correct 26 ms 47292 KB Output is correct
42 Correct 26 ms 47316 KB Output is correct
43 Correct 28 ms 47260 KB Output is correct
44 Correct 25 ms 47316 KB Output is correct
45 Correct 29 ms 47276 KB Output is correct
46 Correct 26 ms 47444 KB Output is correct
47 Correct 25 ms 47280 KB Output is correct
48 Correct 25 ms 47180 KB Output is correct
49 Correct 28 ms 47184 KB Output is correct
50 Correct 28 ms 47316 KB Output is correct
51 Correct 25 ms 47316 KB Output is correct
52 Correct 25 ms 47236 KB Output is correct
53 Correct 26 ms 47320 KB Output is correct
54 Correct 27 ms 47188 KB Output is correct
55 Correct 26 ms 47316 KB Output is correct
56 Correct 26 ms 47276 KB Output is correct
57 Correct 28 ms 47308 KB Output is correct
58 Correct 24 ms 47412 KB Output is correct
59 Correct 25 ms 47316 KB Output is correct
60 Correct 25 ms 47408 KB Output is correct
61 Correct 25 ms 47384 KB Output is correct
62 Correct 25 ms 47444 KB Output is correct
63 Correct 24 ms 47408 KB Output is correct
64 Correct 25 ms 47356 KB Output is correct
65 Correct 24 ms 47332 KB Output is correct
66 Correct 25 ms 47380 KB Output is correct
67 Correct 25 ms 47316 KB Output is correct
68 Correct 27 ms 47316 KB Output is correct
69 Correct 25 ms 47308 KB Output is correct
70 Correct 25 ms 47412 KB Output is correct
71 Correct 25 ms 47532 KB Output is correct
72 Correct 25 ms 47432 KB Output is correct
73 Correct 25 ms 47404 KB Output is correct
74 Correct 25 ms 47388 KB Output is correct
75 Correct 25 ms 47444 KB Output is correct
76 Correct 26 ms 47368 KB Output is correct
77 Correct 27 ms 47412 KB Output is correct
78 Correct 25 ms 47388 KB Output is correct
79 Correct 24 ms 47292 KB Output is correct
80 Correct 24 ms 47352 KB Output is correct
81 Correct 26 ms 47428 KB Output is correct
82 Correct 27 ms 47448 KB Output is correct
83 Correct 25 ms 47256 KB Output is correct
84 Correct 26 ms 47308 KB Output is correct
85 Correct 26 ms 47264 KB Output is correct
86 Correct 27 ms 47296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47324 KB Output is correct
2 Correct 25 ms 47292 KB Output is correct
3 Correct 24 ms 47308 KB Output is correct
4 Correct 26 ms 47288 KB Output is correct
5 Correct 28 ms 47316 KB Output is correct
6 Correct 25 ms 47208 KB Output is correct
7 Correct 26 ms 47316 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47224 KB Output is correct
10 Correct 25 ms 47316 KB Output is correct
11 Correct 25 ms 47280 KB Output is correct
12 Correct 25 ms 47316 KB Output is correct
13 Correct 25 ms 47336 KB Output is correct
14 Correct 25 ms 47316 KB Output is correct
15 Correct 24 ms 47316 KB Output is correct
16 Correct 25 ms 47316 KB Output is correct
17 Correct 24 ms 47188 KB Output is correct
18 Correct 25 ms 47320 KB Output is correct
19 Correct 25 ms 47288 KB Output is correct
20 Correct 25 ms 47212 KB Output is correct
21 Correct 27 ms 47316 KB Output is correct
22 Correct 25 ms 47296 KB Output is correct
23 Correct 25 ms 47280 KB Output is correct
24 Correct 26 ms 47204 KB Output is correct
25 Correct 25 ms 47296 KB Output is correct
26 Correct 26 ms 47216 KB Output is correct
27 Correct 26 ms 47284 KB Output is correct
28 Correct 25 ms 47296 KB Output is correct
29 Correct 25 ms 47304 KB Output is correct
30 Correct 27 ms 47300 KB Output is correct
31 Correct 25 ms 47256 KB Output is correct
32 Correct 26 ms 47180 KB Output is correct
33 Correct 26 ms 47180 KB Output is correct
34 Correct 25 ms 47316 KB Output is correct
35 Correct 24 ms 47208 KB Output is correct
36 Correct 24 ms 47292 KB Output is correct
37 Correct 24 ms 47240 KB Output is correct
38 Correct 24 ms 47296 KB Output is correct
39 Correct 24 ms 47196 KB Output is correct
40 Correct 25 ms 47308 KB Output is correct
41 Correct 26 ms 47292 KB Output is correct
42 Correct 26 ms 47316 KB Output is correct
43 Correct 28 ms 47260 KB Output is correct
44 Correct 25 ms 47316 KB Output is correct
45 Correct 29 ms 47276 KB Output is correct
46 Correct 26 ms 47444 KB Output is correct
47 Correct 25 ms 47280 KB Output is correct
48 Correct 25 ms 47180 KB Output is correct
49 Correct 28 ms 47184 KB Output is correct
50 Correct 28 ms 47316 KB Output is correct
51 Correct 25 ms 47316 KB Output is correct
52 Correct 25 ms 47236 KB Output is correct
53 Correct 26 ms 47320 KB Output is correct
54 Correct 27 ms 47188 KB Output is correct
55 Correct 26 ms 47316 KB Output is correct
56 Correct 26 ms 47276 KB Output is correct
57 Correct 391 ms 210668 KB Output is correct
58 Correct 308 ms 210612 KB Output is correct
59 Correct 313 ms 210584 KB Output is correct
60 Correct 315 ms 210592 KB Output is correct
61 Correct 298 ms 210696 KB Output is correct
62 Correct 298 ms 210692 KB Output is correct
63 Correct 294 ms 210580 KB Output is correct
64 Correct 313 ms 210668 KB Output is correct
65 Correct 296 ms 210608 KB Output is correct
66 Correct 295 ms 210628 KB Output is correct
67 Correct 291 ms 210620 KB Output is correct
68 Correct 289 ms 210640 KB Output is correct
69 Correct 25 ms 47316 KB Output is correct
70 Correct 28 ms 47308 KB Output is correct
71 Correct 24 ms 47412 KB Output is correct
72 Correct 25 ms 47316 KB Output is correct
73 Correct 25 ms 47408 KB Output is correct
74 Correct 25 ms 47384 KB Output is correct
75 Correct 25 ms 47444 KB Output is correct
76 Correct 24 ms 47408 KB Output is correct
77 Correct 25 ms 47356 KB Output is correct
78 Correct 24 ms 47332 KB Output is correct
79 Correct 25 ms 47380 KB Output is correct
80 Correct 25 ms 47316 KB Output is correct
81 Correct 27 ms 47316 KB Output is correct
82 Correct 25 ms 47308 KB Output is correct
83 Correct 25 ms 47412 KB Output is correct
84 Correct 25 ms 47532 KB Output is correct
85 Correct 25 ms 47432 KB Output is correct
86 Correct 25 ms 47404 KB Output is correct
87 Correct 25 ms 47388 KB Output is correct
88 Correct 25 ms 47444 KB Output is correct
89 Correct 26 ms 47368 KB Output is correct
90 Correct 27 ms 47412 KB Output is correct
91 Correct 25 ms 47388 KB Output is correct
92 Correct 24 ms 47292 KB Output is correct
93 Correct 24 ms 47352 KB Output is correct
94 Correct 26 ms 47428 KB Output is correct
95 Correct 27 ms 47448 KB Output is correct
96 Correct 25 ms 47256 KB Output is correct
97 Correct 26 ms 47308 KB Output is correct
98 Correct 26 ms 47264 KB Output is correct
99 Correct 27 ms 47296 KB Output is correct
100 Correct 249 ms 144248 KB Output is correct
101 Correct 244 ms 144060 KB Output is correct
102 Correct 240 ms 144088 KB Output is correct
103 Correct 242 ms 144132 KB Output is correct
104 Correct 235 ms 144276 KB Output is correct
105 Correct 264 ms 166268 KB Output is correct
106 Correct 269 ms 166252 KB Output is correct
107 Correct 260 ms 166316 KB Output is correct
108 Correct 284 ms 166252 KB Output is correct
109 Correct 270 ms 166240 KB Output is correct
110 Correct 256 ms 144272 KB Output is correct
111 Correct 257 ms 144172 KB Output is correct
112 Correct 254 ms 144116 KB Output is correct
113 Correct 245 ms 144104 KB Output is correct
114 Correct 248 ms 144180 KB Output is correct
115 Correct 312 ms 210692 KB Output is correct
116 Correct 306 ms 210560 KB Output is correct
117 Correct 298 ms 210640 KB Output is correct
118 Correct 295 ms 210852 KB Output is correct
119 Correct 298 ms 210760 KB Output is correct
120 Correct 247 ms 144112 KB Output is correct
121 Correct 245 ms 144160 KB Output is correct
122 Correct 251 ms 144136 KB Output is correct
123 Correct 256 ms 144076 KB Output is correct
124 Correct 261 ms 179432 KB Output is correct
125 Correct 253 ms 179312 KB Output is correct
126 Correct 251 ms 179452 KB Output is correct
127 Correct 259 ms 179360 KB Output is correct
128 Correct 139 ms 98012 KB Output is correct
129 Correct 134 ms 98108 KB Output is correct
130 Correct 135 ms 98008 KB Output is correct
131 Correct 26 ms 47296 KB Output is correct