답안 #838443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838443 2023-08-27T00:06:09 Z 12345678 메기 농장 (IOI22_fish) C++17
100 / 100
481 ms 102836 KB
#include "fish.h"
 
#include <vector>
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 
const int nx=1e5+5;
ll mx;
vector<vector<pair<ll, ll>>> v(nx), dp(nx), mx1(nx), mx2(nx), mx3(nx);
 
ll get_val(ll col, ll row)
{
    return prev(upper_bound(v[col].begin(), v[col].end(), make_pair(row, LLONG_MAX)))->second;
}
 
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
  for (int i=0; i<M; i++) v[X[i]+1].push_back({Y[i]+1, W[i]});
  for (int i=0; i<=N+1  ; i++) v[i].push_back({0, 0}), sort(v[i].begin(), v[i].end());
  for (int i=1; i<=N; i++) for (int j=1; j<v[i].size(); j++) v[i][j].second+=v[i][j-1].second;
  mx1[0].push_back({0, 0}); mx2[0].push_back({N, -1e18}); mx3[0].push_back({0, 0});
  for (int i=1; i<=N; i++)
  {
    dp[i].push_back({0, 0});
    for (int j=1; j<v[i-1].size(); j++) dp[i].push_back({v[i-1][j].first, 0ll});
    for (int j=1; j<v[i+1].size(); j++) dp[i].push_back({v[i+1][j].first, 0ll});
    sort(dp[i].begin(), dp[i].end());
    for (int j=0; j<dp[i].size(); j++)
    {
      ll c=dp[i][j].first; dp[i][j].first=0;
      dp[i][j].first=max(dp[i][j].first, get_val(i+1, c)+get_val(i-1, c)+(prev(upper_bound(mx1[i-1].begin(), mx1[i-1].end(), make_pair(c, LLONG_MAX))))->second);
      dp[i][j].second=max(dp[i][j].second, get_val(i+1, c)-get_val(i, c)+(lower_bound(mx2[i-1].begin(), mx2[i-1].end(), make_pair(c, LLONG_MIN)))->second);
      if (i>=2) dp[i][j].first=max(dp[i][j].first, get_val(i+1, c)+(lower_bound(mx2[i-2].begin(), mx2[i-2].end(), make_pair(c, LLONG_MIN)))->second);
      if (i>=2) dp[i][j].first=max(dp[i][j].first, get_val(i+1, c)+get_val(i-1, c)+(prev(upper_bound(mx3[i-2].begin(), mx3[i-2].end(), make_pair(c, LLONG_MAX))))->second);
      mx1[i].push_back({c, dp[i][j].first-get_val(i, c)-get_val(i+1, c)});
      mx2[i].push_back({c, max(dp[i][j].first, dp[i][j].second)});
      mx3[i].push_back({c, max(dp[i][j].first, dp[i][j].second)-get_val(i+1, c)});
      //cout<<i<<' '<<c<<' '<<dp[i][j].first<<' '<<dp[i][j].second<<'\n';
      mx=max({mx, dp[i][j].first, dp[i][j].second});
    }
    for (int j=1; j<mx1[i].size(); j++) mx1[i][j].second=max(mx1[i][j].second, mx1[i][j-1].second);
    for (int j=mx1[i].size()-2; j>=0; j--) mx2[i][j].second=max(mx2[i][j].second, mx2[i][j+1].second);
    for (int j=1; j<mx1[i].size(); j++) mx3[i][j].second=max(mx3[i][j].second, mx3[i][j-1].second);
    mx2[i].push_back({N, -1e18});
  }
  return mx;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:22:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for (int i=1; i<=N; i++) for (int j=1; j<v[i].size(); j++) v[i][j].second+=v[i][j-1].second;
      |                                          ~^~~~~~~~~~~~
fish.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int j=1; j<v[i-1].size(); j++) dp[i].push_back({v[i-1][j].first, 0ll});
      |                   ~^~~~~~~~~~~~~~
fish.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int j=1; j<v[i+1].size(); j++) dp[i].push_back({v[i+1][j].first, 0ll});
      |                   ~^~~~~~~~~~~~~~
fish.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int j=0; j<dp[i].size(); j++)
      |                   ~^~~~~~~~~~~~~
fish.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int j=1; j<mx1[i].size(); j++) mx1[i][j].second=max(mx1[i][j].second, mx1[i][j-1].second);
      |                   ~^~~~~~~~~~~~~~
fish.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int j=1; j<mx1[i].size(); j++) mx3[i][j].second=max(mx3[i][j].second, mx3[i][j-1].second);
      |                   ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 36060 KB Output is correct
