이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#define local
#ifndef local
#include "biscuits.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
int rnd(int l, int r){
int temp = rng() % (r - l + 1);
return abs(temp) + l;
}
int dp[61][20005], expected[61];
long long count_tastiness(long long x, std::vector<long long> a) {
//int n, a[N];
int sum = 0;
for(int i = 0; i < a.size(); i++) sum += a[i] * (1LL << i);
if(sum <= 1e5){
int answer = 1;
for(int i = 1; i <= sum/x; i++){
int rem = 0;
for(int j = 0; j < a.size(); j++){
rem += a[j];
if((i & (1LL << j))) rem -= x;
if(rem < 0) break;
rem /= 2;
}
answer += (rem >= 0);
}
return answer;
}
else if(x <= 1e4){
for(int i = 0; i <= 20000; i++){
for(int j = 0; j <= 60; j++) dp[j][i] = 0;
}
expected[0] = a[0];
for(int i = 1; i < a.size(); i++) expected[i] = (expected[i - 1] / 2) + a[i];
dp[0][0] = 1;
if(a[0] >= x) dp[0][x] = 1;
for(int i = 0; (i + 1) < a.size(); i++){
for(int j = 0; j <= 20000; j++){
int nxt = ((expected[i] - j) / 2) + a[i + 1], actual = expected[i + 1] - nxt;
dp[i + 1][actual] += dp[i][j];
if(nxt >= x){
nxt -= x, actual += x;
dp[i + 1][actual] += dp[i][j];
}
}
}
int answer = 0;
for(int j = 0; j <= 20000; j++) answer += dp[a.size() - 1][j];
return answer;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:36:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = 0; i < a.size(); i++) sum += a[i] * (1LL << i);
| ~~^~~~~~~~~~
biscuits.cpp:41:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int j = 0; j < a.size(); j++){
| ~~^~~~~~~~~~
biscuits.cpp:56:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 1; i < a.size(); i++) expected[i] = (expected[i - 1] / 2) + a[i];
| ~~^~~~~~~~~~
biscuits.cpp:59:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i = 0; (i + 1) < 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... |