답안 #1119054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1119054 2024-11-26T14:23:21 Z stefanneagu Cat Exercise (JOI23_ho_t4) C++17
21 / 100
85 ms 20452 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 2e5 + 1;

int v[nmax], n;

struct AINT {
  int ma[nmax * 4], ai[nmax * 4];

  void build(int nod = 1, int st = 1, int dr = n) {
    if(st == dr) {
      ma[nod] = v[st];
      ai[nod] = st;
      return;
    }
    int mid = (st + dr) / 2;
    build(nod * 2, st, mid);
    build(nod * 2 + 1, mid + 1, dr);
    if(ma[nod * 2] > ma[nod * 2 + 1]) {
      ma[nod] = ma[nod * 2];
      ai[nod] = ai[nod * 2];
    } else {
      ma[nod] = ma[nod * 2 + 1];
      ai[nod] = ai[nod * 2 + 1];
    }
  }

  int query(int l, int r, int nod = 1, int st = 1, int dr = n) {
    if(dr < l || r < st)  {
      return 0;
    }
    if(l <= st && dr <= r) {
      return ai[nod];
    }
    int mid = (st + dr) / 2;
    int i1 = query(l, r, nod * 2, st, mid);
    int i2 = query(l, r, nod * 2 + 1, mid + 1, dr);
    if(v[i1] > v[i2]) {
      return i1;
    }
    return i2;
  }
} st;

int d[nmax];
int maxx = 0;

void solve(int l, int r, int loc, int curr) {
  if(l == r) {
    maxx = max(maxx, curr);
    return;
  }
  int x;
  if(loc == 0) {
    // stanga
    x = st.query(l + 1, r);
    solve(l + 1, x, 1, curr + x - l);
    solve(x, r, 0, curr + x - l);
  } else {
    //dreapta
    x = st.query(l, r - 1);
    solve(l, x, 1, curr + r - x);
    solve(x, r - 1, 0, curr + r - x);
  }
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  int pn;
  for(int i = 1; i <= n; i++) {
    cin >> v[i];
    if(v[i] == n) {
      pn = i;
    }
  }
  for(int i = 1; i < n; i++) {
    int useless;
    cin >> useless >> useless;
  }
  st.build();
  solve(1, pn, 1, 0);
  solve(pn, n, 0, 0);
  cout << maxx;
  return 0;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:86:8: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |   solve(pn, n, 0, 0);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4484 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 2 ms 4692 KB Output is correct
9 Correct 1 ms 4604 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4484 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 2 ms 4692 KB Output is correct
9 Correct 1 ms 4604 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4596 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4712 KB Output is correct
16 Correct 1 ms 4692 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4484 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 2 ms 4692 KB Output is correct
9 Correct 1 ms 4604 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4596 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4712 KB Output is correct
16 Correct 1 ms 4692 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
18 Correct 3 ms 4692 KB Output is correct
19 Correct 4 ms 4692 KB Output is correct
20 Correct 3 ms 4824 KB Output is correct
21 Correct 3 ms 4436 KB Output is correct
22 Correct 3 ms 4692 KB Output is correct
23 Correct 3 ms 4664 KB Output is correct
24 Correct 3 ms 4652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4484 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 2 ms 4692 KB Output is correct
9 Correct 1 ms 4604 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4596 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4712 KB Output is correct
16 Correct 1 ms 4692 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
18 Correct 3 ms 4692 KB Output is correct
19 Correct 4 ms 4692 KB Output is correct
20 Correct 3 ms 4824 KB Output is correct
21 Correct 3 ms 4436 KB Output is correct
22 Correct 3 ms 4692 KB Output is correct
23 Correct 3 ms 4664 KB Output is correct
24 Correct 3 ms 4652 KB Output is correct
25 Correct 1 ms 4436 KB Output is correct
26 Incorrect 3 ms 4576 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4484 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 2 ms 4692 KB Output is correct
9 Correct 1 ms 4604 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4596 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4712 KB Output is correct
16 Correct 1 ms 4692 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
18 Correct 3 ms 4692 KB Output is correct
19 Correct 4 ms 4692 KB Output is correct
20 Correct 3 ms 4824 KB Output is correct
21 Correct 3 ms 4436 KB Output is correct
22 Correct 3 ms 4692 KB Output is correct
23 Correct 3 ms 4664 KB Output is correct
24 Correct 3 ms 4652 KB Output is correct
25 Incorrect 85 ms 20452 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4436 KB Output is correct
2 Incorrect 1 ms 4516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4484 KB Output is correct
2 Correct 2 ms 4436 KB Output is correct
3 Correct 1 ms 4436 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 2 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 2 ms 4692 KB Output is correct
9 Correct 1 ms 4604 KB Output is correct
10 Correct 1 ms 4436 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4436 KB Output is correct
13 Correct 2 ms 4596 KB Output is correct
14 Correct 2 ms 4436 KB Output is correct
15 Correct 2 ms 4712 KB Output is correct
16 Correct 1 ms 4692 KB Output is correct
17 Correct 1 ms 4436 KB Output is correct
18 Correct 3 ms 4692 KB Output is correct
19 Correct 4 ms 4692 KB Output is correct
20 Correct 3 ms 4824 KB Output is correct
21 Correct 3 ms 4436 KB Output is correct
22 Correct 3 ms 4692 KB Output is correct
23 Correct 3 ms 4664 KB Output is correct
24 Correct 3 ms 4652 KB Output is correct
25 Correct 1 ms 4436 KB Output is correct
26 Incorrect 3 ms 4576 KB Output isn't correct
27 Halted 0 ms 0 KB -