Submission #675503

#TimeUsernameProblemLanguageResultExecution timeMemory
675503VodkaInTheJarPacking Biscuits (IOI20_biscuits)C++14
9 / 100
1147 ms997004 KiB
#include <bits/stdc++.h> #include <cstdio> #pragma GCC optimize("O3") #define endl '\n' using namespace std; /* unordered_map <long long, long long> dp[120]; long long f(int pos, long long pr, long long x, vector <long long> &a) { long long sum = pr; if (pos < (int)a.size()) sum += a[pos]; if (sum < x && pos >= (int)a.size()) return 1; if (dp[pos].count(pr)) return dp[pos][pr]; long long ans = f(pos + 1, sum >> 1ll, x, a); if (sum >= x) ans += f(pos + 1, (sum - x) >> 1ll, x, a); return dp[pos][pr] = ans; } */ long long count_tastiness(long long x, vector <long long> a) { // for (int i = 0; i < 120; i++) // dp[i].clear(); queue <pair <int, long long> > q; q.push({0, 0}); long long ans = 0; int sz = (int)a.size(); while (!q.empty()) { auto ver = q.front(); q.pop(); if (ver.first < sz) ver.second += a[ver.first]; if (ver.second < x && ver.first >= sz) { ans++; continue; } q.push({ver.first + 1, ver.second >> 1ll}); if (ver.second >= x) q.push({ver.first + 1, (ver.second - x) >> 1ll}); } return ans; // return f(0, 0, x, a); } /* int main() { long long x, n; cin >> x >> n; vector <long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; cout << count_tastiness(x, a) << endl; } */
#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...