Submission #696314

# Submission time Handle Problem Language Result Execution time Memory
696314 2023-02-06T08:08:48 Z garam1732 Packing Biscuits (IOI20_biscuits) C++14
0 / 100
20 ms 1212 KB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll dp[100];

ll solve(ll x, vector<ll> a, bool full) {
    if(a.empty()) return dp[0] = 1;
    ll z = *a.rbegin(); int sz = a.size();
    a.pop_back();

    if(full && dp[sz]) return dp[sz];

    ll q = z/x, res = 0;
    res += (q+1)*solve(x, a, 1);

    if(z % x) {
        ll v = (x-z%x)*(1<<(sz-1));
        for(int i = (int)a.size()-1; i >= 0; i--) {
            if(v == 0) break;
            else if(v >= a[i]*(1<<i)) {
                v -= a[i]*(1<<i);
                a.pop_back();
            }
            else {
                a[i] -= v/(1<<i);
                break;
            }
        }

        if(v == 0) res += solve(x, a, 0);
    }

    if(full) dp[sz] = res;
    return res;
}

long long count_tastiness(long long x, std::vector<long long> a) {
	for(int i = 0; i < a.size(); i++) {
        dp[i] = 0;
        for(int j = i+1; j < a.size(); j++) {
            if(a[i]/x >= (1<<(j-i))-1) {
                a[i] += a[j]*(1<<(j-i));
                a[j] = 0;
            }
        }
	}

	return solve(x, a, 0);
}

Compilation message

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(int i = 0; i < a.size(); i++) {
      |                 ~~^~~~~~~~~~
biscuits.cpp:42:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int j = i+1; j < a.size(); j++) {
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Incorrect 20 ms 1212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -