제출 #1054997

#제출 시각아이디문제언어결과실행 시간메모리
1054997dozer비스킷 담기 (IOI20_biscuits)C++14
35 / 100
26 ms1340 KiB
#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 127 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 < (int)a.size(); i++){ if (a[i] > x + 1){ if (i < n - 1) a[i + 1] += (a[i] - x) / 2; else a.pb((a[i] - x) / 2); a[i] = a[i] - ((a[i] - x) / 2) * 2; } } while(a.size() < N) a.pb(0); int m = a.size(); vector<__int128_t> pre(m); vector<__int128_t> pw(m, 1); for (int i = 1; i < m; i++) pw[i] = pw[i - 1] * 2; pre[0] = a[0]; for (int i = 1; i < m; i++){ pre[i] = pre[i - 1] + (__int128_t)a[i] * pw[i]; } vector<__int128_t> maks(m); vector<ll> dp(m, 0); for (int i = 0; i < m; i++) { maks[i] = floorl((pre[i] / x) + 1); } for (int i = 0; i < m; i++){ dp[i] = 0; if (i == 0){ dp[i] = (ll)maks[i]; continue; } __int128_t tmp = maks[i]; for (int j = i - 1; j >= 0; j--){ if (tmp >= pw[j + 1]){ dp[i] += dp[j]; tmp -= pw[j + 1]; } if (tmp >= maks[j]){ dp[i] += dp[j]; tmp = 0; break; } } dp[i] += tmp; } 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; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...