Submission #835100

# Submission time Handle Problem Language Result Execution time Memory
835100 2023-08-23T08:15:31 Z veehj Cat Exercise (JOI23_ho_t4) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
int n; vector<pair<int, int>> p;

int f(ll l, ll r, ll nw){
  if(r<=l) return abs(nw-r);
  int ans=0;
  int ht;
  for(int i=0; i<n; i++){
    if(l<=p[i].S && p[i].S<=r){
      ht=p[i].S;
      ans+=abs(nw-ht);
      break;
    }
  }
  if(abs(l-(ht-1))>abs(r-(ht+1))) ans+=f(l, ht-1, ht);
  else ans+=f(ht+1, r, ht);
  return ans;
}

int main() {
    cin >> n;
    p.resize(n); 
    for(int i=0; i<n; i++){
      cin >> p[i].F;
      p[i].S=i;
    }
    sort(all(p), greater<pair<int, int>>());
    int a, b; for(int i=0; i<n-1; i++) cin >> a >> b;
    cout << f(0, n-1, p[0].S);
}

Compilation message

Main.cpp: In function 'int f(ll, ll, ll)':
Main.cpp:24:41: warning: 'ht' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |   if(abs(l-(ht-1))>abs(r-(ht+1))) ans+=f(l, ht-1, ht);
      |                                        ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -