Submission #828726

# Submission time Handle Problem Language Result Execution time Memory
828726 2023-08-17T14:21:41 Z fatemetmhr Distributing Candies (IOI21_candies) C++17
64 / 100
4986 ms 17396 KB
//#pragma GCC optimize ("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops,O3")

#include "candies.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define debug(x)  cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x)    x.begin(), x.end()
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define fi        first
#define se        second
#define pb        push_back
#define mp        make_pair

const int ss    = 1500;
const int maxn5 = 2e5 + 10;

int ret[maxn5], c[maxn5], sig[maxn5];
int L[maxn5], R[maxn5], V[maxn5];

std::vector<int> distribute_candies(std::vector<int> C, std::vector<int> LL,
                                    std::vector<int> RR, std::vector<int> VV) {
    int n = C.size(), q = LL.size();
    for(int i = 0; i < n; i++)
        c[i] = C[i];
    for(int i = 0; i < q; i++){
        L[i] = LL[i];
        R[i] = RR[i];
        V[i] = VV[i];
        sig[i] = (V[i] > 0 ? 1 : -1);
    }
    for(int tt = 0; tt < n; tt += ss){
        for(int i = 1; i < q; i += 2){
            int lim = MIN(tt + ss, n);
            int v1 = V[i - 1], v2 = V[i];
            if(MAX(L[i], L[i - 1] > tt || MIN(R[i], R[i - 1]) < lim - 1)){
                int l = MAX(tt, L[i - 1]), r = MIN(lim, R[i - 1] + 1);
                for(int j = l; j < r; j++){
                    ret[j] += v1;
                    ret[j] = (ret[j] < 0 ? 0 : (ret[j] > c[j] ? c[j] : ret[j]));
                }
                l = MAX(tt, L[i]); 
                r = MIN(lim, R[i] + 1);
                for(int j = l; j < r; j++){
                    ret[j] += v2;
                    ret[j] = (ret[j] < 0 ? 0 : (ret[j] > c[j] ? c[j] : ret[j]));
                }
            }
            else{
                if(sig[i] == sig[i - 1]){
                    v1 += v2;
                    if(v1 > 0){
                        for(int i = tt; i < lim; i++){
                            ret[i] = MIN(c[i], ret[i] + v1);
                        }
                    }
                    else{
                        for(int i = tt; i < lim; i++){
                            ret[i] = MAX(0, ret[i] + v1);
                        }
                    }
                }
                else{
                    for(int j = tt; j < lim; j++){
                        ret[j] += v1;
                        ret[j] = (ret[j] < 0 ? 0 : (ret[j] > c[j] ? c[j] : ret[j]));
                        ret[j] += v2;
                        ret[j] = (ret[j] < 0 ? 0 : (ret[j] > c[j] ? c[j] : ret[j]));
                    }
                }
            }
        }
    }

    std::vector<int> s;
    for(int i = 0; i < n; i++)
        s.pb(ret[i]);
    return s;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2699 ms 12420 KB Output is correct
2 Correct 2676 ms 12368 KB Output is correct
3 Correct 2677 ms 12332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 78 ms 8176 KB Output is correct
3 Correct 68 ms 5540 KB Output is correct
4 Correct 2716 ms 12388 KB Output is correct
5 Correct 2757 ms 12428 KB Output is correct
6 Correct 2719 ms 12336 KB Output is correct
7 Correct 2703 ms 12392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 92 ms 8172 KB Output is correct
4 Correct 85 ms 4620 KB Output is correct
5 Correct 4918 ms 12412 KB Output is correct
6 Correct 4986 ms 16608 KB Output is correct
7 Correct 4970 ms 17148 KB Output is correct
8 Correct 4923 ms 15788 KB Output is correct
9 Correct 4293 ms 17396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -