Submission #831140

# Submission time Handle Problem Language Result Execution time Memory
831140 2023-08-19T19:30:29 Z Wael Catfish Farm (IOI22_fish) C++17
67 / 100
1000 ms 100044 KB
#include <bits/stdc++.h>
using namespace std;
#include "fish.h"
int const Mx = 1e5 + 10;
long long n , m;
map<int , int>cost[Mx] , vis[Mx];
vector<int>possible[Mx];
vector<long long>pref[Mx] , dp[3][Mx];

long long max_weights(int N, int M , vector<int> X, vector<int> Y, vector<int> W) {
    m = M , n = N;
    long long ans = 0 , Sum = 0;
    int MaxX = 0 , Even = 1;

    for(int i = 0 ; i < m ; ++i) {
        ++X[i];
        ++Y[i];
        Sum += W[i];
        if(X[i] % 2 == 0) Even = 0;
        MaxX = max(MaxX , X[i]);
        if(vis[X[i] - 1][Y[i]] == 0) possible[X[i] - 1].push_back(Y[i]);
        if(vis[X[i] + 1][Y[i]] == 0) possible[X[i] + 1].push_back(Y[i]);
        if(vis[X[i]][Y[i]] == 0) possible[X[i]].push_back(Y[i]);
        vis[X[i] - 1][Y[i]] = 1;
        vis[X[i] + 1][Y[i]] = 1;
        vis[X[i]][Y[i]] = 1;
        cost[X[i]][Y[i]] = W[i];
    }

    if(Even) return Sum;
    for(int i = 1 ; i <= n ; ++i) {
        possible[i].push_back(0);
        sort(possible[i].begin() , possible[i].end());
        for(auto j : possible[i]) {
            long long cur = 0;
            if(pref[i].size()) cur = pref[i].back();
            cur += cost[i][j];
            pref[i].push_back(cur);
            dp[0][i].push_back(0);
            dp[1][i].push_back(0);
        }
    }

    if(MaxX <= 2) {
        if(n == 2) return max(pref[1].back() , pref[2].back());
        long long sum = pref[2].back();
        int Req = 0;
        for(int j = 0 ; j < possible[1].size() ; ++j) {
            while(Req + 1 < possible[2].size() && possible[2][Req + 1] <= possible[1][j]) ++Req;
            ans = max(ans , sum - pref[2][Req] + pref[1][j]);
        }
        return ans;
    }

    for(int i = 2 ; i <= n ; ++i) {
        for(int J = 0 ; J < possible[i].size() ; ++J) {
            int j = possible[i][J];
            int Req1 = 0 , Req2 = 0;
            while(Req1 + 1 < possible[i - 1].size() && possible[i - 1][Req1 + 1] <= j) ++Req1;
            for(int K = 0 ; K <  possible[i - 1].size() ; ++K) {
                int k = possible[i - 1][K];
                while(Req2 + 1 < possible[i].size() && possible[i][Req2 + 1] <= k) ++Req2;
                if(k <= j) dp[0][i][J] = max(dp[0][i][J] , dp[0][i - 1][K] + pref[i - 1][Req1] - pref[i - 1][K]);
                else dp[1][i][J] = max(dp[1][i][J] , max(dp[0][i - 1][K] , dp[1][i - 1][K]) + pref[i][Req2] - pref[i][J]);
            }
            if(i >= 3) {
                int Req = 0;
                for(int K = 0 ; K < possible[i - 2].size() ; ++K) {
                    int k = possible[i - 2][K];
                    while(Req + 1 < possible[i - 1].size() && possible[i - 1][Req + 1] <= max(j , k)) ++Req;
                    dp[0][i][J] = max(dp[0][i][J] , max(dp[0][i - 2][K] , dp[1][i - 2][K]) + pref[i - 1][Req]);
                }
            }
            ans = max(ans , dp[0][i][J]);
            ans = max(ans , dp[1][i][J]);
        }
    }

    return ans;
}
/*
3 4
1 1 5
1 2 10
2 1 5
3 1 5
*/

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for(int j = 0 ; j < possible[1].size() ; ++j) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             while(Req + 1 < possible[2].size() && possible[2][Req + 1] <= possible[1][j]) ++Req;
      |                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int J = 0 ; J < possible[i].size() ; ++J) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:59:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             while(Req1 + 1 < possible[i - 1].size() && possible[i - 1][Req1 + 1] <= j) ++Req1;
      |                   ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:60:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             for(int K = 0 ; K <  possible[i - 1].size() ; ++K) {
      |                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:62:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 while(Req2 + 1 < possible[i].size() && possible[i][Req2 + 1] <= k) ++Req2;
      |                       ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:68:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |                 for(int K = 0 ; K < possible[i - 2].size() ; ++K) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:70:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |                     while(Req + 1 < possible[i - 1].size() && possible[i - 1][Req + 1] <= max(j , k)) ++Req;
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 140 ms 40776 KB Output is correct
2 Correct 178 ms 45412 KB Output is correct
3 Correct 12 ms 21388 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 642 ms 94756 KB Output is correct
6 Correct 539 ms 99680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21332 KB Output is correct
2 Correct 393 ms 79484 KB Output is correct
3 Correct 486 ms 88488 KB Output is correct
4 Correct 138 ms 40772 KB Output is correct
5 Correct 180 ms 45460 KB Output is correct
6 Correct 10 ms 21432 KB Output is correct
7 Correct 11 ms 21436 KB Output is correct
8 Correct 11 ms 21372 KB Output is correct
9 Correct 10 ms 21444 KB Output is correct
10 Correct 11 ms 21332 KB Output is correct
11 Correct 11 ms 21412 KB Output is correct
12 Correct 228 ms 70184 KB Output is correct
13 Correct 277 ms 79408 KB Output is correct
14 Correct 204 ms 67436 KB Output is correct
15 Correct 214 ms 62284 KB Output is correct
16 Correct 206 ms 67480 KB Output is correct
17 Correct 234 ms 72320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21432 KB Output is correct
2 Correct 36 ms 38612 KB Output is correct
3 Correct 84 ms 44588 KB Output is correct
4 Correct 70 ms 44188 KB Output is correct
5 Correct 132 ms 51956 KB Output is correct
6 Correct 128 ms 51348 KB Output is correct
7 Correct 131 ms 51932 KB Output is correct
8 Correct 129 ms 51884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21332 KB Output is correct
2 Correct 10 ms 21368 KB Output is correct
3 Correct 9 ms 21444 KB Output is correct
4 Correct 11 ms 21332 KB Output is correct
5 Correct 10 ms 21444 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 10 ms 21384 KB Output is correct
8 Correct 10 ms 21364 KB Output is correct
9 Correct 11 ms 21444 KB Output is correct
10 Correct 12 ms 21844 KB Output is correct
11 Correct 12 ms 21572 KB Output is correct
12 Correct 13 ms 21708 KB Output is correct
13 Correct 10 ms 21440 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21332 KB Output is correct
2 Correct 10 ms 21368 KB Output is correct
3 Correct 9 ms 21444 KB Output is correct
4 Correct 11 ms 21332 KB Output is correct
5 Correct 10 ms 21444 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 10 ms 21384 KB Output is correct
8 Correct 10 ms 21364 KB Output is correct
9 Correct 11 ms 21444 KB Output is correct
10 Correct 12 ms 21844 KB Output is correct
11 Correct 12 ms 21572 KB Output is correct
12 Correct 13 ms 21708 KB Output is correct
13 Correct 10 ms 21440 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
15 Correct 11 ms 21596 KB Output is correct
16 Correct 15 ms 21876 KB Output is correct
17 Correct 164 ms 31892 KB Output is correct
18 Correct 153 ms 30540 KB Output is correct
19 Correct 116 ms 30896 KB Output is correct
20 Correct 98 ms 29716 KB Output is correct
21 Correct 96 ms 29628 KB Output is correct
22 Correct 264 ms 37836 KB Output is correct
23 Correct 37 ms 25164 KB Output is correct
24 Correct 138 ms 30720 KB Output is correct
25 Correct 12 ms 21836 KB Output is correct
26 Correct 33 ms 24716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21332 KB Output is correct
2 Correct 10 ms 21368 KB Output is correct
3 Correct 9 ms 21444 KB Output is correct
4 Correct 11 ms 21332 KB Output is correct
5 Correct 10 ms 21444 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 10 ms 21384 KB Output is correct
8 Correct 10 ms 21364 KB Output is correct
9 Correct 11 ms 21444 KB Output is correct
10 Correct 12 ms 21844 KB Output is correct
11 Correct 12 ms 21572 KB Output is correct
12 Correct 13 ms 21708 KB Output is correct
13 Correct 10 ms 21440 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
15 Correct 11 ms 21596 KB Output is correct
16 Correct 15 ms 21876 KB Output is correct
17 Correct 164 ms 31892 KB Output is correct
18 Correct 153 ms 30540 KB Output is correct
19 Correct 116 ms 30896 KB Output is correct
20 Correct 98 ms 29716 KB Output is correct
21 Correct 96 ms 29628 KB Output is correct
22 Correct 264 ms 37836 KB Output is correct
23 Correct 37 ms 25164 KB Output is correct
24 Correct 138 ms 30720 KB Output is correct
25 Correct 12 ms 21836 KB Output is correct
26 Correct 33 ms 24716 KB Output is correct
27 Correct 15 ms 22996 KB Output is correct
28 Execution timed out 1080 ms 66064 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21432 KB Output is correct
2 Correct 36 ms 38612 KB Output is correct
3 Correct 84 ms 44588 KB Output is correct
4 Correct 70 ms 44188 KB Output is correct
5 Correct 132 ms 51956 KB Output is correct
6 Correct 128 ms 51348 KB Output is correct
7 Correct 131 ms 51932 KB Output is correct
8 Correct 129 ms 51884 KB Output is correct
9 Correct 226 ms 75180 KB Output is correct
10 Correct 113 ms 45800 KB Output is correct
11 Correct 273 ms 70220 KB Output is correct
12 Correct 10 ms 21344 KB Output is correct
13 Correct 10 ms 21356 KB Output is correct
14 Correct 10 ms 21332 KB Output is correct
15 Correct 11 ms 21332 KB Output is correct
16 Correct 11 ms 21432 KB Output is correct
17 Correct 10 ms 21436 KB Output is correct
18 Correct 11 ms 21440 KB Output is correct
19 Correct 10 ms 21332 KB Output is correct
20 Correct 38 ms 38576 KB Output is correct
21 Correct 38 ms 38576 KB Output is correct
22 Correct 292 ms 79256 KB Output is correct
23 Correct 415 ms 96700 KB Output is correct
24 Correct 417 ms 100044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 40776 KB Output is correct
2 Correct 178 ms 45412 KB Output is correct
3 Correct 12 ms 21388 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 642 ms 94756 KB Output is correct
6 Correct 539 ms 99680 KB Output is correct
7 Correct 11 ms 21332 KB Output is correct
8 Correct 393 ms 79484 KB Output is correct
9 Correct 486 ms 88488 KB Output is correct
10 Correct 138 ms 40772 KB Output is correct
11 Correct 180 ms 45460 KB Output is correct
12 Correct 10 ms 21432 KB Output is correct
13 Correct 11 ms 21436 KB Output is correct
14 Correct 11 ms 21372 KB Output is correct
15 Correct 10 ms 21444 KB Output is correct
16 Correct 11 ms 21332 KB Output is correct
17 Correct 11 ms 21412 KB Output is correct
18 Correct 228 ms 70184 KB Output is correct
19 Correct 277 ms 79408 KB Output is correct
20 Correct 204 ms 67436 KB Output is correct
21 Correct 214 ms 62284 KB Output is correct
22 Correct 206 ms 67480 KB Output is correct
23 Correct 234 ms 72320 KB Output is correct
24 Correct 10 ms 21432 KB Output is correct
25 Correct 36 ms 38612 KB Output is correct
26 Correct 84 ms 44588 KB Output is correct
27 Correct 70 ms 44188 KB Output is correct
28 Correct 132 ms 51956 KB Output is correct
29 Correct 128 ms 51348 KB Output is correct
30 Correct 131 ms 51932 KB Output is correct
31 Correct 129 ms 51884 KB Output is correct
32 Correct 11 ms 21332 KB Output is correct
33 Correct 10 ms 21368 KB Output is correct
34 Correct 9 ms 21444 KB Output is correct
35 Correct 11 ms 21332 KB Output is correct
36 Correct 10 ms 21444 KB Output is correct
37 Correct 10 ms 21332 KB Output is correct
38 Correct 10 ms 21384 KB Output is correct
39 Correct 10 ms 21364 KB Output is correct
40 Correct 11 ms 21444 KB Output is correct
41 Correct 12 ms 21844 KB Output is correct
42 Correct 12 ms 21572 KB Output is correct
43 Correct 13 ms 21708 KB Output is correct
44 Correct 10 ms 21440 KB Output is correct
45 Correct 11 ms 21588 KB Output is correct
46 Correct 11 ms 21596 KB Output is correct
47 Correct 15 ms 21876 KB Output is correct
48 Correct 164 ms 31892 KB Output is correct
49 Correct 153 ms 30540 KB Output is correct
50 Correct 116 ms 30896 KB Output is correct
51 Correct 98 ms 29716 KB Output is correct
52 Correct 96 ms 29628 KB Output is correct
53 Correct 264 ms 37836 KB Output is correct
54 Correct 37 ms 25164 KB Output is correct
55 Correct 138 ms 30720 KB Output is correct
56 Correct 12 ms 21836 KB Output is correct
57 Correct 33 ms 24716 KB Output is correct
58 Correct 15 ms 22996 KB Output is correct
59 Execution timed out 1080 ms 66064 KB Time limit exceeded
60 Halted 0 ms 0 KB -