답안 #1092581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092581 2024-09-24T13:51:43 Z Trisanu_Das Cat Exercise (JOI23_ho_t4) C++17
21 / 100
2000 ms 9168 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
 
int n; vector<pair<int, int>> pos;
 
int f(ll l, ll r, ll nw){
  if(r <= l) return abs(nw - r);
  int ans = 0, ht;
  for(int i = 0; i < n; i++){
    if(l <= pos[i].ss && pos[i].ss <= r){
      ht = pos[i].ss;
      ans += abs(nw - ht);
      break;
    }
  }
  return ans + max(f(l, ht - 1, ht), f(ht + 1, r, ht));
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    pos.resize(n); 
    for(int i=0; i<n; i++){
      cin >> pos[i].ff;
      pos[i].ss = i;
    }
    sort(pos.begin(), pos.end(), greater<pair<int, int> >());
    int a, b; for(int i = 0; i < n - 1; i++) cin >> a >> b;
    cout << f(0, n - 1, pos[0].ss) << '\n';
}

Compilation message

Main.cpp: In function 'int f(ll, ll, ll)':
Main.cpp:20:39: warning: 'ht' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |   return ans + max(f(l, ht - 1, ht), f(ht + 1, r, ht));
      |                                      ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 10 ms 604 KB Output is correct
19 Correct 13 ms 716 KB Output is correct
20 Correct 13 ms 736 KB Output is correct
21 Correct 8 ms 348 KB Output is correct
22 Correct 8 ms 572 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 8 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 10 ms 604 KB Output is correct
19 Correct 13 ms 716 KB Output is correct
20 Correct 13 ms 736 KB Output is correct
21 Correct 8 ms 348 KB Output is correct
22 Correct 8 ms 572 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 8 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 8 ms 568 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 10 ms 604 KB Output is correct
19 Correct 13 ms 716 KB Output is correct
20 Correct 13 ms 736 KB Output is correct
21 Correct 8 ms 348 KB Output is correct
22 Correct 8 ms 572 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 8 ms 348 KB Output is correct
25 Execution timed out 2039 ms 9168 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 10 ms 604 KB Output is correct
19 Correct 13 ms 716 KB Output is correct
20 Correct 13 ms 736 KB Output is correct
21 Correct 8 ms 348 KB Output is correct
22 Correct 8 ms 572 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 8 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 8 ms 568 KB Output isn't correct
27 Halted 0 ms 0 KB -