Submission #1103687

# Submission time Handle Problem Language Result Execution time Memory
1103687 2024-10-21T14:25:12 Z Zero_OP Catfish Farm (IOI22_fish) C++17
18 / 100
71 ms 29612 KB
#include <bits/stdc++.h>
#ifndef LOCAL
    #include <fish.h>
#endif // LOCAL

using namespace std;

#define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i)
#define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)
#define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i)
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"

template<typename T>
bool minimize(T& a, const T& b){
    if(a > b) return a = b, true; return false;
}

template<typename T>
bool maximize(T& a, const T& b){
    if(a < b) return a = b, true; return false;
}

using ll = long long;
using ld = long double;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); }
template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); }

const int MAX = 3e5 + 5;

int n, m;
struct fish{
    int x, y, w;
} fishes[MAX];

namespace subtask1{
    bool check(){
        rep(i, 0, m) if(fishes[i].x& 1) return false;
        return true;
    }

    ll solve(){
        ll sum = 0;
        rep(i, 0, m){
            if((i > 0) || (i < n - 1)){
                sum += fishes[i].w;
            }
        }
        return sum;
    }
}

namespace subtask2{
    bool check(){
        for(int i = 0; i < m; ++i){
            if(fishes[i].x > 1) return false;
        }
        return true;
    }

    ll sum[3][MAX];
    ll f[3][MAX], g[3][MAX];

    ll solve(){
        memset(f, 0, sizeof(f));
        memset(g, 0, sizeof(g));

        rep(i, 0, m){
            sum[fishes[i].x][fishes[i].y] += fishes[i].w;
        }

        rep(i, 0, 2){
            rep(j, 0, n){
                sum[i][j] += (j > 0 ? sum[i][j - 1] : 0);
            }
        }

        ll ans = max(sum[0][n - 1], sum[1][n - 1]);
        if(n > 2){
            rep(i, 0, n){
                maximize(ans, sum[1][n - 1] - sum[1][i] + sum[0][i]);
            }
        }

        return ans;
    }
}

namespace subtask3{
    bool check(){
        rep(i, 0, m){
            if(fishes[i].y > 0) return false;
        }
        return true;
    }

    ll dp[MAX], s[MAX];

    ll solve(){
        rep(i, 0, m) s[fishes[i].x] = fishes[i].w;

        dp[0] = 0;
        ll res = 0;
        rep(i, 1, n){
            dp[i] = max(dp[i - 1], s[i - 1]);
            if(i >= 2) maximize(dp[i], dp[i - 2] + s[i - 1]);
            if(i >= 3) maximize(dp[i], dp[i - 3] + s[i - 2] + s[i - 1]);
            maximize(res, dp[i] + s[i + 1]);
        }

        return res;
    }
}

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
    n = N;
    m = M;
    rep(i, 0, M) fishes[i] = {X[i], Y[i], W[i]};

    if(subtask1::check()) return subtask1::solve();
    if(subtask2::check()) return subtask2::solve();
    if(subtask3::check()) return subtask3::solve();

    return -1;
}

#ifdef LOCAL
int main(){
    cout << max_weights(2, 2, {0, 0}, {0, 1}, {4, 5}) << '\n'; //sub1
    cout << max_weights(3, 2, {0, 1}, {0, 1}, {4, 5}) << '\n'; //sub2
    cout << max_weights(5, 3, {2, 4, 1}, {0, 0, 0}, {4, 5, 8}) << '\n'; //sub3
    cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
}
#endif // LOCAL

Compilation message

fish.cpp: In function 'bool minimize(T&, const T&)':
fish.cpp:18:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   18 |     if(a > b) return a = b, true; return false;
      |     ^~
fish.cpp:18:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   18 |     if(a > b) return a = b, true; return false;
      |                                   ^~~~~~
fish.cpp: In function 'bool maximize(T&, const T&)':
fish.cpp:23:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   23 |     if(a < b) return a = b, true; return false;
      |     ^~
fish.cpp:23:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   23 |     if(a < b) return a = b, true; return false;
      |                                   ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4176 KB Output is correct
2 Correct 18 ms 6748 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 62 ms 13640 KB Output is correct
6 Correct 71 ms 15468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20816 KB Output is correct
2 Correct 34 ms 28196 KB Output is correct
3 Correct 38 ms 29612 KB Output is correct
4 Correct 15 ms 5356 KB Output is correct
5 Correct 17 ms 6748 KB Output is correct
6 Correct 3 ms 20816 KB Output is correct
7 Correct 3 ms 20816 KB Output is correct
8 Correct 3 ms 20816 KB Output is correct
9 Correct 3 ms 20816 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 17 ms 23888 KB Output is correct
13 Correct 24 ms 26192 KB Output is correct
14 Correct 17 ms 22880 KB Output is correct
15 Correct 19 ms 25940 KB Output is correct
16 Correct 17 ms 23888 KB Output is correct
17 Correct 18 ms 25060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 12 ms 8788 KB Output is correct
4 Correct 8 ms 8020 KB Output is correct
5 Correct 30 ms 12620 KB Output is correct
6 Correct 16 ms 12116 KB Output is correct
7 Correct 18 ms 12628 KB Output is correct
8 Correct 22 ms 12640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 12 ms 8788 KB Output is correct
4 Correct 8 ms 8020 KB Output is correct
5 Correct 30 ms 12620 KB Output is correct
6 Correct 16 ms 12116 KB Output is correct
7 Correct 18 ms 12628 KB Output is correct
8 Correct 22 ms 12640 KB Output is correct
9 Incorrect 19 ms 8024 KB 1st lines differ - on the 1st token, expected: '99999', found: '-1'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4176 KB Output is correct
2 Correct 18 ms 6748 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 62 ms 13640 KB Output is correct
6 Correct 71 ms 15468 KB Output is correct
7 Correct 3 ms 20816 KB Output is correct
8 Correct 34 ms 28196 KB Output is correct
9 Correct 38 ms 29612 KB Output is correct
10 Correct 15 ms 5356 KB Output is correct
11 Correct 17 ms 6748 KB Output is correct
12 Correct 3 ms 20816 KB Output is correct
13 Correct 3 ms 20816 KB Output is correct
14 Correct 3 ms 20816 KB Output is correct
15 Correct 3 ms 20816 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 17 ms 23888 KB Output is correct
19 Correct 24 ms 26192 KB Output is correct
20 Correct 17 ms 22880 KB Output is correct
21 Correct 19 ms 25940 KB Output is correct
22 Correct 17 ms 23888 KB Output is correct
23 Correct 18 ms 25060 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 12 ms 8788 KB Output is correct
27 Correct 8 ms 8020 KB Output is correct
28 Correct 30 ms 12620 KB Output is correct
29 Correct 16 ms 12116 KB Output is correct
30 Correct 18 ms 12628 KB Output is correct
31 Correct 22 ms 12640 KB Output is correct
32 Incorrect 1 ms 2384 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
33 Halted 0 ms 0 KB -