Submission #408726

#TimeUsernameProblemLanguageResultExecution timeMemory
408726priority_queuePacking Biscuits (IOI20_biscuits)C++14
9 / 100
1088 ms376 KiB
#include <bits/stdc++.h> #define forint(i, N) for (long long i = 0; i < (N); i++) using namespace std; void takeout(vector<long long>& a, long long pos, long long val) { // cerr << "out " << val << " from " << pos << endl; if (a[pos] * (1ll << pos) < val) { takeout(a, pos-1, val - a[pos] * (1ll << pos)); a[pos] = 0; return; } long long v = val / (1ll << pos); a[pos] -= v; if (v * (1ll << pos) < val) { takeout(a, pos-1, val - v * (1ll << pos)); } } long long count(long long x, vector<long long>& a, long long max_y) { /* cerr << "max_y = " << max_y << endl; for (auto aa : a) { cerr << aa << " "; } cerr << endl; */ if (max_y == 0) { return 1; } if (max_y == 1) { if (a[0] >= x) { return 2; // 0 & 1; } else { return 1; // 0 only } } long long k = a.size(); vector<long long> sum(61, 0); sum[0] = a[0]; for (long long i = 1; i < k; i++) { sum[i] = sum[i - 1] + a[i] * (1ll << i); //cerr << "sum i=" << sum[i] << " " << endl; } for (long long i = k; i < 61; i++) { sum[i] = sum[i-1]; //cerr << "sum i=" << sum[i] << " " << endl; } // find i long long i = 0; while ((1ll << i) < max_y) { i++; } if (max_y == (1ll << i)) { if (sum[i] / x >= max_y) { return count(x, a, max_y - 1) + 1; } else { return count(x, a, max_y - 1); } } long long aa = count(x, a, 1ll << (i-1)); //cerr << "omg: " << aa << endl; if (sum[i-1] / (1ll << (i-1)) < x ) { // sum[i-1] >> (i-1) //cerr << "a" << endl; return aa; } else { //cerr << "b" << endl; vector<long long> b; forint(j, k) { if ((1ll << j) <= max_y) { b.push_back(a[j]); } else { break; } } /* cerr << "take out " << (1ll << (i-1)) * x << " from " << i-1 << endl; for(auto bb:b) { cerr << bb << ":"; } cerr << endl; */ //takeout(b, b.size()-1, (1ll << (i-1)) * x); /* long long amount = x; int pos = i-1; while (pos > (b.size()-1)) { pos--; amount *= 2; } while (amount > 0) { if (amount <= b[pos]) { b[pos] -= amount; amount = 0; } else { amount = (amount - b[pos])*2; b[pos] = 0; } } */ long long amount = x; //cout << "hey " << i-1 << " " << sum[i-1] << " " << (1ll << (i-1)) << " " << x << endl; for (long long j = i-1; j >=0; j--) { //cerr << j << ";" << amount << "*" << b[j] << endl; if (j < b.size() && amount <= b[j]) { b[j] -= amount; amount = 0; break; } else { if (j < b.size()) { amount = (amount - b[j]) * 2; b[j] = 0; } else { amount *= 2; } } //cerr << b[j] << "___"; } /* cerr << endl; for(auto bb:b) { cerr << bb << ":"; } cerr << endl; */ return aa + count(x, b, max_y - (1ll << (i-1))) - 1; // 0 has been counted } } long long count_tastiness(long long x, vector<long long> a) { return count(x, a, 1e18); //return count(x, a, 15); }

Compilation message (stderr)

biscuits.cpp: In function 'long long int count(long long int, std::vector<long long int>&, long long int)':
biscuits.cpp:127:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |    if (j < b.size() && amount <= b[j]) {
      |        ~~^~~~~~~~~~
biscuits.cpp:133:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     if (j < b.size()) {
      |         ~~^~~~~~~~~~
#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...