이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "biscuits.h"
#include<bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define pb push_back
#define ll long long
#define LL node * 2
#define RR node * 2 + 1
#define N 65
const int modulo = 1e9 + 7;
const ll M = 1e18;
long long count_tastiness(long long x, vector<long long> a) {
int n = a.size();
for (int i = 0; i < a.size(); i++){
if (a[i] > x){
if (i < n - 1) a[i + 1] += (a[i] - x) / 2;
else a.pb((a[i] - x) / 2);
a[i] = x;
}
}
int m = a.size();
vector<ll> pre1(m), pre2(m);
pre1[0] = a[0] / x, pre2[0] = a[0] % x;
for (int i = 1; i < m; i++){
ll b = a[i] % x, c = a[i] / x;
for (int j = 0; j < i; j++){
c *= 2;
b *= 2;
c += b / x;
b %= x;
}
pre2[i] = pre2[i - 1] + b;
pre1[i] = pre1[i - 1] + pre2[i] / x + c;
pre2[i] %= x;
}
vector<ll> maks(m), dp(m, 0);
for (int i = 0; i < m; i++) maks[i] = pre1[i] + 1;
for (int i = 0; i < m; i++){
dp[i] = 0;
for (int j = i - 1; j >= 0; j--){
if (maks[i] >= (1LL<<(j + 1))) { //how do you know it will fit in a long long??
dp[i] += dp[j];
maks[i] -= (1LL<<(j + 1));
}
}
dp[i] += maks[i];
}
return dp[m - 1];
}
/*
int main() {
fileio();
int q;
assert(scanf("%d", &q) == 1);
vector<int> k(q);
vector<long long> x(q);
vector<vector<long long>> a(q);
vector<long long> results(q);
for (int t = 0; t < q; t++) {
assert(scanf("%d%lld", &k[t], &x[t]) == 2);
a[t] = vector<long long>(k[t]);
for (int i = 0; i < k[t]; i++) {
assert(scanf("%lld", &a[t][i]) == 1);
}
}
fclose(stdin);
for (int t = 0; t < q; t++) {
results[t] = count_tastiness(x[t], a[t]);
}
for (int t = 0; t < q; t++) {
printf("%lld\n", results[t]);
}
fclose(stdout);
return 0;
}
*/
컴파일 시 표준 에러 (stderr) 메시지
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int i = 0; i < a.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |