Submission #625558

# Submission time Handle Problem Language Result Execution time Memory
625558 2022-08-10T14:51:48 Z clams Catfish Farm (IOI22_fish) C++17
3 / 100
85 ms 7284 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 ans = all2;
        int j = 0;
        ll cur1 = 0;
        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';
//
//}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:64: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]
   64 |         for (int i = 0; i < v[1].size(); i++) {
      |                         ~~^~~~~~~~~~~~~
fish.cpp:66: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]
   66 |             while (j < v[0].size() && v[0][j].first <= v[1][i].first) {
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2124 KB Output is correct
2 Correct 27 ms 2636 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 84 ms 7284 KB Output is correct
6 Correct 85 ms 7264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
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 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 26 ms 2124 KB Output is correct
2 Correct 27 ms 2636 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 84 ms 7284 KB Output is correct
6 Correct 85 ms 7264 KB Output is correct
7 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
8 Halted 0 ms 0 KB -