Submission #625563

# Submission time Handle Problem Language Result Execution time Memory
625563 2022-08-10T14:57:18 Z clams Catfish Farm (IOI22_fish) C++17
3 / 100
88 ms 7268 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    bool issub1 = 1;
    for (int i = 0; i < m; i++) {
        if (x[i] & 1) {
            issub1 = 0;
            break;
        }
    }

    if (issub1) {
        // just sum up every thing
        ll ans = accumulate(w.begin(), w.end(), 0LL);
        return ans;
    }

    bool issub2 = 1;
    for (int i = 0; i < m; i++) {
        if (x[i] > 1) {
            issub2 = 0;
            break;
        }
    }

    if (issub2) {
        // there is only two columns, BUT be careful since n can be > 2
        if (n == 1) {
            // you can't choose anything
            return 0;
        }

        if (n == 2) {
            // only two columns
            vector<ll> col(2);
            for (int i = 0; i < m; i++) {
                col[x[i]] += w[i];
            }

            return max(col[0], col[1]);
        }

        // prefix of col[0] and suffix of col[1]

        // 2 pointer
        vector<vector<pair<int, int>>> v(2);
        for (int i = 0; i < m; i++) {
            v[x[i]].push_back({y[i], w[i]});
        }

        for (int j = 0; j < 2; j++) {
            sort(v[j].begin(), v[j].end());
        }

        ll all2 = 0;
        for (auto i : v[1]) all2 += i.second;

        ll all1 = 0;
        for (auto i : v[0]) all1 += i.second;

        ll ans = all1;
        int j = 0;
        ll cur1 = 0;
        while (j < v[0].size() && v[0][j].first <= v[1][0].first) {
            cur1 += v[0][j].second;
            j++;
        }
        ans = max(ans, cur1 + all2);
        for (int i = 0; i < v[1].size(); i++) {
            all2 -= v[1][i].second;
            while (j < v[0].size() && v[0][j].first <= v[1][i].first) {
                cur1 += v[0][j].second;
                j++;
            }
            ans = max(ans, all2 + cur1);
        }

        return ans;
    }

    return 0;
}

//int main() {
//    int tmp = 2e9;
////    cout << max_weights(5, 4, {1, 0, 1, 0}, {2, 1, 4, 3}, {tmp, tmp, tmp, tmp}) << '\n';
////    cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
//    cout << max_weights(2, 4, {1, 0, 1, 0}, {2, 1, 4, 3}, {tmp, tmp, tmp, tmp}) << '\n';
//    cout << max_weights(1, 4, {0, 0, 0, 0}, {2, 1, 4, 3}, {tmp, tmp, tmp, tmp}) << '\n';
//    cout << max_weights(3, 4, {1, 0, 1, 0}, {2, 1, 4, 3}, {0, 0, tmp, tmp}) << '\n';
//    cout << max_weights(3, 2, {0, 1}, {1, 2}, {1, 1}) << '\n';
//}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while (j < v[0].size() && v[0][j].first <= v[1][0].first) {
      |                ~~^~~~~~~~~~~~~
fish.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < v[1].size(); i++) {
      |                         ~~^~~~~~~~~~~~~
fish.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             while (j < v[0].size() && v[0][j].first <= v[1][i].first) {
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2140 KB Output is correct
2 Correct 25 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 81 ms 7268 KB Output is correct
6 Correct 88 ms 7268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 56 ms 5736 KB Output is correct
3 Correct 76 ms 6728 KB Output is correct
4 Correct 21 ms 2144 KB Output is correct
5 Correct 31 ms 2644 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 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 29 ms 3300 KB Output is correct
13 Correct 37 ms 3784 KB Output is correct
14 Correct 31 ms 3080 KB Output is correct
15 Correct 32 ms 3408 KB Output is correct
16 Correct 28 ms 3176 KB Output is correct
17 Incorrect 31 ms 3404 KB 1st lines differ - on the 1st token, expected: '45076987066882', found: '45077310326876'
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2140 KB Output is correct
2 Correct 25 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 81 ms 7268 KB Output is correct
6 Correct 88 ms 7268 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 56 ms 5736 KB Output is correct
9 Correct 76 ms 6728 KB Output is correct
10 Correct 21 ms 2144 KB Output is correct
11 Correct 31 ms 2644 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 29 ms 3300 KB Output is correct
19 Correct 37 ms 3784 KB Output is correct
20 Correct 31 ms 3080 KB Output is correct
21 Correct 32 ms 3408 KB Output is correct
22 Correct 28 ms 3176 KB Output is correct
23 Incorrect 31 ms 3404 KB 1st lines differ - on the 1st token, expected: '45076987066882', found: '45077310326876'
24 Halted 0 ms 0 KB -