2 Correct 95 ms 41080 KB Output is correct
3 Correct 45 ms 29260 KB Output is correct
4 Correct 43 ms 29232 KB Output is correct
5 Correct 348 ms 82440 KB Output is correct
6 Correct 374 ms 102580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 193 ms 49444 KB Output is correct
3 Correct 217 ms 59388 KB Output is correct
4 Correct 81 ms 37176 KB Output is correct
5 Correct 96 ms 41152 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 5 ms 11988 KB Output is correct
8 Correct 5 ms 11988 KB Output is correct
9 Correct 6 ms 12048 KB Output is correct
10 Correct 43 ms 29172 KB Output is correct
11 Correct 44 ms 29196 KB Output is correct
12 Correct 110 ms 42284 KB Output is correct
13 Correct 129 ms 47408 KB Output is correct
14 Correct 106 ms 39908 KB Output is correct
15 Correct 123 ms 42920 KB Output is correct
16 Correct 101 ms 39712 KB Output is correct
17 Correct 115 ms 42752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 29188 KB Output is correct
2 Correct 41 ms 29132 KB Output is correct
3 Correct 86 ms 39652 KB Output is correct
4 Correct 71 ms 37140 KB Output is correct
5 Correct 129 ms 51680 KB Output is correct
6 Correct 118 ms 51660 KB Output is correct
7 Correct 128 ms 51564 KB Output is correct
8 Correct 122 ms 51572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12056 KB Output is correct
2 Correct 5 ms 11988 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Correct 6 ms 12116 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 11996 KB Output is correct
8 Correct 6 ms 12056 KB Output is correct
9 Correct 6 ms 12184 KB Output is correct
10 Correct 8 ms 12756 KB Output is correct
11 Correct 7 ms 12264 KB Output is correct
12 Correct 7 ms 12372 KB Output is correct
13 Correct 6 ms 12060 KB Output is correct
14 Correct 7 ms 12324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12056 KB Output is correct
2 Correct 5 ms 11988 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Correct 6 ms 12116 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 11996 KB Output is correct
8 Correct 6 ms 12056 KB Output is correct
9 Correct 6 ms 12184 KB Output is correct
10 Correct 8 ms 12756 KB Output is correct
11 Correct 7 ms 12264 KB Output is correct
12 Correct 7 ms 12372 KB Output is correct
13 Correct 6 ms 12060 KB Output is correct
14 Correct 7 ms 12324 KB Output is correct
15 Correct 6 ms 12056 KB Output is correct
16 Correct 9 ms 12404 KB Output is correct
17 Correct 66 ms 20420 KB Output is correct
18 Correct 66 ms 23836 KB Output is correct
19 Correct 62 ms 24424 KB Output is correct
20 Correct 56 ms 24396 KB Output is correct
21 Correct 56 ms 24468 KB Output is correct
22 Correct 114 ms 34240 KB Output is correct
23 Correct 17 ms 14240 KB Output is correct
24 Correct 47 ms 18600 KB Output is correct
25 Correct 7 ms 12316 KB Output is correct
26 Correct 16 ms 13956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12056 KB Output is correct
2 Correct 5 ms 11988 KB Output is correct
3 Correct 5 ms 11988 KB Output is correct
4 Correct 6 ms 12116 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 11996 KB Output is correct
8 Correct 6 ms 12056 KB Output is correct
9 Correct 6 ms 12184 KB Output is correct
10 Correct 8 ms 12756 KB Output is correct
11 Correct 7 ms 12264 KB Output is correct
12 Correct 7 ms 12372 KB Output is correct
13 Correct 6 ms 12060 KB Output is correct
14 Correct 7 ms 12324 KB Output is correct
15 Correct 6 ms 12056 KB Output is correct
16 Correct 9 ms 12404 KB Output is correct
17 Correct 66 ms 20420 KB Output is correct
18 Correct 66 ms 23836 KB Output is correct
19 Correct 62 ms 24424 KB Output is correct
20 Correct 56 ms 24396 KB Output is correct
21 Correct 56 ms 24468 KB Output is correct
22 Correct 114 ms 34240 KB Output is correct
23 Correct 17 ms 14240 KB Output is correct
24 Correct 47 ms 18600 KB Output is correct
25 Correct 7 ms 12316 KB Output is correct
26 Correct 16 ms 13956 KB Output is correct
27 Correct 9 ms 13192 KB Output is correct
28 Correct 298 ms 60032 KB Output is correct
29 Correct 390 ms 75636 KB Output is correct
30 Correct 417 ms 79640 KB Output is correct
31 Correct 439 ms 79668 KB Output is correct
32 Correct 361 ms 84924 KB Output is correct
33 Correct 438 ms 79580 KB Output is correct
34 Correct 440 ms 79680 KB Output is correct
35 Correct 156 ms 42324 KB Output is correct
36 Correct 443 ms 85428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 29188 KB Output is correct
2 Correct 41 ms 29132 KB Output is correct
3 Correct 86 ms 39652 KB Output is correct
4 Correct 71 ms 37140 KB Output is correct
5 Correct 129 ms 51680 KB Output is correct
6 Correct 118 ms 51660 KB Output is correct
7 Correct 128 ms 51564 KB Output is correct
8 Correct 122 ms 51572 KB Output is correct
9 Correct 123 ms 52528 KB Output is correct
10 Correct 99 ms 48808 KB Output is correct
11 Correct 203 ms 85488 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12012 KB Output is correct
14 Correct 5 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 6 ms 12004 KB Output is correct
17 Correct 5 ms 12056 KB Output is correct
18 Correct 41 ms 29220 KB Output is correct
19 Correct 41 ms 29176 KB Output is correct
20 Correct 42 ms 29224 KB Output is correct
21 Correct 41 ms 29200 KB Output is correct
22 Correct 161 ms 53128 KB Output is correct
23 Correct 211 ms 85532 KB Output is correct
24 Correct 202 ms 86068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 36060 KB Output is correct
2 Correct 95 ms 41080 KB Output is correct
3 Correct 45 ms 29260 KB Output is correct
4 Correct 43 ms 29232 KB Output is correct
5 Correct 348 ms 82440 KB Output is correct
6 Correct 374 ms 102580 KB Output is correct
7 Correct 7 ms 11988 KB Output is correct
8 Correct 193 ms 49444 KB Output is correct
9 Correct 217 ms 59388 KB Output is correct
10 Correct 81 ms 37176 KB Output is correct
11 Correct 96 ms 41152 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 5 ms 11988 KB Output is correct
14 Correct 5 ms 11988 KB Output is correct
15 Correct 6 ms 12048 KB Output is correct
16 Correct 43 ms 29172 KB Output is correct
17 Correct 44 ms 29196 KB Output is correct
18 Correct 110 ms 42284 KB Output is correct
19 Correct 129 ms 47408 KB Output is correct
20 Correct 106 ms 39908 KB Output is correct
21 Correct 123 ms 42920 KB Output is correct
22 Correct 101 ms 39712 KB Output is correct
23 Correct 115 ms 42752 KB Output is correct
24 Correct 40 ms 29188 KB Output is correct
25 Correct 41 ms 29132 KB Output is correct
26 Correct 86 ms 39652 KB Output is correct
27 Correct 71 ms 37140 KB Output is correct
28 Correct 129 ms 51680 KB Output is correct
29 Correct 118 ms 51660 KB Output is correct
30 Correct 128 ms 51564 KB Output is correct
31 Correct 122 ms 51572 KB Output is correct
32 Correct 6 ms 12056 KB Output is correct
33 Correct 5 ms 11988 KB Output is correct
34 Correct 5 ms 11988 KB Output is correct
35 Correct 6 ms 12116 KB Output is correct
36 Correct 6 ms 11988 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 6 ms 11996 KB Output is correct
39 Correct 6 ms 12056 KB Output is correct
40 Correct 6 ms 12184 KB Output is correct
41 Correct 8 ms 12756 KB Output is correct
42 Correct 7 ms 12264 KB Output is correct
43 Correct 7 ms 12372 KB Output is correct
44 Correct 6 ms 12060 KB Output is correct
45 Correct 7 ms 12324 KB Output is correct
46 Correct 6 ms 12056 KB Output is correct
47 Correct 9 ms 12404 KB Output is correct
48 Correct 66 ms 20420 KB Output is correct
49 Correct 66 ms 23836 KB Output is correct
50 Correct 62 ms 24424 KB Output is correct
51 Correct 56 ms 24396 KB Output is correct
52 Correct 56 ms 24468 KB Output is correct
53 Correct 114 ms 34240 KB Output is correct
54 Correct 17 ms 14240 KB Output is correct
55 Correct 47 ms 18600 KB Output is correct
56 Correct 7 ms 12316 KB Output is correct
57 Correct 16 ms 13956 KB Output is correct
58 Correct 9 ms 13192 KB Output is correct
59 Correct 298 ms 60032 KB Output is correct
60 Correct 390 ms 75636 KB Output is correct
61 Correct 417 ms 79640 KB Output is correct
62 Correct 439 ms 79668 KB Output is correct
63 Correct 361 ms 84924 KB Output is correct
64 Correct 438 ms 79580 KB Output is correct
65 Correct 440 ms 79680 KB Output is correct
66 Correct 156 ms 42324 KB Output is correct
67 Correct 443 ms 85428 KB Output is correct
68 Correct 123 ms 52528 KB Output is correct
69 Correct 99 ms 48808 KB Output is correct
70 Correct 203 ms 85488 KB Output is correct
71 Correct 6 ms 11988 KB Output is correct
72 Correct 6 ms 12012 KB Output is correct
73 Correct 5 ms 11988 KB Output is correct
74 Correct 6 ms 11988 KB Output is correct
75 Correct 6 ms 12004 KB Output is correct
76 Correct 5 ms 12056 KB Output is correct
77 Correct 41 ms 29220 KB Output is correct
78 Correct 41 ms 29176 KB Output is correct
79 Correct 42 ms 29224 KB Output is correct
80 Correct 41 ms 29200 KB Output is correct
81 Correct 161 ms 53128 KB Output is correct
82 Correct 211 ms 85532 KB Output is correct
83 Correct 202 ms 86068 KB Output is correct
84 Correct 480 ms 86388 KB Output is correct
85 Correct 481 ms 86788 KB Output is correct
86 Correct 392 ms 100924 KB Output is correct
87 Correct 394 ms 102836 KB Output is correct
88 Correct 5 ms 11988 KB Output is correct
89 Correct 402 ms 102816 KB Output is correct
90 Correct 402 ms 101788 KB Output is correct
91 Correct 359 ms 102268 KB Output is correct