답안 #966187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966187 2024-04-19T13:49:03 Z AkibAzmain 사탕 분배 (IOI21_candies) C++17
29 / 100
150 ms 32572 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

std::vector<int> distribute_candies (std::vector<int> c, std::vector<int> l,
                                     std::vector<int> r, std::vector<int> v)
{
  ll n = c.size();
  v.push_back (0);
  vector < ll > a;
  for (auto &x : v) a.push_back (x);
  reverse (a.begin (), a.end ());
  a.push_back (-1e18);
  for (auto &x : a) x *= -1;
  for (int i = 1; i < a.size (); ++i) a[i] += a[i - 1];
  pair < ll, ll > mn = { 0, 0 }, mx = { 0, 0 };
  vector < pair < ll, ll > > mna (a.size ()), mxa = mna;
  map < ll, int > mp;
  for (int i = 0; i < a.size (); ++i)
    {
      if (a[i] < mn.first) mn = { a[i], i };
      if (a[i] > mx.first) mx = { a[i], i };
      mna[i] = mn;
      mxa[i] = mx;
      if (mp.count (mx.first - mn.first) == 0)
        mp[mx.first - mn.first] = i;
    }
  vector < int > ans (n);
  for (int i = 0; i < n; ++i)
    {
      int j = mp.lower_bound (c[i])->second;
      if (a[j] == mna[j].first)
        ans[i] = c[i] - a[mxa[j].second];
      else
        ans[i] = -a[mna[j].second];
      if (ans[i] < 0) ans[i] += c[i];
    }
  return ans;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for (int i = 1; i < a.size (); ++i) a[i] += a[i - 1];
      |                   ~~^~~~~~~~~~~
candies.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for (int i = 0; i < a.size (); ++i)
      |                   ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 Incorrect 150 ms 32572 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 Correct 1 ms 344 KB Output is correct
3 Correct 48 ms 16588 KB Output is correct
4 Correct 40 ms 4164 KB Output is correct
5 Correct 96 ms 19076 KB Output is correct
6 Correct 104 ms 19536 KB Output is correct
7 Correct 91 ms 20284 KB Output is correct
8 Correct 89 ms 18848 KB Output is correct
9 Correct 150 ms 32572 KB Output is correct
# 결과 실행 시간 메모리 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 -