이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define all(v) v.begin(),v.end()
#define sort(v) sort(all(v))
#define endl '\n'
#define forn(i,n) for(int i = 0; i < n; ++i)
#define forbe(i,b,e) for(int i = b; i < e; ++i)
#define forr(i,n) for(int i = n-1; i >= 0; --i)
#define sz(v) ((int)v.size())
#define pb push_back
#define f first
#define s second
ll count_tastiness(ll x, vector<ll> a){
int k = sz(a);
ll ans = 0;
forn(j,k-1) {
if (a[j] < x)
continue;
ll delta = a[j]-x;
a[j] -= delta;
if (delta&1) ++a[j];
a[j+1] += (delta)/2l;
}
if (x == -1) {
vector<ll> dp(k+1, 0);
int lz = -1;
int l2 = -2;
dp[0] = 1;
ans = 1;
forn(j, k) {
if (a[j]) {
ans += dp[j];
dp[j+1] = ans;
if (a[j] > 1) l2=j;
continue;
}
if (l2 < lz) {
dp[j+1] = ans;
lz = j;
continue;
}
ans += dp[l2];
dp[j+1] = ans;
lz = j;
}
return ans;
}
int mval = 100000;
ll rem;
int t;
forbe(i,0, mval+4) {
++ans;
rem = 0;
t = 1;
forn(j, 25) {
rem = (rem/2l);
if (j < k) rem += a[j];
// cout << i << ' ' << j << ' ' << rem << endl;
if ((i&(1<<j)) == 0) continue;
// cout << i << endl;
if (rem < x) {
t = 0;
--ans;
// cout << i << endl;
break;
}
rem -= x;
}
// if (t)
// cout << i << endl;
}
return ans;
}
#ifdef ONPC
void solve() {
int k, x;
cin >> k >> x;
vector<ll> a(k);
forn(i,k)
cin >> a[i];
cout << count_tastiness(x,a) << endl;
}
int main() {
freopen("in", "r", stdin);
// ios_base::sync_with_stdio(0);cin.tie(0);
solve();
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:68:9: warning: variable 't' set but not used [-Wunused-but-set-variable]
68 | int t;
| ^
# | 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... |