답안 #1051595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051595 2024-08-10T08:29:36 Z Itamar 메기 농장 (IOI22_fish) C++17
100 / 100
476 ms 163344 KB
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#include<map>
#define pi pair<int,int>
#include <algorithm>
#include<unordered_map>
#define map unordered_map
ll max_weights(int N, int M, vi X, vi Y, vi W){
    for(int i = 0; i < M; i++)X[i]++,Y[i]++;
    vector<vi> fish(N+2);
    vector<map<int,int>> w(N+2);
    vector<map<int,ll>> s(N+2);
    vector<map<int,ll>> dp(N+2);
    vector<map<int,ll>> pref(N+2); // maximum (prefix - prefix_sum), notice initialization
    ll ans = 0;
    ll su=0;
    for(int i = 0; i <= N+1; i++){
        fish[i].push_back(0);fish[i].push_back(N+2);
    }
    for(int i = 0; i < M; i++){
        fish[X[i]].push_back(Y[i]);
        w[X[i]][Y[i]]=W[i];
    }
    for(int i = 0; i < N+2; i++)sort(fish[i].begin(),fish[i].end());
    for(int i = 0; i < N+2; i++){
        for(int j = 1; j < fish[i].size(); j++){
            s[i][fish[i][j]] = s[i][fish[i][j-1]]+w[i][fish[i][j-1]];
        }
    }
    for(int i = 1; i < N+1; i++){
        int dub = 0;
        for(int y : fish[i]){
            dp[i][y] = max(dp[i][y], su-s[i][y]);
            if(y){int predown = *--upper_bound(fish[i-1].begin(),fish[i-1].end(),y-1); // maybe y-1
            dp[i][y]=max(dp[i][y], pref[i-1][predown]+s[i-1][predown]+w[i-1][predown]);
            }
            //ans = max(ans,dp[i][y]);
        }
        int maxi = 0;
        int it = 0;
        pref[i][0] = ans;
        for(int y : fish[i])ans = max(ans,dp[i][y]);
         for(int j = 1; j < fish[i].size(); j++){
            int y = fish[i][j], prey=fish[i][j-1];
            pref[i][y] = pref[i][prey];
            int predown = *--upper_bound(fish[i-1].begin(),fish[i-1].end(),y-1); // maybe y-1
            pref[i][y]=max(pref[i][y], pref[i-1][predown]+s[i-1][predown]-s[i][y]+w[i-1][predown]);
        }
        su= s[i+1][N+2] + dp[i][N+2];
        for(int j = fish[i].size()-2; j>=0; j--){
            int y = fish[i][j],yaf = fish[i][j+1];
            int predown = *upper_bound(fish[i+1].begin(),fish[i+1].end(),y-1);
            su = max(su, dp[i][y] + s[i+1][predown]);
        }
    }
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:29:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int j = 1; j < fish[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~~
fish.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |          for(int j = 1; j < fish[i].size(); j++){
      |                         ~~^~~~~~~~~~~~~~~~
fish.cpp:54:32: warning: unused variable 'yaf' [-Wunused-variable]
   54 |             int y = fish[i][j],yaf = fish[i][j+1];
      |                                ^~~
fish.cpp:34:13: warning: unused variable 'dub' [-Wunused-variable]
   34 |         int dub = 0;
      |             ^~~
fish.cpp:42:13: warning: unused variable 'maxi' [-Wunused-variable]
   42 |         int maxi = 0;
      |             ^~~~
fish.cpp:43:13: warning: unused variable 'it' [-Wunused-variable]
   43 |         int it = 0;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 100520 KB Output is correct
2 Correct 173 ms 115948 KB Output is correct
3 Correct 163 ms 93388 KB Output is correct
4 Correct 121 ms 93404 KB Output is correct
5 Correct 348 ms 163344 KB Output is correct
6 Correct 476 ms 146520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 235 ms 116948 KB Output is correct
3 Correct 271 ms 138436 KB Output is correct
4 Correct 184 ms 100460 KB Output is correct
5 Correct 195 ms 115880 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 107 ms 93508 KB Output is correct
11 Correct 100 ms 93484 KB Output is correct
12 Correct 144 ms 100668 KB Output is correct
13 Correct 176 ms 115932 KB Output is correct
14 Correct 137 ms 100612 KB Output is correct
15 Correct 149 ms 114268 KB Output is correct
16 Correct 161 ms 100608 KB Output is correct
17 Correct 198 ms 114028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 93556 KB Output is correct
2 Correct 109 ms 93524 KB Output is correct
3 Correct 186 ms 93012 KB Output is correct
4 Correct 121 ms 99548 KB Output is correct
5 Correct 231 ms 109936 KB Output is correct
6 Correct 206 ms 109332 KB Output is correct
7 Correct 208 ms 109872 KB Output is correct
8 Correct 200 ms 109908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1088 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1088 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 28 ms 9704 KB Output is correct
18 Correct 31 ms 11092 KB Output is correct
19 Correct 40 ms 10676 KB Output is correct
20 Correct 29 ms 10776 KB Output is correct
21 Correct 27 ms 10528 KB Output is correct
22 Correct 62 ms 21196 KB Output is correct
23 Correct 6 ms 2396 KB Output is correct
24 Correct 22 ms 6692 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 6 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1088 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 28 ms 9704 KB Output is correct
18 Correct 31 ms 11092 KB Output is correct
19 Correct 40 ms 10676 KB Output is correct
20 Correct 29 ms 10776 KB Output is correct
21 Correct 27 ms 10528 KB Output is correct
22 Correct 62 ms 21196 KB Output is correct
23 Correct 6 ms 2396 KB Output is correct
24 Correct 22 ms 6692 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 6 ms 2424 KB Output is correct
27 Correct 5 ms 3512 KB Output is correct
28 Correct 161 ms 50852 KB Output is correct
29 Correct 255 ms 74836 KB Output is correct
30 Correct 334 ms 65744 KB Output is correct
31 Correct 351 ms 65888 KB Output is correct
32 Correct 227 ms 71508 KB Output is correct
33 Correct 277 ms 65884 KB Output is correct
34 Correct 279 ms 66000 KB Output is correct
35 Correct 92 ms 27356 KB Output is correct
36 Correct 273 ms 70480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 93556 KB Output is correct
2 Correct 109 ms 93524 KB Output is correct
3 Correct 186 ms 93012 KB Output is correct
4 Correct 121 ms 99548 KB Output is correct
5 Correct 231 ms 109936 KB Output is correct
6 Correct 206 ms 109332 KB Output is correct
7 Correct 208 ms 109872 KB Output is correct
8 Correct 200 ms 109908 KB Output is correct
9 Correct 197 ms 109652 KB Output is correct
10 Correct 120 ms 63568 KB Output is correct
11 Correct 265 ms 126572 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 92 ms 93344 KB Output is correct
19 Correct 131 ms 93524 KB Output is correct
20 Correct 111 ms 93412 KB Output is correct
21 Correct 129 ms 93504 KB Output is correct
22 Correct 182 ms 110424 KB Output is correct
23 Correct 271 ms 126668 KB Output is correct
24 Correct 264 ms 127312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 100520 KB Output is correct
2 Correct 173 ms 115948 KB Output is correct
3 Correct 163 ms 93388 KB Output is correct
4 Correct 121 ms 93404 KB Output is correct
5 Correct 348 ms 163344 KB Output is correct
6 Correct 476 ms 146520 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 235 ms 116948 KB Output is correct
9 Correct 271 ms 138436 KB Output is correct
10 Correct 184 ms 100460 KB Output is correct
11 Correct 195 ms 115880 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 107 ms 93508 KB Output is correct
17 Correct 100 ms 93484 KB Output is correct
18 Correct 144 ms 100668 KB Output is correct
19 Correct 176 ms 115932 KB Output is correct
20 Correct 137 ms 100612 KB Output is correct
21 Correct 149 ms 114268 KB Output is correct
22 Correct 161 ms 100608 KB Output is correct
23 Correct 198 ms 114028 KB Output is correct
24 Correct 136 ms 93556 KB Output is correct
25 Correct 109 ms 93524 KB Output is correct
26 Correct 186 ms 93012 KB Output is correct
27 Correct 121 ms 99548 KB Output is correct
28 Correct 231 ms 109936 KB Output is correct
29 Correct 206 ms 109332 KB Output is correct
30 Correct 208 ms 109872 KB Output is correct
31 Correct 200 ms 109908 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 428 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 1088 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 856 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 28 ms 9704 KB Output is correct
49 Correct 31 ms 11092 KB Output is correct
50 Correct 40 ms 10676 KB Output is correct
51 Correct 29 ms 10776 KB Output is correct
52 Correct 27 ms 10528 KB Output is correct
53 Correct 62 ms 21196 KB Output is correct
54 Correct 6 ms 2396 KB Output is correct
55 Correct 22 ms 6692 KB Output is correct
56 Correct 2 ms 860 KB Output is correct
57 Correct 6 ms 2424 KB Output is correct
58 Correct 5 ms 3512 KB Output is correct
59 Correct 161 ms 50852 KB Output is correct
60 Correct 255 ms 74836 KB Output is correct
61 Correct 334 ms 65744 KB Output is correct
62 Correct 351 ms 65888 KB Output is correct
63 Correct 227 ms 71508 KB Output is correct
64 Correct 277 ms 65884 KB Output is correct
65 Correct 279 ms 66000 KB Output is correct
66 Correct 92 ms 27356 KB Output is correct
67 Correct 273 ms 70480 KB Output is correct
68 Correct 197 ms 109652 KB Output is correct
69 Correct 120 ms 63568 KB Output is correct
70 Correct 265 ms 126572 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 92 ms 93344 KB Output is correct
78 Correct 131 ms 93524 KB Output is correct
79 Correct 111 ms 93412 KB Output is correct
80 Correct 129 ms 93504 KB Output is correct
81 Correct 182 ms 110424 KB Output is correct
82 Correct 271 ms 126668 KB Output is correct
83 Correct 264 ms 127312 KB Output is correct
84 Correct 384 ms 147284 KB Output is correct
85 Correct 417 ms 154712 KB Output is correct
86 Correct 375 ms 135764 KB Output is correct
87 Correct 381 ms 145492 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 460 ms 145364 KB Output is correct
90 Correct 358 ms 147280 KB Output is correct
91 Correct 407 ms 151708 KB Output is correct