답안 #831208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831208 2023-08-19T22:25:07 Z Wael 메기 농장 (IOI22_fish) C++17
84 / 100
1000 ms 163268 KB
#include <bits/stdc++.h>
using namespace std;
#include "fish.h"
int const Mx = 1e5 + 10;
int n , m , j , Req , ReqNext;
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;

    for(int i = 0 ; i < m ; ++i) {
        ++X[i];
        ++Y[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];
    }

    for(int i = 1 ; i <= n + 1 ; ++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);
        }
    }

    long long MaxPref = 0 , MaxSuf = pref[2].back() , MaxDp = 0 , MaxAddDp = 0;
    for(int i = 2 ; i <= n ; ++i) {
        Req = 0 , ReqNext = 0;
        for(int J = 0 ; J < possible[i].size() ; ++J) {
            j = possible[i][J];
            while(Req + 1 < possible[i - 1].size() && possible[i - 1][Req + 1] <= j) ++Req;
            dp[0][i][J] = max(dp[0][i][J] , MaxPref + pref[i - 1][Req]);
            dp[1][i][J] = max(dp[1][i][J] , MaxSuf - pref[i][J]);
            if(i >= 3) {
               dp[0][i][J] = max(dp[0][i][J] , MaxDp + pref[i - 1][Req]);
               dp[0][i][J] = max(dp[0][i][J] , MaxAddDp - pref[i - 1][Req]);
            }
            ans = max(ans , dp[0][i][J]);
            ans = max(ans , dp[1][i][J]);
        }

        MaxPref = MaxSuf = MaxDp = MaxAddDp = 0;
        for(int J = 0 ; J < possible[i].size() ; ++J) {
            j = possible[i][J];
            while(ReqNext + 1 < possible[i + 1].size() && possible[i + 1][ReqNext + 1] <= j) ++ReqNext;
            MaxPref = max(MaxPref , dp[0][i][J] - pref[i][J]);
            MaxSuf = max(MaxSuf , max(dp[0][i][J] , dp[1][i][J]) + pref[i + 1][ReqNext]);
        }

        Req = 0;
        for(int J = 0 ; J < possible[i - 1].size() ; ++J) {
            j = possible[i - 1][J];
            while(Req + 1 < possible[i].size() && possible[i][Req + 1] <= j) ++Req;
            MaxDp = max(MaxDp , max(dp[0][i - 1][J] , dp[1][i - 1][J]));
            MaxAddDp = max(MaxAddDp , max(dp[0][i - 1][J] , dp[1][i - 1][J]) + pref[i][Req]);
        }
    }

    return ans;
}
/*
pref = max Dp - prefi
suf = max Dp - prefi + 1
Pref = max Dp
Suf = max Dp + prefi + 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:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int J = 0 ; J < possible[i].size() ; ++J) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             while(Req + 1 < possible[i - 1].size() && possible[i - 1][Req + 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:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             while(ReqNext + 1 < possible[i + 1].size() && possible[i + 1][ReqNext + 1] <= j) ++ReqNext;
      |                   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:64:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for(int J = 0 ; J < possible[i - 1].size() ; ++J) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             while(Req + 1 < possible[i].size() && possible[i][Req + 1] <= j) ++Req;
      |                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 62820 KB Output is correct
2 Correct 253 ms 70564 KB Output is correct
3 Correct 39 ms 38612 KB Output is correct
4 Correct 40 ms 38612 KB Output is correct
5 Correct 886 ms 156580 KB Output is correct
6 Correct 788 ms 163268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21320 KB Output is correct
2 Correct 445 ms 76620 KB Output is correct
3 Correct 537 ms 85040 KB Output is correct
4 Correct 216 ms 62864 KB Output is correct
5 Correct 251 ms 70616 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 12 ms 21344 KB Output is correct
8 Correct 11 ms 21356 KB Output is correct
9 Correct 10 ms 21440 KB Output is correct
10 Correct 39 ms 38576 KB Output is correct
11 Correct 38 ms 38540 KB Output is correct
12 Correct 221 ms 68684 KB Output is correct
13 Correct 288 ms 77620 KB Output is correct
14 Correct 216 ms 65972 KB Output is correct
15 Correct 210 ms 60692 KB Output is correct
16 Correct 250 ms 66136 KB Output is correct
17 Correct 256 ms 70844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 38564 KB Output is correct
2 Correct 38 ms 38640 KB Output is correct
3 Correct 83 ms 43724 KB Output is correct
4 Correct 70 ms 43636 KB Output is correct
5 Correct 148 ms 50408 KB Output is correct
6 Correct 130 ms 50392 KB Output is correct
7 Correct 164 ms 50352 KB Output is correct
8 Correct 138 ms 50396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21332 KB Output is correct
2 Correct 11 ms 21332 KB Output is correct
3 Correct 11 ms 21376 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21384 KB Output is correct
6 Correct 10 ms 21316 KB Output is correct
7 Correct 11 ms 21332 KB Output is correct
8 Correct 11 ms 21400 KB Output is correct
9 Correct 11 ms 21524 KB Output is correct
10 Correct 12 ms 21816 KB Output is correct
11 Correct 11 ms 21588 KB Output is correct
12 Correct 11 ms 21716 KB Output is correct
13 Correct 11 ms 21404 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21332 KB Output is correct
2 Correct 11 ms 21332 KB Output is correct
3 Correct 11 ms 21376 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21384 KB Output is correct
6 Correct 10 ms 21316 KB Output is correct
7 Correct 11 ms 21332 KB Output is correct
8 Correct 11 ms 21400 KB Output is correct
9 Correct 11 ms 21524 KB Output is correct
10 Correct 12 ms 21816 KB Output is correct
11 Correct 11 ms 21588 KB Output is correct
12 Correct 11 ms 21716 KB Output is correct
13 Correct 11 ms 21404 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
15 Correct 12 ms 21580 KB Output is correct
16 Correct 13 ms 21924 KB Output is correct
17 Correct 79 ms 31196 KB Output is correct
18 Correct 65 ms 29772 KB Output is correct
19 Correct 62 ms 30024 KB Output is correct
20 Correct 59 ms 28940 KB Output is correct
21 Correct 59 ms 28884 KB Output is correct
22 Correct 119 ms 36300 KB Output is correct
23 Correct 24 ms 25052 KB Output is correct
24 Correct 61 ms 30156 KB Output is correct
25 Correct 13 ms 21852 KB Output is correct
26 Correct 27 ms 24532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21332 KB Output is correct
2 Correct 11 ms 21332 KB Output is correct
3 Correct 11 ms 21376 KB Output is correct
4 Correct 10 ms 21332 KB Output is correct
5 Correct 10 ms 21384 KB Output is correct
6 Correct 10 ms 21316 KB Output is correct
7 Correct 11 ms 21332 KB Output is correct
8 Correct 11 ms 21400 KB Output is correct
9 Correct 11 ms 21524 KB Output is correct
10 Correct 12 ms 21816 KB Output is correct
11 Correct 11 ms 21588 KB Output is correct
12 Correct 11 ms 21716 KB Output is correct
13 Correct 11 ms 21404 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
15 Correct 12 ms 21580 KB Output is correct
16 Correct 13 ms 21924 KB Output is correct
17 Correct 79 ms 31196 KB Output is correct
18 Correct 65 ms 29772 KB Output is correct
19 Correct 62 ms 30024 KB Output is correct
20 Correct 59 ms 28940 KB Output is correct
21 Correct 59 ms 28884 KB Output is correct
22 Correct 119 ms 36300 KB Output is correct
23 Correct 24 ms 25052 KB Output is correct
24 Correct 61 ms 30156 KB Output is correct
25 Correct 13 ms 21852 KB Output is correct
26 Correct 27 ms 24532 KB Output is correct
27 Correct 14 ms 22896 KB Output is correct
28 Correct 404 ms 62272 KB Output is correct
29 Correct 774 ms 91864 KB Output is correct
30 Correct 920 ms 150516 KB Output is correct
31 Correct 923 ms 149296 KB Output is correct
32 Correct 608 ms 72072 KB Output is correct
33 Correct 953 ms 152576 KB Output is correct
34 Correct 944 ms 152740 KB Output is correct
35 Correct 211 ms 58884 KB Output is correct
36 Correct 855 ms 129844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 38564 KB Output is correct
2 Correct 38 ms 38640 KB Output is correct
3 Correct 83 ms 43724 KB Output is correct
4 Correct 70 ms 43636 KB Output is correct
5 Correct 148 ms 50408 KB Output is correct
6 Correct 130 ms 50392 KB Output is correct
7 Correct 164 ms 50352 KB Output is correct
8 Correct 138 ms 50396 KB Output is correct
9 Correct 233 ms 73880 KB Output is correct
10 Correct 112 ms 44104 KB Output is correct
11 Correct 272 ms 66764 KB Output is correct
12 Correct 13 ms 21332 KB Output is correct
13 Correct 11 ms 21424 KB Output is correct
14 Correct 11 ms 21332 KB Output is correct
15 Correct 12 ms 21336 KB Output is correct
16 Correct 11 ms 21332 KB Output is correct
17 Correct 10 ms 21376 KB Output is correct
18 Correct 36 ms 38544 KB Output is correct
19 Correct 37 ms 38660 KB Output is correct
20 Correct 38 ms 38572 KB Output is correct
21 Correct 38 ms 38616 KB Output is correct
22 Correct 273 ms 77144 KB Output is correct
23 Correct 397 ms 92920 KB Output is correct
24 Correct 428 ms 96164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 62820 KB Output is correct
2 Correct 253 ms 70564 KB Output is correct
3 Correct 39 ms 38612 KB Output is correct
4 Correct 40 ms 38612 KB Output is correct
5 Correct 886 ms 156580 KB Output is correct
6 Correct 788 ms 163268 KB Output is correct
7 Correct 11 ms 21320 KB Output is correct
8 Correct 445 ms 76620 KB Output is correct
9 Correct 537 ms 85040 KB Output is correct
10 Correct 216 ms 62864 KB Output is correct
11 Correct 251 ms 70616 KB Output is correct
12 Correct 10 ms 21332 KB Output is correct
13 Correct 12 ms 21344 KB Output is correct
14 Correct 11 ms 21356 KB Output is correct
15 Correct 10 ms 21440 KB Output is correct
16 Correct 39 ms 38576 KB Output is correct
17 Correct 38 ms 38540 KB Output is correct
18 Correct 221 ms 68684 KB Output is correct
19 Correct 288 ms 77620 KB Output is correct
20 Correct 216 ms 65972 KB Output is correct
21 Correct 210 ms 60692 KB Output is correct
22 Correct 250 ms 66136 KB Output is correct
23 Correct 256 ms 70844 KB Output is correct
24 Correct 38 ms 38564 KB Output is correct
25 Correct 38 ms 38640 KB Output is correct
26 Correct 83 ms 43724 KB Output is correct
27 Correct 70 ms 43636 KB Output is correct
28 Correct 148 ms 50408 KB Output is correct
29 Correct 130 ms 50392 KB Output is correct
30 Correct 164 ms 50352 KB Output is correct
31 Correct 138 ms 50396 KB Output is correct
32 Correct 11 ms 21332 KB Output is correct
33 Correct 11 ms 21332 KB Output is correct
34 Correct 11 ms 21376 KB Output is correct
35 Correct 10 ms 21332 KB Output is correct
36 Correct 10 ms 21384 KB Output is correct
37 Correct 10 ms 21316 KB Output is correct
38 Correct 11 ms 21332 KB Output is correct
39 Correct 11 ms 21400 KB Output is correct
40 Correct 11 ms 21524 KB Output is correct
41 Correct 12 ms 21816 KB Output is correct
42 Correct 11 ms 21588 KB Output is correct
43 Correct 11 ms 21716 KB Output is correct
44 Correct 11 ms 21404 KB Output is correct
45 Correct 11 ms 21588 KB Output is correct
46 Correct 12 ms 21580 KB Output is correct
47 Correct 13 ms 21924 KB Output is correct
48 Correct 79 ms 31196 KB Output is correct
49 Correct 65 ms 29772 KB Output is correct
50 Correct 62 ms 30024 KB Output is correct
51 Correct 59 ms 28940 KB Output is correct
52 Correct 59 ms 28884 KB Output is correct
53 Correct 119 ms 36300 KB Output is correct
54 Correct 24 ms 25052 KB Output is correct
55 Correct 61 ms 30156 KB Output is correct
56 Correct 13 ms 21852 KB Output is correct
57 Correct 27 ms 24532 KB Output is correct
58 Correct 14 ms 22896 KB Output is correct
59 Correct 404 ms 62272 KB Output is correct
60 Correct 774 ms 91864 KB Output is correct
61 Correct 920 ms 150516 KB Output is correct
62 Correct 923 ms 149296 KB Output is correct
63 Correct 608 ms 72072 KB Output is correct
64 Correct 953 ms 152576 KB Output is correct
65 Correct 944 ms 152740 KB Output is correct
66 Correct 211 ms 58884 KB Output is correct
67 Correct 855 ms 129844 KB Output is correct
68 Correct 233 ms 73880 KB Output is correct
69 Correct 112 ms 44104 KB Output is correct
70 Correct 272 ms 66764 KB Output is correct
71 Correct 13 ms 21332 KB Output is correct
72 Correct 11 ms 21424 KB Output is correct
73 Correct 11 ms 21332 KB Output is correct
74 Correct 12 ms 21336 KB Output is correct
75 Correct 11 ms 21332 KB Output is correct
76 Correct 10 ms 21376 KB Output is correct
77 Correct 36 ms 38544 KB Output is correct
78 Correct 37 ms 38660 KB Output is correct
79 Correct 38 ms 38572 KB Output is correct
80 Correct 38 ms 38616 KB Output is correct
81 Correct 273 ms 77144 KB Output is correct
82 Correct 397 ms 92920 KB Output is correct
83 Correct 428 ms 96164 KB Output is correct
84 Execution timed out 1084 ms 141452 KB Time limit exceeded
85 Halted 0 ms 0 KB -