Submission #800440

# Submission time Handle Problem Language Result Execution time Memory
800440 2023-08-01T14:57:24 Z Khizri Distributing Candies (IOI21_candies) C++17
0 / 100
3811 ms 2097152 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=2005;
int n,q;
vector<ll>pre[mxn];
vector<int> distribute_candies(vector<int> c, vector<int> x, vector<int> y, vector<int> vq) {
    n = c.size();
    q=x.size();
    for(int i=0;i<q;i++){
        int l=x[i],r=y[i],val=vq[i];
        for(int j=l;j<=r;j++){
            pre[j].pb(vq[i]);
        }
    }
    vector<int>ans;
    for(int id=0;id<n;id++){
        ll lim=c[id];
        for(int i=1;i<pre[id].size();i++){
            pre[id][i]+=pre[id][i-1];
        }
        ll mx=-INF,mn=INF,idx=-1,idx2=-1,left;
        for(int i=pre[id].size()-1;i>=0;i--){
            if(pre[id][i]>mx){
                mx=pre[id][i];
                idx=i;
            }
            if(pre[id][i]<mn){
                mn=pre[id][i];
                idx2=i;
            }
            if(mx-mn>lim){
                left=i;
                break;
            }
        }
        if(pre[id].size()==0){
            ans.pb(0);
            continue;
        }
        if(mx-mn<lim){
            //cout<<"OK"<<endl;
            ans.pb(pre[id].back()-min(0ll,mn));
            continue;
        }
        ll a=pre[id][left];
        ll b=pre[id].back();
        if(a>=b){
            ans.pb(b-mn);
        }
        else{
            ans.pb(lim-(mx-b));
        }
    }
    return ans;
}
/*
g++ candies.cpp grader.cpp ; .\a.exe
3 
10 15 13
2
0 2 20
0 1 -11
1
4
9
0 0 -100
0 0 4
0 0 -8
0 0 200
0 0 -5
0 0 2
0 0 1
0 0 -2
0 0 1

1
67
3
0 0 -60
0 0 -41
0 0 100

-100 -96 -104 96 91 93 94 92 93
1
10
9
0 0 100
0 0 5
0 0 7
0 0 -4
0 0 -1000
0 0 2
0 0 1
0 0 10000
0 0 -9
-100 -95 -88 -92 -90 -89

1
50
8
0 0 100
0 0 -200
0 0 25
0 0 -30
0 0 14
0 0 50
0 0 -30
0 0 29

1
440
10
0 0 60
0 0 -9
0 0 -30
0 0 41
0 0 82
0 0 69
0 0 -79
0 0 -39
0 0 72
0 0 41
*/

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:22:27: warning: unused variable 'val' [-Wunused-variable]
   22 |         int l=x[i],r=y[i],val=vq[i];
      |                           ^~~
candies.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i=1;i<pre[id].size();i++){
      |                     ~^~~~~~~~~~~~~~~
candies.cpp:33:27: warning: variable 'idx' set but not used [-Wunused-but-set-variable]
   33 |         ll mx=-INF,mn=INF,idx=-1,idx2=-1,left;
      |                           ^~~
candies.cpp:33:34: warning: variable 'idx2' set but not used [-Wunused-but-set-variable]
   33 |         ll mx=-INF,mn=INF,idx=-1,idx2=-1,left;
      |                                  ^~~~
candies.cpp:57:26: warning: 'left' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |         ll a=pre[id][left];
      |                          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1124 KB Output is correct
5 Incorrect 15 ms 13964 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 68 ms 17804 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 2349 ms 1104752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Runtime error 3811 ms 2097152 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1124 KB Output is correct
5 Incorrect 15 ms 13964 KB Output isn't correct
6 Halted 0 ms 0 KB -