답안 #791029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791029 2023-07-23T11:01:48 Z penguinman 메기 농장 (IOI22_fish) C++17
100 / 100
452 ms 71252 KB
#include "fish.h"

#include <bits/stdc++.h>

using std::vector;
using std::string;
using std::cin;
using std::cout;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define ln "\n"
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define all(a) a.begin(), a.end()
#define mp std::make_pair
#define pb emplace_back
constexpr ll inf = (1ll<<60);

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
  // task 6
  rep(i,0,M) X[i]++, Y[i]++;
  // data1 : その行
  // data2 : 隣接
  vector<vector<pii>> data1(N+2), data2(N+2);
  rep(i,0,M){
    data1[X[i]].pb(mp(Y[i],W[i]));
    if(X[i]-1) data2[X[i]-1].pb(mp(Y[i],W[i]));
    if(X[i]+1 <= N) data2[X[i]+1].pb(mp(Y[i],W[i]));
  }
  vii sum(N+2);
  rep(i,0,N+2){
    data1[i].pb(mp(0,0));
    data2[i].pb(mp(0,0));
    sort(all(data1[i]));
    sort(all(data2[i]));
    sum[i].resize(data1[i].size());
    rep(j,1,data1[i].size()) sum[i][j] = sum[i][j-1]+data1[i][j].second;
  }
  auto id = [&](ll x, ll height){
    ll idx = std::upper_bound(all(data1[x]), mp(height, inf))-data1[x].begin();
    idx--;
    return idx;
  };
  auto calc = [&](ll x, ll height){
    ll idx = std::upper_bound(all(data1[x]), mp(height, inf))-data1[x].begin();
    idx--;
    return sum[x][idx];
  };
  vii up(N+2), down(N+2);
  up[0].resize(1);
  down[0].resize(1);
  up[0][0] = down[0][0] = 0;
  rep(i,1,N+2){
    up[i].resize(data2[i].size(),-inf);
    down[i].resize(data2[i].size(),-inf);
    {
      vi max(data2[i-1].size());
      rep(j,0,data2[i-1].size()){
        max[j] = up[i-1][j]-calc(i-1, data2[i-1][j].first);
        if(j) max[j] = std::max(max[j], max[j-1]);
      }
      rep(j,0,data2[i].size()){
        ll idx = upper_bound(all(data2[i-1]), data2[i][j])-data2[i-1].begin();
        if(idx) up[i][j] = std::max(up[i][j], max[idx-1]+calc(i-1, data2[i][j].first));
      }
    }
    {
      vi max(data2[i-1].size());
      per(j,data2[i-1].size()-1,0){
        max[j] = down[i-1][j]+calc(i, data2[i-1][j].first);
        if(j+1 < data2[i-1].size()) max[j] = std::max(max[j], max[j+1]);
      }
      rep(j,0,data2[i].size()){
        ll idx = lower_bound(all(data2[i-1]), data2[i][j])-data2[i-1].begin();
        if(idx < data2[i-1].size()) down[i][j] = std::max(down[i][j], max[idx]-calc(i, data2[i][j].first));
      }
    }
    if(i-2 >= 0){
      vi max(data2[i-2].size());
      per(j,data2[i-2].size()-1,0){
        max[j] = down[i-2][j]+calc(i-1, data2[i-2][j].first);
        if(j+1 < data2[i-2].size()) max[j] = std::max(max[j], max[j+1]);
      }
      rep(j,0,data2[i].size()){
        ll idx = lower_bound(all(data2[i-2]), data2[i][j])-data2[i-2].begin();
        if(idx < data2[i-2].size()) up[i][j] = std::max(up[i][j], max[idx]);
      }
    }
    if(i-2 >= 0){
      vi max(data2[i-2].size());
      rep(j,0,data2[i-2].size()){
        max[j] = down[i-2][j];
        if(j) max[j] = std::max(max[j], max[j-1]);
      }
      rep(j,0,data2[i].size()){
        ll idx = upper_bound(all(data2[i-2]), data2[i][j])-data2[i-2].begin();
        if(idx) up[i][j] = std::max(up[i][j], max[idx-1]+calc(i-1, data2[i][j].first));
      }
    }
    if(i-3 >= 0){
      ll max = 0;
      rep(k,0,data2[i-3].size()){
        max = std::max(max, down[i-3][k]+calc(i-2, data2[i-3][k].first));
      }
      rep(j,0,data2[i].size()){
        up[i][j] = std::max(up[i][j], max+calc(i-1,data2[i][j].first));
      }
    }
    rep(j,0,data2[i].size()) down[i][j] = std::max(down[i][j], up[i][j]);
  }
  ll ans = std::max(up[N+1][0], down[N+1][0]);
  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:74:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         if(j+1 < data2[i-1].size()) max[j] = std::max(max[j], max[j+1]);
      |            ~~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:78:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         if(idx < data2[i-1].size()) down[i][j] = std::max(down[i][j], max[idx]-calc(i, data2[i][j].first));
      |            ~~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:85:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         if(j+1 < data2[i-2].size()) max[j] = std::max(max[j], max[j+1]);
      |            ~~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:89:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         if(idx < data2[i-2].size()) up[i][j] = std::max(up[i][j], max[idx]);
      |            ~~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:42:8: warning: variable 'id' set but not used [-Wunused-but-set-variable]
   42 |   auto id = [&](ll x, ll height){
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 31280 KB Output is correct
2 Correct 98 ms 35488 KB Output is correct
3 Correct 46 ms 27600 KB Output is correct
4 Correct 50 ms 27756 KB Output is correct
5 Correct 335 ms 61028 KB Output is correct
6 Correct 335 ms 71252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 199 ms 40200 KB Output is correct
3 Correct 224 ms 46428 KB Output is correct
4 Correct 93 ms 31292 KB Output is correct
5 Correct 105 ms 35508 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 45 ms 27600 KB Output is correct
11 Correct 48 ms 27644 KB Output is correct
12 Correct 116 ms 33784 KB Output is correct
13 Correct 139 ms 40304 KB Output is correct
14 Correct 105 ms 33940 KB Output is correct
15 Correct 128 ms 37712 KB Output is correct
16 Correct 106 ms 33992 KB Output is correct
17 Correct 117 ms 37632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 27596 KB Output is correct
2 Correct 47 ms 27676 KB Output is correct
3 Correct 80 ms 29440 KB Output is correct
4 Correct 75 ms 31252 KB Output is correct
5 Correct 122 ms 37928 KB Output is correct
6 Correct 115 ms 37260 KB Output is correct
7 Correct 131 ms 37796 KB Output is correct
8 Correct 122 ms 37840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 276 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 276 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 61 ms 5532 KB Output is correct
18 Correct 63 ms 7564 KB Output is correct
19 Correct 57 ms 7500 KB Output is correct
20 Correct 60 ms 7596 KB Output is correct
21 Correct 59 ms 7588 KB Output is correct
22 Correct 128 ms 14284 KB Output is correct
23 Correct 11 ms 1588 KB Output is correct
24 Correct 41 ms 4500 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 11 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 276 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 61 ms 5532 KB Output is correct
18 Correct 63 ms 7564 KB Output is correct
19 Correct 57 ms 7500 KB Output is correct
20 Correct 60 ms 7596 KB Output is correct
21 Correct 59 ms 7588 KB Output is correct
22 Correct 128 ms 14284 KB Output is correct
23 Correct 11 ms 1588 KB Output is correct
24 Correct 41 ms 4500 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 11 ms 1528 KB Output is correct
27 Correct 3 ms 1364 KB Output is correct
28 Correct 310 ms 32528 KB Output is correct
29 Correct 401 ms 44768 KB Output is correct
30 Correct 373 ms 43472 KB Output is correct
31 Correct 387 ms 43440 KB Output is correct
32 Correct 419 ms 46368 KB Output is correct
33 Correct 383 ms 43448 KB Output is correct
34 Correct 389 ms 43516 KB Output is correct
35 Correct 141 ms 18484 KB Output is correct
36 Correct 413 ms 45612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 27596 KB Output is correct
2 Correct 47 ms 27676 KB Output is correct
3 Correct 80 ms 29440 KB Output is correct
4 Correct 75 ms 31252 KB Output is correct
5 Correct 122 ms 37928 KB Output is correct
6 Correct 115 ms 37260 KB Output is correct
7 Correct 131 ms 37796 KB Output is correct
8 Correct 122 ms 37840 KB Output is correct
9 Correct 166 ms 37580 KB Output is correct
10 Correct 94 ms 28040 KB Output is correct
11 Correct 218 ms 55968 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 52 ms 27684 KB Output is correct
19 Correct 44 ms 27604 KB Output is correct
20 Correct 44 ms 27596 KB Output is correct
21 Correct 45 ms 27676 KB Output is correct
22 Correct 153 ms 39492 KB Output is correct
23 Correct 232 ms 55896 KB Output is correct
24 Correct 270 ms 56536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 31280 KB Output is correct
2 Correct 98 ms 35488 KB Output is correct
3 Correct 46 ms 27600 KB Output is correct
4 Correct 50 ms 27756 KB Output is correct
5 Correct 335 ms 61028 KB Output is correct
6 Correct 335 ms 71252 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 199 ms 40200 KB Output is correct
9 Correct 224 ms 46428 KB Output is correct
10 Correct 93 ms 31292 KB Output is correct
11 Correct 105 ms 35508 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 45 ms 27600 KB Output is correct
17 Correct 48 ms 27644 KB Output is correct
18 Correct 116 ms 33784 KB Output is correct
19 Correct 139 ms 40304 KB Output is correct
20 Correct 105 ms 33940 KB Output is correct
21 Correct 128 ms 37712 KB Output is correct
22 Correct 106 ms 33992 KB Output is correct
23 Correct 117 ms 37632 KB Output is correct
24 Correct 45 ms 27596 KB Output is correct
25 Correct 47 ms 27676 KB Output is correct
26 Correct 80 ms 29440 KB Output is correct
27 Correct 75 ms 31252 KB Output is correct
28 Correct 122 ms 37928 KB Output is correct
29 Correct 115 ms 37260 KB Output is correct
30 Correct 131 ms 37796 KB Output is correct
31 Correct 122 ms 37840 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 276 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 61 ms 5532 KB Output is correct
49 Correct 63 ms 7564 KB Output is correct
50 Correct 57 ms 7500 KB Output is correct
51 Correct 60 ms 7596 KB Output is correct
52 Correct 59 ms 7588 KB Output is correct
53 Correct 128 ms 14284 KB Output is correct
54 Correct 11 ms 1588 KB Output is correct
55 Correct 41 ms 4500 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 11 ms 1528 KB Output is correct
58 Correct 3 ms 1364 KB Output is correct
59 Correct 310 ms 32528 KB Output is correct
60 Correct 401 ms 44768 KB Output is correct
61 Correct 373 ms 43472 KB Output is correct
62 Correct 387 ms 43440 KB Output is correct
63 Correct 419 ms 46368 KB Output is correct
64 Correct 383 ms 43448 KB Output is correct
65 Correct 389 ms 43516 KB Output is correct
66 Correct 141 ms 18484 KB Output is correct
67 Correct 413 ms 45612 KB Output is correct
68 Correct 166 ms 37580 KB Output is correct
69 Correct 94 ms 28040 KB Output is correct
70 Correct 218 ms 55968 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 300 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 52 ms 27684 KB Output is correct
78 Correct 44 ms 27604 KB Output is correct
79 Correct 44 ms 27596 KB Output is correct
80 Correct 45 ms 27676 KB Output is correct
81 Correct 153 ms 39492 KB Output is correct
82 Correct 232 ms 55896 KB Output is correct
83 Correct 270 ms 56536 KB Output is correct
84 Correct 442 ms 66584 KB Output is correct
85 Correct 452 ms 68252 KB Output is correct
86 Correct 392 ms 66360 KB Output is correct
87 Correct 392 ms 68956 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 384 ms 68936 KB Output is correct
90 Correct 389 ms 70076 KB Output is correct
91 Correct 393 ms 70880 KB Output is correct