Submission #661046

# Submission time Handle Problem Language Result Execution time Memory
661046 2022-11-24T06:00:58 Z mychecksedad Catfish Farm (IOI22_fish) C++17
32 / 100
85 ms 86064 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int N = 1e5 + 100;


ll dp[N][15][2], a[N][2], s[N], pref[N][15], dp_pref[N][15], dp_suf[N][15], dp_pref_max[N][15], dp_suf_max[N][15];
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;
    for(int i = 0; i < m; ++i){
        if(x[i] % 2) case1 = 0;
        if(x[i] > 1) case2 = 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] = s[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) s[i] = s[i + 1] + a[i][1];

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

            return best;
        }
    }
    for(int i = 0; i <= n + 5; ++i){
        for(int j = 0; j < 15; ++j) pref[i][j] = dp[i][j][0] = dp[i][j][1] = dp_pref[i][j] = dp_suf[i][j] = dp_pref_max[i][j] = 0;
    }
    for(int i = 0; i < m; ++i) pref[x[i]][y[i] + 1] = w[i];

    for(int i = 0; i <= n; ++i){
        for(int j = 1; j < 15; ++j) pref[i][j] += pref[i][j - 1];
    }
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j < 10; ++j){    
            if(i == 0){
                dp[i][j][0] = dp[i][j][1] = pref[i + 1][j];
                continue;
            }

            dp[i][j][0] = pref[i + 1][j];

            if(i == 1){
                dp[i][j][0] += dp_pref[i - 1][j] + pref[i - 1][j];
            }else{  
                dp[i][j][0] += max({dp_pref[i - 1][j] + pref[i - 1][j],
                    dp_suf[i - 2][0],
                    dp_pref_max[i - 2][j] + pref[i - 1][j] 
                });
            }

            dp[i][j][1] = pref[i + 1][j] - pref[i][j] + dp_suf[i - 1][j];
        }

        for(int j = 0; j < 10; ++j){
            if(j == 0){
                dp_pref[i][j] = dp[i][j][0] - pref[i + 1][j] - pref[i][j];
                dp_pref_max[i][j] = max(dp[i][j][0], dp[i][j][1]) - pref[i + 1][j];
            }
            else{
                dp_pref[i][j] = max(dp_pref[i][j - 1], dp[i][j][0] - pref[i + 1][j] - pref[i][j]);
                dp_pref_max[i][j] = max(dp_pref_max[i][j - 1], max(dp[i][j][0], dp[i][j][1]) - pref[i + 1][j]);
            }
        }

        for(int j = 9; j >= 0; --j){
            if(j == 9){
                dp_suf[i][j] = max(dp[i][j][0], dp[i][j][1]);
                dp_suf_max[i][j] = max(dp[i][j][0], dp[i][j][1]) + pref[i + 1][j];
            }
            else{
                dp_suf[i][j] = max({dp_suf[i][j + 1], dp[i][j][0], dp[i][j][1]});
                dp_suf_max[i][j] = max(dp_suf_max[i][j - 1], max(dp[i][j][0], dp[i][j][1]) + pref[i + 1][j]);
            }
        }
    }
    return max(dp[n][0][0], dp[n][0][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:31:17: warning: unused variable 'p' [-Wunused-variable]
   31 |             int p = 0;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2124 KB Output is correct
2 Correct 26 ms 2620 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 85 ms 7244 KB Output is correct
6 Correct 83 ms 7284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 46 ms 6220 KB Output is correct
3 Correct 61 ms 7256 KB Output is correct
4 Correct 21 ms 2124 KB Output is correct
5 Correct 26 ms 2640 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 1 ms 212 KB Output is correct
12 Correct 22 ms 4356 KB Output is correct
13 Correct 27 ms 4948 KB Output is correct
14 Correct 23 ms 4308 KB Output is correct
15 Correct 27 ms 4700 KB Output is correct
16 Correct 23 ms 4348 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 48 ms 82412 KB Output is correct
3 Correct 54 ms 75456 KB Output is correct
4 Correct 56 ms 83824 KB Output is correct
5 Correct 68 ms 85292 KB Output is correct
6 Correct 70 ms 85452 KB Output is correct
7 Correct 76 ms 85392 KB Output is correct
8 Correct 72 ms 85296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 576 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 576 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 576 KB Output is correct
15 Incorrect 1 ms 596 KB 1st lines differ - on the 1st token, expected: '299', found: '189'
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 576 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 576 KB Output is correct
15 Incorrect 1 ms 596 KB 1st lines differ - on the 1st token, expected: '299', found: '189'
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 48 ms 82412 KB Output is correct
3 Correct 54 ms 75456 KB Output is correct
4 Correct 56 ms 83824 KB Output is correct
5 Correct 68 ms 85292 KB Output is correct
6 Correct 70 ms 85452 KB Output is correct
7 Correct 76 ms 85392 KB Output is correct
8 Correct 72 ms 85296 KB Output is correct
9 Incorrect 71 ms 86064 KB 1st lines differ - on the 1st token, expected: '99999', found: '62500'
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 2620 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 85 ms 7244 KB Output is correct
6 Correct 83 ms 7284 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 46 ms 6220 KB Output is correct
9 Correct 61 ms 7256 KB Output is correct
10 Correct 21 ms 2124 KB Output is correct
11 Correct 26 ms 2640 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 1 ms 212 KB Output is correct
18 Correct 22 ms 4356 KB Output is correct
19 Correct 27 ms 4948 KB Output is correct
20 Correct 23 ms 4308 KB Output is correct
21 Correct 27 ms 4700 KB Output is correct
22 Correct 23 ms 4348 KB Output is correct
23 Correct 26 ms 4704 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 48 ms 82412 KB Output is correct
26 Correct 54 ms 75456 KB Output is correct
27 Correct 56 ms 83824 KB Output is correct
28 Correct 68 ms 85292 KB Output is correct
29 Correct 70 ms 85452 KB Output is correct
30 Correct 76 ms 85392 KB Output is correct
31 Correct 72 ms 85296 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 576 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 596 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 576 KB Output is correct
46 Incorrect 1 ms 596 KB 1st lines differ - on the 1st token, expected: '299', found: '189'
47 Halted 0 ms 0 KB -