Submission #784005

# Submission time Handle Problem Language Result Execution time Memory
784005 2023-07-15T14:17:20 Z SoulKnight Catfish Farm (IOI22_fish) C++17
6 / 100
127 ms 15568 KB
#include "fish.h"

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ln '\n'


long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {

    if (N <= 2){
        ll r1, r2; r1 = r2 = 0LL;

        for (int i = 0; i < M; i++){
            if (X[i] == 1) r2 += W[i];
            else r1 += W[i];
        }

        return max(r1, r2);
    } else {
        ll r0, r1; r0 = r1 = 0LL;

        vector<array<ll, 2>> vec0, vec1;

        for (int i = 0; i < M; i++){
            if (X[i] == 0) {vec0.push_back({Y[i], W[i]}); r0 += W[i];}
            else {vec1.push_back({Y[i], W[i]}); r1 += W[i];}
        }

        if (vec0.empty()) {return r1;}
        if (vec1.empty()) {return r0;}

        sort(vec0.begin(), vec0.end());
        sort(vec1.begin(), vec1.end());

        for (int i = 1; i < vec0.size(); i++) vec0[i][1] += vec0[i-1][1];
        for (int i = 1; i < vec1.size(); i++) vec1[i][1] += vec1[i-1][1];


        ll ans = r1;
        array<ll, 2> t;

        for (auto& p: vec0){
            // cout << p[0] << ' ' << p[1] << ln;
            t = {p[0], -1};
            int idx = lower_bound(vec1.begin(), vec1.end(), t) - vec1.begin();
            if (idx == vec1.size()) {ans = max(ans, p[1]); continue;}

            if (vec1[idx][0] > p[0]) idx--;
            ll tmp = r1;
            if (idx >= 0) tmp -= vec1[idx][1];

            ans = max(ans, tmp + p[1]);
        }

        return ans;
    }

}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 1; i < vec0.size(); i++) vec0[i][1] += vec0[i-1][1];
      |                         ~~^~~~~~~~~~~~~
fish.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int i = 1; i < vec1.size(); i++) vec1[i][1] += vec1[i-1][1];
      |                         ~~^~~~~~~~~~~~~
fish.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             if (idx == vec1.size()) {ans = max(ans, p[1]); continue;}
      |                 ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4296 KB Output is correct
2 Correct 24 ms 4800 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 82 ms 15568 KB Output is correct
6 Incorrect 127 ms 15568 KB 1st lines differ - on the 1st token, expected: '300000000000000', found: '299997000000000'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 58 ms 7244 KB Output is correct
3 Correct 71 ms 11816 KB Output is correct
4 Correct 20 ms 5700 KB Output is correct
5 Correct 23 ms 6572 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 19 ms 5792 KB Output is correct
13 Correct 24 ms 6556 KB Output is correct
14 Correct 27 ms 5228 KB Output is correct
15 Correct 31 ms 5704 KB Output is correct
16 Correct 27 ms 5332 KB Output is correct
17 Correct 30 ms 5696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 18 ms 2636 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722970317066'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '310912587092'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '310912587092'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '310912587092'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 18 ms 2636 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26722970317066'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4296 KB Output is correct
2 Correct 24 ms 4800 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 82 ms 15568 KB Output is correct
6 Incorrect 127 ms 15568 KB 1st lines differ - on the 1st token, expected: '300000000000000', found: '299997000000000'
7 Halted 0 ms 0 KB -