Submission #1052992

# Submission time Handle Problem Language Result Execution time Memory
1052992 2024-08-11T07:26:40 Z mychecksedad Distributing Candies (IOI21_candies) C++17
0 / 100
2363 ms 2097152 KB
#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define pii pair<int,int>
#define ff first
#define ss second
const int N = 3e5+100;

std::vector<int> distribute_candies(std::vector<int> cc, std::vector<int> l, std::vector<int> r, std::vector<int> v) {
  vector<ll> c(all(cc));
  int n = c.size();
  int q = l.size();
  std::vector<int> s(n);

  vector<vector<int>> Q(n);
  for(int i = 0; i < q; ++i){
    for(int j = l[i]; j <= r[i]; ++j){
      Q[j].pb(v[i]);
    }
  }
  for(int i = 0; i < n; ++i){
    if(Q[i].size() == 0) continue;
    ll sum = 0;
    int x = 0;
    for(int j = Q[i].size() - 1; j >= 0; --j){
      // cout << Q[i][j] << ' ';
      ll v = Q[i][j] + sum;
      if(v >= c[i] || Q[i][j] >= c[i]){
        x = -1;
        int last = j;
        ll cur = 0;
        for(int l = j + 1; l < Q[i].size(); ++l){
          cur += Q[i][l];
          if(cur >= 0){
            last = l;
          }
        }
        ll sum = c[i];
        for(int l = last + 1; l < Q[i].size(); ++l){
          sum += Q[i][l];
        }
        // cout << "wtf" << sum << ' ';
        s[i] = sum;
        break;
      }else if(v <= -c[i] || Q[i][j] <= -c[i]){
        int last = j;
        ll cur = Q[i][j];
        for(int l = j + 1; l < Q[i].size(); ++l){
          cur += Q[i][l];
          if(cur <= 0){
            last = l;
          }
        }
        ll sum = 0;
        for(int l = last + 1; l < Q[i].size(); ++l){
          sum += Q[i][l];
        }
        s[i] = sum;
        x = -1;
        break;
      }
      sum = v;
    }
    if(x != -1){
      int j = 0;
      int last = j;
      ll cur = Q[i][j];
      for(int l = j + 1; l < Q[i].size(); ++l){
        cur += Q[i][l];
        if(cur <= 0){
          last = l;
        }
      }
      ll sum = 0;
      for(int l = last + 1; l < Q[i].size(); ++l){
        sum += Q[i][l];
      }
      s[i] = sum;
      x = -1;
    }
    // if(x==-1) continue;
    // sum = 0;
    // for(int j = x; j < Q[i].size(); ++j){
    //   sum += Q[i][j];
    //   sum = max(0ll, min(sum, c[i]));
    // }
    // s[i] = sum;
  }


  return s;
}

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:36:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int l = j + 1; l < Q[i].size(); ++l){
      |                            ~~^~~~~~~~~~~~~
candies.cpp:43:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int l = last + 1; l < Q[i].size(); ++l){
      |                               ~~^~~~~~~~~~~~~
candies.cpp:52:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int l = j + 1; l < Q[i].size(); ++l){
      |                            ~~^~~~~~~~~~~~~
candies.cpp:59:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int l = last + 1; l < Q[i].size(); ++l){
      |                               ~~^~~~~~~~~~~~~
candies.cpp:72:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |       for(int l = j + 1; l < Q[i].size(); ++l){
      |                          ~~^~~~~~~~~~~~~
candies.cpp:79:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |       for(int l = last + 1; l < Q[i].size(); ++l){
      |                             ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2363 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -