답안 #1020974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020974 2024-07-12T12:23:31 Z NeroZein 사탕 분배 (IOI21_candies) C++17
0 / 100
120 ms 16864 KB
#include "candies.h"
#include <bits/stdc++.h>
 
using namespace std; 
 
vector<int> distribute_candies(vector<int> c_, vector<int> ql, vector<int> qr, vector<int> v) {
  int n = (int) c_.size(), q = (int) ql.size();
  vector<pair<int, int>> c(n); 
  for (int i = 0; i < n; ++i) {
    c[i] = {c_[i], i};
  }
  sort(c.begin(), c.end());
  vector<pair<int, int>> reach(n);
  for (int i = 0; i < n; ++i) {
    reach[i].first = -1; 
  }
  long long mn = 0, mx = 0, sum = 0;
  for (int i = 0; i < q; ++i) {
    sum += v[i];
    mn = min(mn, sum);
    mx = max(mx, sum);
    if (v[i] > 0) {
      long long bigjump = sum - mn;
      int l = -1, r = n - 1;
      while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (c[mid].first <= bigjump) {
          l = mid;
        } else {
          r = mid - 1;
        }
      }
      if (l != -1) {
        reach[l] = {i, c[l].first};
      }      
    } else {
      long long smalljump = sum - mx;
      int l = -1, r = n - 1; 
      while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (smalljump <= -c[mid].first) {
          l = mid;
        } else {
          r = mid - 1; 
        }
      }
      
      if (l != -1) {
        reach[l] = {i, 0};
      }
    }
  }
  for (int i = n - 2; i >= 0; --i) {
    if (reach[i + 1].first > reach[i].first) {
      reach[i].first = reach[i + 1].first; 
      reach[i].second = min(reach[i + 1].second, c[i].first);
    }
  }
  vector<long long> ps(q);
  ps[0] = v[0];
  for (int i = 1; i < q; ++i) {
    ps[i] = ps[i - 1] + v[i]; 
  }
  vector<int> s(n);
  for (int i = 0; i < n; ++i) {
    s[c[i].second] = reach[i].second; 
    if (reach[i].first != -1) {
      s[c[i].second] += ps[q - 1] - ps[reach[i].first];      
    }
  }
  return s;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 120 ms 16864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 432 KB Output isn't correct
3 Halted 0 ms 0 KB -