Submission #439902

# Submission time Handle Problem Language Result Execution time Memory
439902 2021-07-01T07:04:37 Z QuantumK9 Distributing Candies (IOI21_candies) C++17
11 / 100
175 ms 16028 KB
#include "candies.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;

vector<int> st1(vector<int> c, vector<int> l,
                vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n);
    for( int i = 0; i < n; i++ ){ s[i] = 0; }
    int q = v.size();
    for( int i = 0; i < q; i++ ){
        for( int j = l[i]; j <= r[i]; j++ ){
            if( v[i] > 0 ){ s[j] = min( c[j], s[j]+v[i] ); }
            else if ( v[i] < 0 ){ s[j] = max( 0, s[j]+v[i] ); }
        }
    }
    return s;
}


vector<int> st2(vector<int> c, vector<int> l,
                vector<int> r, vector<int> v) {
    int n = c.size();
    int q = v.size();

    vector<ll> pfs(n+3);
    for( int i = 0; i < n+3; i++ ){ pfs[i] = 0; }

    for( int i = 0; i < q; i++ ){
        pfs[ l[i] ] += v[i];
        pfs[ r[i]+1 ] -= v[i];
    }

    vector<int> ans(n);
    ll rs = 0;
    for( int i = 0; i < n; i++ ){
        rs += pfs[i];
        ans[i] = min( (ll)c[i], rs );
    }
    return ans;
}


vector<int> distribute_candies(vector<int> c, vector<int> l,
                               vector<int> r, vector<int> v) {
    int n = c.size();
    int q = v.size();

    if ( n <= 2000 && q <= 2000 ){ return st1(c,l,r,v); }
    else{ return st2(c,l,r,v); }

    //return st2(c,l,r,v);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 11972 KB Output is correct
2 Correct 175 ms 16028 KB Output is correct
3 Correct 123 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 88 ms 10312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 84 ms 9920 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 130 ms 11972 KB Output is correct
7 Correct 175 ms 16028 KB Output is correct
8 Correct 123 ms 15952 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Incorrect 88 ms 10312 KB Output isn't correct
11 Halted 0 ms 0 KB -