답안 #304000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304000 2020-09-20T23:42:20 Z Fdg 비스킷 담기 (IOI20_biscuits) C++14
100 / 100
170 ms 1016 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

vector<long long> trans(const vector<long long>& a, long long sub) {
  vector<long long> na = a;
  na.pop_back();
  if (a.back() - sub > 1) {
    long long val = (a.back() - sub) / 2;
    if (na.size() == 0) na.push_back(val);
    else na.back() += val;
  }
  return na;
}

map<pair<int, long long>, long long> f;

long long solve(long long x, vector<long long> a, int pos) {
  if (a.size() == 0) return 1;
  if (f.count({pos, a.back()})) return f[{pos, a.back()}];

  long long ret = 0;
  if (a.back() >= x) {
    ret += solve(x, trans(a, x), pos + 1);
  }

  ret += solve(x, trans(a, 0), pos + 1);
  return f[{pos, a.back()}] = ret;
}

vector<long long> arr;

long long solve2(long long x, long long last, int pos) {
  if ((int) arr.size() <= pos && last < x) return 1;
  if (f.count({pos, last})) return f[{pos, last}];

  long long ret = 0;
  if (last >= x) {
    long long nlast = (pos + 1 < (int) arr.size() ? arr[pos + 1] : 0) + (last - x) / 2;
    ret += solve2(x, nlast, pos + 1);
  }

  long long nlast = (pos + 1 < (int) arr.size() ? arr[pos + 1] : 0) + last / 2;
  ret += solve2(x, nlast, pos + 1);
  return f[{pos, last}] = ret;
}

vector<long long> sums;

long long solve3(long long x, int pos, long long sub) {
  if (pos == -1) return sub == 0;
  if (f.count({pos, sub})) return f[{pos, sub}];

  long long cur = pos < (int) arr.size() ? arr[pos] : 0;

  long long ret = 0;
  if ((1LL << pos) <= (sums[pos] - sub) / x) {
    long long what = solve3(x, pos - 1, max(0LL, sub + x * (1LL << pos) - (1LL << pos) * cur));
    ret += what;
    if (what == (1LL << pos)) {
      ret += what;
      return f[{pos, sub}] = ret;
    }
  }

  ret += solve3(x, pos - 1, max(0LL, sub - (1LL << pos) * cur));

  return f[{pos, sub}] = ret;
}

long long count_tastiness(long long x, vector<long long> a) {
  f.clear(); sums.clear();

  // for (int i = 0; i < (int) a.size(); ++i) {
  //   if (a[i] > x) {
  //     long long add = (a[i] - x) / 2;
  //     a[i] = x + ((a[i] - x) & 1);
  //     if (i + 1 == (int) a.size())
  //       a.push_back(add);
  //     else
  //       a[i + 1] += add;
  //   }
  // }

  long long s = 0, pw = 1;
  for (int i = 0; i < 60; ++i) {
    if (i < (int) a.size())
      s += pw * a[i];
    pw <<= 1;
    sums.push_back(s);
  }

  // reverse(a.begin(), a.end());
  arr = a;
  // return solve2(x, arr[0], 0);
  // cout << "2: " << solve2(x, arr[0], 0) << endl;
  return solve3(x, 59, 0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 54 ms 896 KB Output is correct
3 Correct 52 ms 896 KB Output is correct
4 Correct 50 ms 896 KB Output is correct
5 Correct 47 ms 912 KB Output is correct
6 Correct 70 ms 896 KB Output is correct
7 Correct 68 ms 896 KB Output is correct
8 Correct 61 ms 896 KB Output is correct
9 Correct 59 ms 1016 KB Output is correct
10 Correct 35 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 16 ms 384 KB Output is correct
38 Correct 54 ms 896 KB Output is correct
39 Correct 52 ms 896 KB Output is correct
40 Correct 50 ms 896 KB Output is correct
41 Correct 47 ms 912 KB Output is correct
42 Correct 70 ms 896 KB Output is correct
43 Correct 68 ms 896 KB Output is correct
44 Correct 61 ms 896 KB Output is correct
45 Correct 59 ms 1016 KB Output is correct
46 Correct 35 ms 896 KB Output is correct
47 Correct 38 ms 384 KB Output is correct
48 Correct 170 ms 972 KB Output is correct
49 Correct 99 ms 504 KB Output is correct
50 Correct 157 ms 768 KB Output is correct
51 Correct 18 ms 896 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 16 ms 768 KB Output is correct
54 Correct 158 ms 896 KB Output is correct
55 Correct 157 ms 1016 KB Output is correct
56 Correct 143 ms 896 KB Output is correct
57 Correct 121 ms 896 KB Output is correct