이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 100;
const ll inf = 2e18;
ll dp[maxn][2];
long long count_tastiness(long long x, std::vector<long long> a) {
dp[0][0] = dp[0][1] = 1;
for (int i = 1; i <= a.size(); i++){
dp[i][0] = dp[i][1] = 0;
ll tmp = (x-a[i-1]) % x;
dp[i][0] = (dp[i-1][1]) * ((a[i-1]+x-1) / x);
ll idx = i-1;
while(idx > 0){
tmp *= 2;
tmp = min(tmp, inf);
//debug(dp[i][0], idx, a[idx-1], tmp);
if (a[idx-1] < tmp){
tmp -= a[idx-1];
idx--;
continue;
}
dp[i][0] += (dp[idx-1][1]) * ((a[idx-1]-tmp+x-1) / x);
tmp = (x-a[idx-1]-tmp) % x;
idx--;
}
if (tmp == 0) dp[i][0]++;
//debug(i, dp[i][0]);
if (i == a.size()) break;
tmp = 0;
idx = i;
ll lim = x+1;
bool ok = true;
while(idx > 0){
//debug(idx);
tmp *= 2;
tmp = min(tmp, inf);
if ((lim-1) < a[idx-1]){
if (tmp > (lim-1)){
ok = false;
break;
}
dp[i][1] += (dp[idx-1][1]) * (((lim-1)-tmp+x-1) / x);
break;
}
if (a[idx-1] < tmp){
tmp -= a[idx-1];
lim -= a[idx-1];
lim *= 2;
lim = min(lim, inf);
idx--;
continue;
}
dp[i][1] += (dp[idx-1][1]) * ((a[idx-1]-tmp+x-1) / x);
tmp = (x-a[idx-1]-tmp) % x;
lim -= a[idx-1];
lim *= 2;
lim = min(lim, inf);
idx--;
}
if (ok && tmp == 0) dp[i][1]++;
//debug(i, dp[i][1]);
}
//debug(a.size(), dp[a.size()][0]);
return dp[a.size()][0];
}
컴파일 시 표준 에러 (stderr) 메시지
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 1; i <= a.size(); i++){
| ~~^~~~~~~~~~~
biscuits.cpp:50:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | if (i == a.size()) break;
| ~~^~~~~~~~~~~
# | 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... |