답안 #865534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865534 2023-10-24T09:35:35 Z mychecksedad Homework (CEOI22_homework) C++17
53 / 100
120 ms 172076 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;

vector<int> g[N];
vector<int> tp;
int sz[N];
pair<int, int> dfs(int v){
  sz[v] = tp[v] == 2;
  if(tp[v] == 2) return {1, 1};
  pair<int, int> x = dfs(g[v][0]);
  pair<int, int> y = dfs(g[v][1]);
  // cout << g[v][0] << ": " << x.first << ' ' << x.second << '|' << g[v][1] << ": " << y.first << ' ' << y.second << '\n';
  sz[v] += sz[g[v][0]];
  sz[v] += sz[g[v][1]];
  if(tp[v] == 0)
    return {min(x.first, y.first), x.second + y.second - 1};
  return {x.first + y.first, max(sz[g[v][0]] + y.second, x.second + sz[g[v][1]])};
}
string s;
void solve(){
  cin >> s;
  int n = 0, mx = 0, mn = 0;
  int cur = 1;
  tp.resize(s.size()+2);
  vector<int> last;
  for(int i = 0 ; i < s.length(); ++i){
    if(s[i] == '?'){
      tp[cur] = 2;
      if(!last.empty()){
        g[last.back()].pb(cur);
      }

      ++cur;
    }else if(s[i] == '('){
      if(!last.empty()){
        g[last.back()].pb(cur);
      }
      if(s[i - 1] == 'n') tp[cur] = 0;
      else if(s[i - 1] == 'x') tp[cur] = 1;
      last.pb(cur);
      ++cur;
    }else if(s[i] == ')'){
      last.pop_back();
    }
  }
  auto R = dfs(1);

  cout << R.second-R.first+1;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // cin >> tt;
  while(tt--){
    solve();
    // en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i = 0 ; i < s.length(); ++i){
      |                   ~~^~~~~~~~~~~~
Main.cpp:30:7: warning: unused variable 'n' [-Wunused-variable]
   30 |   int n = 0, mx = 0, mn = 0;
      |       ^
Main.cpp:30:14: warning: unused variable 'mx' [-Wunused-variable]
   30 |   int n = 0, mx = 0, mn = 0;
      |              ^~
Main.cpp:30:22: warning: unused variable 'mn' [-Wunused-variable]
   30 |   int n = 0, mx = 0, mn = 0;
      |                      ^~
Main.cpp: In function 'int main()':
Main.cpp:62:15: warning: unused variable 'aa' [-Wunused-variable]
   62 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25432 KB Output is correct
2 Correct 6 ms 25640 KB Output is correct
3 Correct 5 ms 25436 KB Output is correct
4 Correct 5 ms 25436 KB Output is correct
5 Correct 5 ms 25436 KB Output is correct
6 Correct 5 ms 25436 KB Output is correct
7 Correct 5 ms 25556 KB Output is correct
8 Correct 5 ms 25556 KB Output is correct
9 Correct 5 ms 25632 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 5 ms 25640 KB Output is correct
12 Correct 5 ms 25564 KB Output is correct
13 Correct 5 ms 25432 KB Output is correct
14 Correct 5 ms 25544 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 5 ms 25436 KB Output is correct
17 Correct 5 ms 25436 KB Output is correct
18 Correct 6 ms 25436 KB Output is correct
19 Correct 5 ms 25436 KB Output is correct
20 Correct 5 ms 25436 KB Output is correct
21 Correct 5 ms 25632 KB Output is correct
22 Correct 5 ms 25436 KB Output is correct
23 Correct 5 ms 25436 KB Output is correct
24 Correct 5 ms 25560 KB Output is correct
25 Correct 5 ms 25436 KB Output is correct
26 Correct 6 ms 25432 KB Output is correct
27 Correct 5 ms 25436 KB Output is correct
28 Correct 6 ms 25436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25432 KB Output is correct
2 Correct 6 ms 25640 KB Output is correct
3 Correct 5 ms 25436 KB Output is correct
4 Correct 5 ms 25436 KB Output is correct
5 Correct 5 ms 25436 KB Output is correct
6 Correct 5 ms 25436 KB Output is correct
7 Correct 5 ms 25556 KB Output is correct
8 Correct 5 ms 25556 KB Output is correct
9 Correct 5 ms 25632 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 5 ms 25640 KB Output is correct
12 Correct 5 ms 25564 KB Output is correct
13 Correct 5 ms 25432 KB Output is correct
14 Correct 5 ms 25544 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 5 ms 25436 KB Output is correct
17 Correct 5 ms 25436 KB Output is correct
18 Correct 6 ms 25436 KB Output is correct
19 Correct 5 ms 25436 KB Output is correct
20 Correct 5 ms 25436 KB Output is correct
21 Correct 5 ms 25632 KB Output is correct
22 Correct 5 ms 25436 KB Output is correct
23 Correct 5 ms 25436 KB Output is correct
24 Correct 5 ms 25560 KB Output is correct
25 Correct 5 ms 25436 KB Output is correct
26 Correct 6 ms 25432 KB Output is correct
27 Correct 5 ms 25436 KB Output is correct
28 Correct 6 ms 25436 KB Output is correct
29 Correct 5 ms 25436 KB Output is correct
30 Correct 6 ms 25636 KB Output is correct
31 Correct 5 ms 25436 KB Output is correct
32 Correct 5 ms 25436 KB Output is correct
33 Correct 5 ms 25532 KB Output is correct
34 Correct 5 ms 25432 KB Output is correct
35 Correct 5 ms 25636 KB Output is correct
36 Correct 5 ms 25436 KB Output is correct
37 Correct 5 ms 25644 KB Output is correct
38 Correct 5 ms 25436 KB Output is correct
39 Correct 6 ms 25436 KB Output is correct
40 Correct 5 ms 25436 KB Output is correct
41 Correct 5 ms 25632 KB Output is correct
42 Correct 5 ms 25432 KB Output is correct
43 Correct 5 ms 25436 KB Output is correct
44 Correct 5 ms 25436 KB Output is correct
45 Correct 5 ms 25436 KB Output is correct
46 Correct 5 ms 25436 KB Output is correct
47 Correct 5 ms 25436 KB Output is correct
48 Correct 6 ms 25436 KB Output is correct
49 Correct 5 ms 25436 KB Output is correct
50 Correct 5 ms 25432 KB Output is correct
51 Correct 5 ms 25436 KB Output is correct
52 Correct 5 ms 25436 KB Output is correct
53 Correct 5 ms 25636 KB Output is correct
54 Correct 5 ms 25432 KB Output is correct
55 Correct 5 ms 25436 KB Output is correct
56 Correct 7 ms 25436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 120 ms 172076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25432 KB Output is correct
2 Correct 6 ms 25640 KB Output is correct
3 Correct 5 ms 25436 KB Output is correct
4 Correct 5 ms 25436 KB Output is correct
5 Correct 5 ms 25436 KB Output is correct
6 Correct 5 ms 25436 KB Output is correct
7 Correct 5 ms 25556 KB Output is correct
8 Correct 5 ms 25556 KB Output is correct
9 Correct 5 ms 25632 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 5 ms 25640 KB Output is correct
12 Correct 5 ms 25564 KB Output is correct
13 Correct 5 ms 25432 KB Output is correct
14 Correct 5 ms 25544 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 5 ms 25436 KB Output is correct
17 Correct 5 ms 25436 KB Output is correct
18 Correct 6 ms 25436 KB Output is correct
19 Correct 5 ms 25436 KB Output is correct
20 Correct 5 ms 25436 KB Output is correct
21 Correct 5 ms 25632 KB Output is correct
22 Correct 5 ms 25436 KB Output is correct
23 Correct 5 ms 25436 KB Output is correct
24 Correct 5 ms 25560 KB Output is correct
25 Correct 5 ms 25436 KB Output is correct
26 Correct 6 ms 25432 KB Output is correct
27 Correct 5 ms 25436 KB Output is correct
28 Correct 6 ms 25436 KB Output is correct
29 Correct 5 ms 25436 KB Output is correct
30 Correct 6 ms 25636 KB Output is correct
31 Correct 5 ms 25436 KB Output is correct
32 Correct 5 ms 25436 KB Output is correct
33 Correct 5 ms 25532 KB Output is correct
34 Correct 5 ms 25432 KB Output is correct
35 Correct 5 ms 25636 KB Output is correct
36 Correct 5 ms 25436 KB Output is correct
37 Correct 5 ms 25644 KB Output is correct
38 Correct 5 ms 25436 KB Output is correct
39 Correct 6 ms 25436 KB Output is correct
40 Correct 5 ms 25436 KB Output is correct
41 Correct 5 ms 25632 KB Output is correct
42 Correct 5 ms 25432 KB Output is correct
43 Correct 5 ms 25436 KB Output is correct
44 Correct 5 ms 25436 KB Output is correct
45 Correct 5 ms 25436 KB Output is correct
46 Correct 5 ms 25436 KB Output is correct
47 Correct 5 ms 25436 KB Output is correct
48 Correct 6 ms 25436 KB Output is correct
49 Correct 5 ms 25436 KB Output is correct
50 Correct 5 ms 25432 KB Output is correct
51 Correct 5 ms 25436 KB Output is correct
52 Correct 5 ms 25436 KB Output is correct
53 Correct 5 ms 25636 KB Output is correct
54 Correct 5 ms 25432 KB Output is correct
55 Correct 5 ms 25436 KB Output is correct
56 Correct 7 ms 25436 KB Output is correct
57 Correct 6 ms 25688 KB Output is correct
58 Correct 7 ms 25692 KB Output is correct
59 Correct 6 ms 25692 KB Output is correct
60 Correct 5 ms 25692 KB Output is correct
61 Correct 6 ms 25692 KB Output is correct
62 Correct 5 ms 25692 KB Output is correct
63 Correct 5 ms 25564 KB Output is correct
64 Correct 5 ms 25692 KB Output is correct
65 Correct 6 ms 25692 KB Output is correct
66 Correct 6 ms 25692 KB Output is correct
67 Correct 7 ms 25692 KB Output is correct
68 Correct 7 ms 25692 KB Output is correct
69 Correct 6 ms 25536 KB Output is correct
70 Correct 6 ms 25692 KB Output is correct
71 Correct 7 ms 25560 KB Output is correct
72 Correct 6 ms 25692 KB Output is correct
73 Correct 6 ms 25692 KB Output is correct
74 Correct 6 ms 25692 KB Output is correct
75 Correct 5 ms 25644 KB Output is correct
76 Correct 5 ms 25640 KB Output is correct
77 Correct 5 ms 25692 KB Output is correct
78 Correct 5 ms 25644 KB Output is correct
79 Correct 5 ms 25692 KB Output is correct
80 Correct 6 ms 25640 KB Output is correct
81 Correct 5 ms 25692 KB Output is correct
82 Correct 5 ms 25692 KB Output is correct
83 Correct 5 ms 25432 KB Output is correct
84 Correct 6 ms 25436 KB Output is correct
85 Correct 5 ms 25528 KB Output is correct
86 Correct 5 ms 25436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25432 KB Output is correct
2 Correct 6 ms 25640 KB Output is correct
3 Correct 5 ms 25436 KB Output is correct
4 Correct 5 ms 25436 KB Output is correct
5 Correct 5 ms 25436 KB Output is correct
6 Correct 5 ms 25436 KB Output is correct
7 Correct 5 ms 25556 KB Output is correct
8 Correct 5 ms 25556 KB Output is correct
9 Correct 5 ms 25632 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 5 ms 25640 KB Output is correct
12 Correct 5 ms 25564 KB Output is correct
13 Correct 5 ms 25432 KB Output is correct
14 Correct 5 ms 25544 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 5 ms 25436 KB Output is correct
17 Correct 5 ms 25436 KB Output is correct
18 Correct 6 ms 25436 KB Output is correct
19 Correct 5 ms 25436 KB Output is correct
20 Correct 5 ms 25436 KB Output is correct
21 Correct 5 ms 25632 KB Output is correct
22 Correct 5 ms 25436 KB Output is correct
23 Correct 5 ms 25436 KB Output is correct
24 Correct 5 ms 25560 KB Output is correct
25 Correct 5 ms 25436 KB Output is correct
26 Correct 6 ms 25432 KB Output is correct
27 Correct 5 ms 25436 KB Output is correct
28 Correct 6 ms 25436 KB Output is correct
29 Correct 5 ms 25436 KB Output is correct
30 Correct 6 ms 25636 KB Output is correct
31 Correct 5 ms 25436 KB Output is correct
32 Correct 5 ms 25436 KB Output is correct
33 Correct 5 ms 25532 KB Output is correct
34 Correct 5 ms 25432 KB Output is correct
35 Correct 5 ms 25636 KB Output is correct
36 Correct 5 ms 25436 KB Output is correct
37 Correct 5 ms 25644 KB Output is correct
38 Correct 5 ms 25436 KB Output is correct
39 Correct 6 ms 25436 KB Output is correct
40 Correct 5 ms 25436 KB Output is correct
41 Correct 5 ms 25632 KB Output is correct
42 Correct 5 ms 25432 KB Output is correct
43 Correct 5 ms 25436 KB Output is correct
44 Correct 5 ms 25436 KB Output is correct
45 Correct 5 ms 25436 KB Output is correct
46 Correct 5 ms 25436 KB Output is correct
47 Correct 5 ms 25436 KB Output is correct
48 Correct 6 ms 25436 KB Output is correct
49 Correct 5 ms 25436 KB Output is correct
50 Correct 5 ms 25432 KB Output is correct
51 Correct 5 ms 25436 KB Output is correct
52 Correct 5 ms 25436 KB Output is correct
53 Correct 5 ms 25636 KB Output is correct
54 Correct 5 ms 25432 KB Output is correct
55 Correct 5 ms 25436 KB Output is correct
56 Correct 7 ms 25436 KB Output is correct
57 Runtime error 120 ms 172076 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -