답안 #435002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435002 2021-06-22T18:52:11 Z MilosMilutinovic 사탕 분배 (IOI21_candies) C++17
11 / 100
131 ms 12784 KB
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define mod 998244353
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll ksm(ll a, ll b) {if (b == 0) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
using namespace std;

const int maxn = 200005;
int n, q;
vi a(maxn);

vi brute_force(vi c, vi l, vi r, vi v) {
    for (int i = 0; i < q; i++) {
        for (int j = l[i]; j <= r[i]; j++) {
            if (v[i] > 0) a[j] = min(c[j], a[j] + v[i]);
            else a[j] = max(0, a[j] + v[i]);
        }
    }
    return a;
}

vi all_positive(vi c, vi l, vi r, vi v) {
    vector<ll> pref(n);
    for (int i = 0; i < q; i++) {
        pref[l[i]] += v[i];
        if (r[i] + 1 < n) pref[r[i] + 1] -= v[i];
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += pref[i];
        a[i] = min((ll) c[i], sum);
    }
    return a;
}

vi distribute_candies(vi c, vi l, vi r, vi v) {
    n = (int) c.size();
    q = (int) l.size();
    a.resize(n);
    if (n <= 2000 && q <= 2000) {
        return brute_force(c, l, r, v);
    }
    int mini = 1e9;
    for (int i = 0; i < n; i++) chkmin(mini, v[i]);
    if (mini > 0) {
        return all_positive(c, l, r, v);
    }
}

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:55:1: warning: control reaches end of non-void function [-Wreturn-type]
   55 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 12736 KB Output is correct
2 Correct 122 ms 12784 KB Output is correct
3 Correct 127 ms 12784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Incorrect 64 ms 8260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Incorrect 64 ms 8164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 131 ms 12736 KB Output is correct
7 Correct 122 ms 12784 KB Output is correct
8 Correct 127 ms 12784 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Incorrect 64 ms 8260 KB Output isn't correct
11 Halted 0 ms 0 KB -