Submission #1033477

#TimeUsernameProblemLanguageResultExecution timeMemory
1033477ZicrusPacking Biscuits (IOI20_biscuits)C++17
42 / 100
1094 ms29276 KiB
#include <bits/stdc++.h>
#include "biscuits.h"
using namespace std;

typedef long long ll;

ll sub3(ll x, vector<ll> a) {
    ll n = a.size();
    ll m = 6*x;
    vector<vector<ll>> dp(n, vector<ll>(m));
    for (int i = 0; i < m; i++) {
        dp.back()[i] = i/x + 1;
    }
 
    for (int i = n-2; i >= 0; i--) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = dp[i+1][a[i+1] + j/2];
            if (j >= x) {
                dp[i][j] += dp[i+1][a[i+1] + (j-x)/2];
            }
        }
    }
 
    return dp[0][a[0]];
}

vector<map<ll, ll>> dp;

ll numWays(const ll &n, const ll &m, const ll &mxN, const ll &x, const vector<ll> &a) {
    if (n == mxN) return m/x + 1;
    if (dp[n][m]) return dp[n][m];

    ll res = numWays(n+1, a[n+1] + m/2, mxN, x, a);
    if (m >= x) {
        res += numWays(n+1, a[n+1] + (m-x)/2, mxN, x, a);
    }

    return dp[n][m] = res;
}

ll count_tastiness(ll x, vector<ll> a) {
    for (int i = 0; i < a.size(); i++) {
        ll transfer = max(0ll, (a[i]-x) / (2*x));
        if (transfer > 0) {
            if (i+1 >= a.size()) a.push_back(x*transfer);
            else a[i+1] += x*transfer;
            a[i] -= 2*x*transfer;
        }
    }

    if (x <= 10000) return sub3(x, a);

    ll n = a.size();
    dp = vector<map<ll, ll>>(n-1);
    ll res = numWays(0, a[0], n-1, x, a);
    return res;
}

Compilation message (stderr)

biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:42:23: 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 i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
biscuits.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             if (i+1 >= a.size()) a.push_back(x*transfer);
      |                 ~~~~^~~~~~~~~~~
#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...