답안 #522711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522711 2022-02-05T13:43:39 Z InternetPerson10 사탕 분배 (IOI21_candies) C++17
37 / 100
130 ms 22228 KB
#include "candies.h"
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const ll BIG = 123456789123456789;

vector<int> distribute_candies(vector<int> cInt, vector<int> lInt, vector<int> rInt, vector<int> vInt) {
    int n = cInt.size();
    int q = vInt.size();
    vector<ll> s(n+1), c(n), l(q), r(q), v(q);
    for(int i = 0; i < n; i++) {
        c[i] = cInt[i];
    }
    for(int i = 0; i < q; i++) {
        l[i] = lInt[i];
        r[i] = rInt[i];
        v[i] = vInt[i];
    }
    bool subtask2 = true, subtask3 = true, subtask4 = true;
    for(int i = 1; i < n; i++) {
        if(c[i] != c[i-1]) subtask3 = false;
    }
    for(int i = 0; i < q; i++) {
        if(v[i] < 0) subtask2 = false;
        if(r[i] - l[i] != n-1) subtask4 = false;
    }
    if(false) { // Subtask 1
        for(int i = 0; i < q; i++) {
            for(int j = l[i]; j <= r[i]; j++) {
                s[j] += v[i];
                s[j] = max(s[j], 0LL);
                s[j] = min(s[j], c[j]);
            }
        }
    }
    else if(subtask2) {
        for(int i = 0; i < q; i++) {
            s[l[i]] += v[i];
            s[r[i]+1] -= v[i];
        }
        for(int i = 1; i < n; i++) {
            s[i] += s[i-1];
        }
        for(int i = 0; i < n; i++) {
            s[i] = min(s[i], c[i]);
        }
    }
    else if(subtask3) {

    }
    else if(subtask4) {
        vector<ll> qs;
        qs.push_back(-BIG);
        auto sameSign = [&]() {
            ll x = qs[qs.size() - 2];
            ll y = qs[qs.size() - 1];
            return ((x >= 0 && y >= 0) || (x <= 0 && y <= 0));
        };
        auto decreasingOrder = [&]() {
            ll x = qs[qs.size() - 2];
            ll y = qs[qs.size() - 1];
            return (abs(x) > abs(y));
        };
        for(ll g : v) {
            qs.push_back(g);
            while(qs.size() > 1) {
                if(sameSign() || !decreasingOrder()) {
                    ll last = qs.back(); qs.pop_back();
                    qs[qs.size() - 1] += last;
                }
                else break;
            }
        }
        if(qs.size()%2) qs.push_back(0);
        qs.push_back(0);
        reverse(qs.begin(), qs.end());
        for(ll &g : qs) g = abs(g);
        vector<pair<ll, int>> caps(n);
        for(int i = 0; i < n; i++) caps[i] = {c[i], i};
        sort(caps.begin(), caps.end());
        ll currCount = 0;
        int j = 0;
        for(int i = 1; i < qs.size(); i++) {
            if(i%2 == 0) {
                currCount += (qs[i-1] - qs[i-2]);
            }
            while(j != n) {
                if(caps[j].first > qs[i]) break;
                if(i%2) s[caps[j].second] = currCount + (caps[j].first - qs[i-1]);
                else s[caps[j].second] = currCount;
                j++;
            }
        }
    }
    else {

    }
    vector<int> sInt(n);
    for(int i = 0; i < n; i++) sInt[i] = s[i];
    return sInt;
}

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:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for(int i = 1; i < qs.size(); i++) {
      |                        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 15208 KB Output is correct
2 Correct 95 ms 15068 KB Output is correct
3 Correct 94 ms 15068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 52 ms 9692 KB Output is correct
4 Correct 63 ms 9412 KB Output is correct
5 Correct 113 ms 20948 KB Output is correct
6 Correct 114 ms 21712 KB Output is correct
7 Correct 130 ms 22228 KB Output is correct
8 Correct 111 ms 20884 KB Output is correct
9 Correct 95 ms 20004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -