Submission #418766

#TimeUsernameProblemLanguageResultExecution timeMemory
4187662qbingxuanPacking Biscuits (IOI20_biscuits)C++14
42 / 100
1088 ms38540 KiB
#include "biscuits.h" #include <bits/stdc++.h> #ifdef local #define debug(x...) qqbx(#x, x) template <typename ...T> void qqbx(const char *s, T ...args) { int cnt = sizeof...(T); ((std::cerr << "\e[1;32m(" << s << ") = (") , ... , (std::cerr << args << (--cnt ? ", " : ")\e[0m\n"))); } #else #define debug(...) ((void)0) #endif using namespace std; const int maxn = 65; long long suf[maxn]; unordered_map<long long, long long> dp[maxn]; int cnt = 0; long long dfs(vector<long long> &a, long long x, int i, long long carry) { if (i == a.size()) { return carry / x + 1; } ++cnt; if (dp[i].count(carry)) return dp[i][carry]; long long &res = dp[i][carry]; carry += a[i]; if (carry + suf[i] < x) return res = 1; res += dfs(a, x, i+1, carry / 2); // y >> i & 1 == 0 if (carry >= x) res += dfs(a, x, i+1, (carry - x) / 2); return res; } long long count_tastiness(long long x, std::vector<long long> a) { for (int i = 0; i < a.size(); i++) dp[i].clear(); for (int i = 0; i+1 < a.size(); i++) { if (a[i] >= x) { long long diff = (a[i] - x) / 2; a[i] -= diff * 2; a[i+1] += diff; } } for (int i = 0; i < a.size(); i++) { suf[i] = 0; for (int j = i+1; j < a.size(); j++) { suf[i] += a[j] << (j - i); } } long long res = dfs(a, x, 0, 0); return res; }

Compilation message (stderr)

biscuits.cpp: In function 'long long int dfs(std::vector<long long int>&, long long int, int, long long int)':
biscuits.cpp:19:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     if (i == a.size()) {
      |         ~~^~~~~~~~~~~
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i = 0; i < a.size(); i++) dp[i].clear();
      |                     ~~^~~~~~~~~~
biscuits.cpp:36:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 0; i+1 < a.size(); i++) {
      |                     ~~~~^~~~~~~~~~
biscuits.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
biscuits.cpp:45:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int j = i+1; j < a.size(); j++) {
      |                           ~~^~~~~~~~~~
#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...