Submission #510066

# Submission time Handle Problem Language Result Execution time Memory
510066 2022-01-14T16:05:46 Z CraniXort Ice Hockey World Championship (CEOI15_bobek) C++17
100 / 100
210 ms 33424 KB
#include <bits/stdc++.h>

#define fin std::cin
#define fout std::cout

// std::ifstream fin("hockey.in");
// std::ofstream fout("hockey.out");

long long maxsum;

void compute(std::vector <long long>& v) {
    std::vector <long long> x;
    std::stack <long long> toAdd;
    x.push_back(0);

    for(auto value: v) {
        for(auto sum: x) 
            toAdd.push(value + sum);
        while(toAdd.empty() == false) {
            if(toAdd.top() <= maxsum)
                x.push_back(toAdd.top());
            toAdd.pop();
        }
    }

    std::sort(x.begin(), x.end());
    v = x;
}

void print(std::vector <long long> &v) {
    for(int i: v)
        fout << i << ' ';
    fout << '\n';
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n;

    fin >> n >> maxsum;

    std::vector <long long> a, b;
    for(long long i = 0, value; i < n / 2; i ++) {
        fin >> value;
        a.push_back(value);
    }

    for(long long i = n / 2, value; i < n; i ++){
        fin >> value;
        b.push_back(value);
    }

    compute(a);
    compute(b);

    // print(a);
    // print(b);
    long long ans = 0;
    for(int i = 0, j = b.size() - 1; i < a.size(); i ++) {
        while(j >= 0 and a[i] + b[j] > maxsum)
            j --;
        ans = ans + (j + 1);
    }

    fout << ans << '\n';


    return 0;
}

Compilation message

bobek.cpp: In function 'int main()':
bobek.cpp:61:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i = 0, j = b.size() - 1; i < a.size(); i ++) {
      |                                      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3960 KB Output is correct
2 Correct 47 ms 8580 KB Output is correct
3 Correct 210 ms 33412 KB Output is correct
4 Correct 51 ms 8584 KB Output is correct
5 Correct 6 ms 2248 KB Output is correct
6 Correct 5 ms 1352 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 4416 KB Output is correct
2 Correct 18 ms 3956 KB Output is correct
3 Correct 74 ms 16856 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 3 ms 1360 KB Output is correct
6 Correct 11 ms 2268 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7516 KB Output is correct
2 Correct 72 ms 14720 KB Output is correct
3 Correct 72 ms 14804 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 35 ms 14812 KB Output is correct
6 Correct 155 ms 33412 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 29308 KB Output is correct
2 Correct 16 ms 3900 KB Output is correct
3 Correct 5 ms 1332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 4 ms 1352 KB Output is correct
6 Correct 150 ms 29316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3956 KB Output is correct
2 Correct 48 ms 8584 KB Output is correct
3 Correct 6 ms 1352 KB Output is correct
4 Correct 6 ms 1352 KB Output is correct
5 Correct 53 ms 14768 KB Output is correct
6 Correct 16 ms 3964 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 33408 KB Output is correct
2 Correct 17 ms 3928 KB Output is correct
3 Correct 6 ms 1356 KB Output is correct
4 Correct 204 ms 33424 KB Output is correct
5 Correct 52 ms 16812 KB Output is correct
6 Correct 13 ms 2372 KB Output is correct
7 Correct 0 ms 204 KB Output is correct