답안 #436518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436518 2021-06-24T14:58:02 Z VladaMG98 사탕 분배 (IOI21_candies) C++17
0 / 100
903 ms 17280 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200010;
typedef long long ll;
const ll INF = 1e18;
ll a[MAXN];

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int q = (int)c.size();
    int n = (int)l.size();
    vector<int> answer(q);
    a[1] = INF;
    a[2] = 0;
    for (int i = 3; i <= n + 2; i++) {
        a[i] = a[i - 1] + v[i - 3];
    }
    n += 2;
    for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;     
    for (int q_i = 0; q_i < q; q_i++) {
        int C = c[q_i], ans;
        ll cur_mx = a[n], cur_mn = a[n];
        for (int i = n; i >= 1; i--) {
            cur_mx = max(cur_mx, a[i]);
            cur_mn = min(cur_mn, a[i]);
            if (cur_mx - cur_mn >= C) {
                cout << i << " " << cur_mn << " " << cur_mx << endl;
                if (a[i] == cur_mx) {
                    ans = a[n] - cur_mn;
                } else {
                    ans = C - (cur_mx - a[n]);    
                }
                break;
            }
        }
        answer[q_i] = ans;
    }
    return answer;
}

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:21:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   21 |     for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
      |     ^~~
candies.cpp:21:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   21 |     for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
      |                                                       ^~~~
candies.cpp:38:21: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |         answer[q_i] = ans;
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 903 ms 17280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -