Submission #966165

# Submission time Handle Problem Language Result Execution time Memory
966165 2024-04-19T13:12:55 Z AkibAzmain Distributing Candies (IOI21_candies) C++17
0 / 100
90 ms 17640 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();
  list < ll > lv;
  lv.insert (lv.end (), (ll) -1e18);
  for (auto &x : v) lv.insert (lv.end (), x);
  if (lv.size () > 2)
    for (auto it = prev (lv.end (), 2);; --it)
      {
        if (*it >= 0 && *next (it, 1) >= 0) *it += *next (it, 1), lv.erase (next (it, 1));
        if (*it <= 0 && *next (it, 1) <= 0) *it += *next (it, 1), lv.erase (next (it, 1));
        if (it == lv.begin ()) break;
      }
  if (lv.size () > 3)
    for (auto it = prev (lv.end (), 3);; --it)
      {
        if (next (it, 2) == lv.end ())
          {
            if (it == lv.begin ()) break;
            continue;
          }
        if (*it >= 0 && *next (it, 1) <= 0 && *next (it, 2) >= 0
            && *it >= -*next (it, 1) && *next (it, 2) >= -*next (it, 1))
          *it += *next (it, 1) + *next (it, 2),
            lv.erase (next (it, 1)), lv.erase (next (it, 1));
        if (*it >= 0 && *next (it, 1) <= 0 && *next (it, 2) >= 0
            && -*it >= *next (it, 1) && -*next (it, 2) >= *next (it, 1))
          *it += *next (it, 1) + *next (it, 2),
            lv.erase (next (it, 1)), lv.erase (next (it, 1));
        if (it == lv.begin ()) break;
      }
  vector < ll > ss;
  for (auto &x : lv) ss.push_back (x);
  ss.push_back (0);
  map < ll, pair < int, bool > > mp;
  for (int i = ss.size () - 2; i >= 0; --i)
    {
      if (mp.count (abs (ss[i])) == 0)
        mp[abs (ss[i])] = { i, ss[i] >= 0 };
      ss[i] += ss[i + 1];
    }
  vector < int > ans (n);
  for (int i = 0; i < n; ++i)
    {
      auto it = mp.lower_bound (c[i])->second;
      if (it.second) ans[i] = c[i] + ss[it.first + 1];
      else ans[i] = ss[it.first + 1];
    }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 17640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 68 ms 14684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -