Submission #308492

#TimeUsernameProblemLanguageResultExecution timeMemory
308492jwvg0425Packing Biscuits (IOI20_biscuits)C++17
0 / 100
1 ms384 KiB
#include "biscuits.h" #include <stdio.h> #include <vector> #include <queue> #include <algorithm> #include <iostream> #include <string> #include <bitset> #include <map> #include <set> #include <tuple> #include <string.h> #include <math.h> #include <random> #include <functional> #include <assert.h> #include <math.h> #define all(x) (x).begin(), (x).end() #define xx first #define yy second using namespace std; template<typename T, typename Pr = less<T>> using pq = priority_queue<T, vector<T>, Pr>; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; struct Solver { Solver(i64 xv, const vector<i64>& a) : k(a.size()), value(a.size()), cnt(a.size()), x(xv) { for (int i = 0; i < k; i++) value[i] = (1ll << i) * a[i]; for (int i = 1; i < k; i++) value[i] += value[i - 1]; } i64 solve() { i64 res = 1; for (int i = 0; i < k; i++) { i64 need = (1ll << i); i64 now = value[i] / x; if (now < need) continue; now -= need; if (now >= need - 1) { // 아래에서 자유롭게 선택 가능한 경우 cnt[i] = res; res *= 2; continue; } // 내려가면서, bit 위치 1인 경우 센다. int fst = -1; for (int bit = i - 1; bit >= 0; bit--) { if ((now & (1ll << bit)) == 0) continue; fst = bit; break; } if (fst != -1) cnt[i] = calc(fst, now); else cnt[i] = 1; res += cnt[i]; } return res; } i64 calc(int bit, i64 lim) { i64 res = 2; // 000..0, 100..0 for (int j = 0; j < bit; j++) res += cnt[j]; lim = lim & ((1ll << bit) - 1); i64 now = value[bit] / x; lim = min(lim, now); for (int j = bit - 1; j >= 0; j--) { if ((lim & (1ll << j)) == 0) continue; res += calc(j, lim); break; } return res; } int k; i64 x; vector<i64> value; vector<i64> cnt; }; i64 count_tastiness(i64 x, vector<i64> a) { Solver s(x, a); return s.solve(); }

Compilation message (stderr)

biscuits.cpp: In constructor 'Solver::Solver(i64, const std::vector<long long int>&)':
biscuits.cpp:109:14: warning: 'Solver::cnt' will be initialized after [-Wreorder]
  109 |  vector<i64> cnt;
      |              ^~~
biscuits.cpp:107:6: warning:   'i64 Solver::x' [-Wreorder]
  107 |  i64 x;
      |      ^
biscuits.cpp:32:2: warning:   when initialized here [-Wreorder]
   32 |  Solver(i64 xv, const vector<i64>& a)
      |  ^~~~~~
#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...