Submission #660844

# Submission time Handle Problem Language Result Execution time Memory
660844 2022-11-23T10:16:54 Z mychecksedad Catfish Farm (IOI22_fish) C++17
18 / 100
87 ms 7312 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int S = 1e5 + 100;


ll dp[S][2], a[S][2], suf[S];
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w){  
    bool case1 = 1, case2 = 1, case3 = 1;
    for(int i = 0; i < m; ++i){
        if(x[i] % 2) case1 = 0;
        if(x[i] > 1) case2 = 0;
        if(y[i] != 0) case3 = 0;
    }
    if(case1){
        ll ans = 0;
        for(int i = 0; i < m; ++i) ans += w[i];
        return ans;
    }
    if(case2){
        ll ans1 = 0, ans2 = 0;

        for(int i = 0; i < m; ++i){
            if(x[i] == 0) ans1 += w[i];
            else ans2 += w[i];
        }
        if(n == 2)
            return max(ans1, ans2);
        else{
            ll best = 0, sum = 0;
            int p = 0;
            for(int i = 0; i <= n + 1; ++i) a[i][0] = a[i][1] = suf[i] = 0;
            for(int i = 0; i < m; i++) if(x[i] == 0) a[y[i]][0] = w[i]; else a[y[i]][1] = w[i];

            for(int i = n; i >= 0; --i) suf[i] = suf[i + 1] + a[i][1];

            for(int i = 0; i <= n + 1; ++i){
                best = max(best, suf[i] + sum);
                sum += a[i][0];
            }

            return best;
        }
    }
    if(case3){
        for(int i = 0; i <= n; ++i){
            dp[i][0] = dp[i][1] = 0;
        }
        vector<ll> v(S); 
        for(int i = 0; i < m; ++i) v[x[i]] = w[i];
        for(int i = 1; i <= n; ++i){
            dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + v[i]);
            if(i>=3)
                dp[i][1] = max({dp[i - 1][1], dp[i - 2][1] + v[i - 1], dp[i - 3][1] + v[i - 2] + v[i - 1]});
            else if(i==2)
                dp[i][1] = max({dp[i - 1][1], dp[i - 2][1] + v[i - 1], dp[i - 2][0] + v[i - 1]});
            else
                dp[i][1] = max({dp[i - 1][1], dp[i - 1][0] + v[i - 1]});
        }
        return dp[n][0];
    }
    return -1;
}   

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:32:17: warning: unused variable 'p' [-Wunused-variable]
   32 |             int p = 0;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2124 KB Output is correct
2 Correct 26 ms 2640 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 87 ms 7280 KB Output is correct
6 Correct 76 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 44 ms 6184 KB Output is correct
3 Correct 55 ms 7312 KB Output is correct
4 Correct 23 ms 2160 KB Output is correct
5 Correct 26 ms 2632 KB Output is correct
6 Correct 1 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 21 ms 4352 KB Output is correct
13 Correct 26 ms 4956 KB Output is correct
14 Correct 25 ms 4216 KB Output is correct
15 Correct 26 ms 4692 KB Output is correct
16 Correct 23 ms 4300 KB Output is correct
17 Correct 26 ms 4704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 15 ms 3772 KB Output is correct
4 Correct 10 ms 3412 KB Output is correct
5 Correct 26 ms 4948 KB Output is correct
6 Correct 30 ms 5948 KB Output is correct
7 Correct 26 ms 6480 KB Output is correct
8 Correct 27 ms 6476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 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 0 ms 212 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 0 ms 212 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 0 ms 212 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 15 ms 3772 KB Output is correct
4 Correct 10 ms 3412 KB Output is correct
5 Correct 26 ms 4948 KB Output is correct
6 Correct 30 ms 5948 KB Output is correct
7 Correct 26 ms 6480 KB Output is correct
8 Correct 27 ms 6476 KB Output is correct
9 Incorrect 24 ms 3924 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 21 ms 2124 KB Output is correct
2 Correct 26 ms 2640 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 87 ms 7280 KB Output is correct
6 Correct 76 ms 7244 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 44 ms 6184 KB Output is correct
9 Correct 55 ms 7312 KB Output is correct
10 Correct 23 ms 2160 KB Output is correct
11 Correct 26 ms 2632 KB Output is correct
12 Correct 1 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 21 ms 4352 KB Output is correct
19 Correct 26 ms 4956 KB Output is correct
20 Correct 25 ms 4216 KB Output is correct
21 Correct 26 ms 4692 KB Output is correct
22 Correct 23 ms 4300 KB Output is correct
23 Correct 26 ms 4704 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 15 ms 3772 KB Output is correct
27 Correct 10 ms 3412 KB Output is correct
28 Correct 26 ms 4948 KB Output is correct
29 Correct 30 ms 5948 KB Output is correct
30 Correct 26 ms 6480 KB Output is correct
31 Correct 27 ms 6476 KB Output is correct
32 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '-1'
33 Halted 0 ms 0 KB -