Submission #1052472

#TimeUsernameProblemLanguageResultExecution timeMemory
1052472mychecksedadPacking Biscuits (IOI20_biscuits)C++17
42 / 100
1059 ms37792 KiB
#include "biscuits.h" #include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long int #define all(x) x.begin(),x.end() #define vi vector<int> #define pii pair<int,int> #define ff first #define ss second long long count_tastiness(long long x, std::vector<long long> a) { // if(x > 1000000) return 1; a.resize(63); vector<vector<pair<ll, ll>>> dp(63); for(int i = 0; i + 1 < a.size(); ++i){ if(a[i] > x){ ll dif = (a[i] - x) / 2; a[i + 1] += dif; a[i] -= dif * 2; } } ll k = a.size(); if(x == 1){ vector<vector<int>> v; for(int i = 0; i < k; ++i){ if(a[i] >= 1){ if(i == 0 || a[i - 1] == 0) v.pb({a[i]}); else v.back().pb(a[i]); } } ll ans = 1; for(auto u: v){ ll x = 1; for(int i = u.size() - 1; i >= 0; --i){ x *= 2; if(u[i] == 2) x += 1; } ans *= x; } return ans; } dp[0].pb({0, 1}); for(int i = 0; i < k - 1; ++i){ vector<pair<ll, ll>> DP; for(auto j: dp[i]){ DP.pb({j.ff + a[i] >> 1, j.ss}); // dp[i + 1][(j.ff + a[i]) >> 1] += j.ss; if(j.ff + a[i] >= x){ DP.pb({j.ff + a[i] - x >> 1, j.ss}); } // dp[i + 1][(j.ff + a[i] - x) >> 1] += j.ss; // cout << dp[i][j] << ' '; } sort(all(DP)); for(int j = 0; j < DP.size(); ++j){ if(j == 0) dp[i + 1].pb({DP[j].ff, DP[j].ss}); else{ if(DP[j].ff == DP[j - 1].ff) dp[i + 1].back().ss += DP[j].ss; else dp[i + 1].pb(DP[j]); } } // cout << '\n'; } ll ans = 0; for(auto j: dp[k - 1]) ans += j.ss; return ans; }

Compilation message (stderr)

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i = 0; i + 1 < a.size(); ++i){
      |                 ~~~~~~^~~~~~~~~~
biscuits.cpp:29:44: warning: narrowing conversion of 'a.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   29 |     if(i == 0 || a[i - 1] == 0) v.pb({a[i]});
      |                                            ^
biscuits.cpp:29:44: warning: narrowing conversion of 'a.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
biscuits.cpp:48:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |    DP.pb({j.ff + a[i] >> 1, j.ss});
biscuits.cpp:51:24: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   51 |     DP.pb({j.ff + a[i] - x >> 1, j.ss});
      |            ~~~~~~~~~~~~^~~
biscuits.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int j = 0; j < DP.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...