답안 #831207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831207 2023-08-19T22:20:54 Z Wael 메기 농장 (IOI22_fish) C++17
84 / 100
1000 ms 163168 KB
#include <bits/stdc++.h>
using namespace std;
#include "fish.h"
int const Mx = 1e5 + 10;
int n , m , j;
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) {
        int 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 204 ms 62884 KB Output is correct
2 Correct 258 ms 70556 KB Output is correct
3 Correct 39 ms 38640 KB Output is correct
4 Correct 40 ms 38576 KB Output is correct
5 Correct 920 ms 156580 KB Output is correct
6 Correct 797 ms 163168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 21332 KB Output is correct
2 Correct 412 ms 76644 KB Output is correct
3 Correct 519 ms 85128 KB Output is correct
4 Correct 205 ms 62908 KB Output is correct
5 Correct 254 ms 70544 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 10 ms 21332 KB Output is correct
8 Correct 10 ms 21344 KB Output is correct
9 Correct 10 ms 21332 KB Output is correct
10 Correct 39 ms 38640 KB Output is correct
11 Correct 42 ms 38612 KB Output is correct
12 Correct 221 ms 68724 KB Output is correct
13 Correct 281 ms 77660 KB Output is correct
14 Correct 220 ms 66028 KB Output is correct
15 Correct 211 ms 60748 KB Output is correct
16 Correct 212 ms 66116 KB Output is correct
17 Correct 243 ms 70840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 38612 KB Output is correct
2 Correct 41 ms 38640 KB Output is correct
3 Correct 89 ms 43668 KB Output is correct
4 Correct 74 ms 43628 KB Output is correct
5 Correct 138 ms 50380 KB Output is correct
6 Correct 139 ms 50376 KB Output is correct
7 Correct 134 ms 50396 KB Output is correct
8 Correct 137 ms 50340 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 10 ms 21332 KB Output is correct
4 Correct 10 ms 21396 KB Output is correct
5 Correct 11 ms 21332 KB Output is correct
6 Correct 14 ms 21332 KB Output is correct
7 Correct 10 ms 21332 KB Output is correct
8 Correct 11 ms 21332 KB Output is correct
9 Correct 11 ms 21528 KB Output is correct
10 Correct 12 ms 21872 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 21460 KB Output is correct
14 Correct 13 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 10 ms 21332 KB Output is correct
4 Correct 10 ms 21396 KB Output is correct
5 Correct 11 ms 21332 KB Output is correct
6 Correct 14 ms 21332 KB Output is correct
7 Correct 10 ms 21332 KB Output is correct
8 Correct 11 ms 21332 KB Output is correct
9 Correct 11 ms 21528 KB Output is correct
10 Correct 12 ms 21872 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 21460 KB Output is correct
14 Correct 13 ms 21588 KB Output is correct
15 Correct 11 ms 21580 KB Output is correct
16 Correct 13 ms 21924 KB Output is correct
17 Correct 68 ms 31104 KB Output is correct
18 Correct 63 ms 29772 KB Output is correct
19 Correct 67 ms 30040 KB Output is correct
20 Correct 58 ms 28928 KB Output is correct
21 Correct 60 ms 28872 KB Output is correct
22 Correct 119 ms 36296 KB Output is correct
23 Correct 24 ms 25048 KB Output is correct
24 Correct 54 ms 30244 KB Output is correct
25 Correct 12 ms 21832 KB Output is correct
26 Correct 22 ms 24496 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 10 ms 21332 KB Output is correct
4 Correct 10 ms 21396 KB Output is correct
5 Correct 11 ms 21332 KB Output is correct
6 Correct 14 ms 21332 KB Output is correct
7 Correct 10 ms 21332 KB Output is correct
8 Correct 11 ms 21332 KB Output is correct
9 Correct 11 ms 21528 KB Output is correct
10 Correct 12 ms 21872 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 21460 KB Output is correct
14 Correct 13 ms 21588 KB Output is correct
15 Correct 11 ms 21580 KB Output is correct
16 Correct 13 ms 21924 KB Output is correct
17 Correct 68 ms 31104 KB Output is correct
18 Correct 63 ms 29772 KB Output is correct
19 Correct 67 ms 30040 KB Output is correct
20 Correct 58 ms 28928 KB Output is correct
21 Correct 60 ms 28872 KB Output is correct
22 Correct 119 ms 36296 KB Output is correct
23 Correct 24 ms 25048 KB Output is correct
24 Correct 54 ms 30244 KB Output is correct
25 Correct 12 ms 21832 KB Output is correct
26 Correct 22 ms 24496 KB Output is correct
27 Correct 17 ms 23128 KB Output is correct
28 Correct 422 ms 62344 KB Output is correct
29 Correct 730 ms 91816 KB Output is correct
30 Correct 904 ms 150532 KB Output is correct
31 Correct 911 ms 149268 KB Output is correct
32 Correct 588 ms 72176 KB Output is correct
33 Correct 898 ms 152576 KB Output is correct
34 Correct 904 ms 152684 KB Output is correct
35 Correct 223 ms 58904 KB Output is correct
36 Correct 865 ms 129920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 38612 KB Output is correct
2 Correct 41 ms 38640 KB Output is correct
3 Correct 89 ms 43668 KB Output is correct
4 Correct 74 ms 43628 KB Output is correct
5 Correct 138 ms 50380 KB Output is correct
6 Correct 139 ms 50376 KB Output is correct
7 Correct 134 ms 50396 KB Output is correct
8 Correct 137 ms 50340 KB Output is correct
9 Correct 224 ms 73804 KB Output is correct
10 Correct 115 ms 44024 KB Output is correct
11 Correct 273 ms 66768 KB Output is correct
12 Correct 10 ms 21332 KB Output is correct
13 Correct 11 ms 21444 KB Output is correct
14 Correct 11 ms 21332 KB Output is correct
15 Correct 10 ms 21332 KB Output is correct
16 Correct 10 ms 21332 KB Output is correct
17 Correct 10 ms 21332 KB Output is correct
18 Correct 41 ms 38632 KB Output is correct
19 Correct 37 ms 38592 KB Output is correct
20 Correct 39 ms 38632 KB Output is correct
21 Correct 39 ms 38608 KB Output is correct
22 Correct 262 ms 77028 KB Output is correct
23 Correct 400 ms 93060 KB Output is correct
24 Correct 415 ms 96076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 62884 KB Output is correct
2 Correct 258 ms 70556 KB Output is correct
3 Correct 39 ms 38640 KB Output is correct
4 Correct 40 ms 38576 KB Output is correct
5 Correct 920 ms 156580 KB Output is correct
6 Correct 797 ms 163168 KB Output is correct
7 Correct 10 ms 21332 KB Output is correct
8 Correct 412 ms 76644 KB Output is correct
9 Correct 519 ms 85128 KB Output is correct
10 Correct 205 ms 62908 KB Output is correct
11 Correct 254 ms 70544 KB Output is correct
12 Correct 10 ms 21332 KB Output is correct
13 Correct 10 ms 21332 KB Output is correct
14 Correct 10 ms 21344 KB Output is correct
15 Correct 10 ms 21332 KB Output is correct
16 Correct 39 ms 38640 KB Output is correct
17 Correct 42 ms 38612 KB Output is correct
18 Correct 221 ms 68724 KB Output is correct
19 Correct 281 ms 77660 KB Output is correct
20 Correct 220 ms 66028 KB Output is correct
21 Correct 211 ms 60748 KB Output is correct
22 Correct 212 ms 66116 KB Output is correct
23 Correct 243 ms 70840 KB Output is correct
24 Correct 48 ms 38612 KB Output is correct
25 Correct 41 ms 38640 KB Output is correct
26 Correct 89 ms 43668 KB Output is correct
27 Correct 74 ms 43628 KB Output is correct
28 Correct 138 ms 50380 KB Output is correct
29 Correct 139 ms 50376 KB Output is correct
30 Correct 134 ms 50396 KB Output is correct
31 Correct 137 ms 50340 KB Output is correct
32 Correct 11 ms 21332 KB Output is correct
33 Correct 11 ms 21332 KB Output is correct
34 Correct 10 ms 21332 KB Output is correct
35 Correct 10 ms 21396 KB Output is correct
36 Correct 11 ms 21332 KB Output is correct
37 Correct 14 ms 21332 KB Output is correct
38 Correct 10 ms 21332 KB Output is correct
39 Correct 11 ms 21332 KB Output is correct
40 Correct 11 ms 21528 KB Output is correct
41 Correct 12 ms 21872 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 21460 KB Output is correct
45 Correct 13 ms 21588 KB Output is correct
46 Correct 11 ms 21580 KB Output is correct
47 Correct 13 ms 21924 KB Output is correct
48 Correct 68 ms 31104 KB Output is correct
49 Correct 63 ms 29772 KB Output is correct
50 Correct 67 ms 30040 KB Output is correct
51 Correct 58 ms 28928 KB Output is correct
52 Correct 60 ms 28872 KB Output is correct
53 Correct 119 ms 36296 KB Output is correct
54 Correct 24 ms 25048 KB Output is correct
55 Correct 54 ms 30244 KB Output is correct
56 Correct 12 ms 21832 KB Output is correct
57 Correct 22 ms 24496 KB Output is correct
58 Correct 17 ms 23128 KB Output is correct
59 Correct 422 ms 62344 KB Output is correct
60 Correct 730 ms 91816 KB Output is correct
61 Correct 904 ms 150532 KB Output is correct
62 Correct 911 ms 149268 KB Output is correct
63 Correct 588 ms 72176 KB Output is correct
64 Correct 898 ms 152576 KB Output is correct
65 Correct 904 ms 152684 KB Output is correct
66 Correct 223 ms 58904 KB Output is correct
67 Correct 865 ms 129920 KB Output is correct
68 Correct 224 ms 73804 KB Output is correct
69 Correct 115 ms 44024 KB Output is correct
70 Correct 273 ms 66768 KB Output is correct
71 Correct 10 ms 21332 KB Output is correct
72 Correct 11 ms 21444 KB Output is correct
73 Correct 11 ms 21332 KB Output is correct
74 Correct 10 ms 21332 KB Output is correct
75 Correct 10 ms 21332 KB Output is correct
76 Correct 10 ms 21332 KB Output is correct
77 Correct 41 ms 38632 KB Output is correct
78 Correct 37 ms 38592 KB Output is correct
79 Correct 39 ms 38632 KB Output is correct
80 Correct 39 ms 38608 KB Output is correct
81 Correct 262 ms 77028 KB Output is correct
82 Correct 400 ms 93060 KB Output is correct
83 Correct 415 ms 96076 KB Output is correct
84 Execution timed out 1031 ms 141368 KB Time limit exceeded
85 Halted 0 ms 0 KB -