Submission #306253

# Submission time Handle Problem Language Result Execution time Memory
306253 2020-09-25T03:35:07 Z qpwoeirut Packing Biscuits (IOI20_biscuits) C++17
9 / 100
1000 ms 384 KB
#include "biscuits.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll sub2(ll x, vector<ll> a) {
    //cerr << "a: "; for (int i=0; i<a.size(); ++i) cerr << a[i] << ' '; cerr << endl;

    ll ans = 1;
    for (int i=0; i<a.size(); ++i) {
        if (a[i] >= x) ans <<= 1;
    }
    //cerr << "base: " << ans << endl;

    int cur = 0;
    for (int i=0; i<a.size(); ++i) {
        if (a[i] > x) {
            ++cur;
            a[i+1] += a[i] >> 1;
            a[i] = 0;
        }
        else {
            if (cur > 0) {
                ans += ans >> cur;
            }
            cur = 0;
        }
    }

	return ans;
}

long long count_tastiness(long long x, std::vector<long long> a) {
    a.resize(128, 0);
    //cerr << "a: "; for (int i=0; i<a.size(); ++i) cerr << a[i] << ' '; cerr << endl;
    int add = 0;
    for (int i=0; i<a.size(); ++i) {
        a[i] += add;
        add = max(0LL, (a[i] - x) >> 1);
        a[i] -= add << 1;
    }

    ll ans = 0;
    for (int y=0; y<=100000; ++y) {
        ll carry = 0;
        bool ok = true;
        for (int i=0; i<62; ++i) {
            ll cur = a[i] + carry;
            if (y & (1LL << i)) {
                if (cur < x) {
                    ok = false;
                    break;
                }
                cur -= x;
            }
            carry = cur >> 1;
        }
        if (ok) {
            ++ans;
            //cerr << "y: " << y << '\n';
        }
    }
    
    return ans;
}

/*
2
3 3
5 2 1
3 2
2 1 2

1
5 1
0 1 1 1 2

1
4 1
1 5 2 9

1
5 1
0 0 0 1 0

1
1 1
128
*/

Compilation message

biscuits.cpp: In function 'll sub2(ll, std::vector<long long int>)':
biscuits.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i=0; i<a.size(); ++i) {
      |                   ~^~~~~~~~~
biscuits.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i=0; i<a.size(); ++i) {
      |                   ~^~~~~~~~~
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i=0; i<a.size(); ++i) {
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 27 ms 256 KB Output is correct
4 Correct 68 ms 356 KB Output is correct
5 Correct 45 ms 256 KB Output is correct
6 Correct 82 ms 256 KB Output is correct
7 Correct 44 ms 256 KB Output is correct
8 Correct 80 ms 376 KB Output is correct
9 Correct 55 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 53 ms 256 KB Output is correct
13 Correct 49 ms 256 KB Output is correct
14 Correct 26 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 384 KB Output is correct
2 Incorrect 52 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 27 ms 256 KB Output is correct
4 Correct 68 ms 356 KB Output is correct
5 Correct 45 ms 256 KB Output is correct
6 Correct 82 ms 256 KB Output is correct
7 Correct 44 ms 256 KB Output is correct
8 Correct 80 ms 376 KB Output is correct
9 Correct 55 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 53 ms 256 KB Output is correct
13 Correct 49 ms 256 KB Output is correct
14 Correct 26 ms 256 KB Output is correct
15 Correct 23 ms 384 KB Output is correct
16 Incorrect 52 ms 256 KB Output isn't correct
17 Halted 0 ms 0 KB -