답안 #629225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629225 2022-08-14T09:35:15 Z kdh9949 메기 농장 (IOI22_fish) C++17
100 / 100
523 ms 38252 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

using vint = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define x first
#define y second
#define all(v) (v).begin(),(v).end()

const int SZ = 131072;
const ll INF = ll(1e18);
struct Seg {
  ll d[2 * SZ];
  void u(int x, ll v) {
    for(x += SZ; x; x /= 2) d[x] = max(d[x], v);
  }
  ll g(int s = 0, int e = SZ - 1) {
    ll r = 0;
    for(s += SZ, e += SZ; s <= e; s /= 2, e /= 2) {
      if(s & 1) r = max(r, d[s++]);
      if(~e& 1) r = max(r, d[e--]);
    }
    return r;
  }
} U[3], D[3];

ll max_weights(int N, int M, vint X, vint Y, vint W) {
  vector<vpil> a(N);
  vector<vpll> d(N);
  for(int i = 0; i < M; i++) {
    a[X[i]].emplace_back(Y[i], W[i]);
    d[X[i]].emplace_back(-INF, -INF);
  }
  for(int i = 0; i < N; i++) sort(all(a[i]));

  for(int i = 0; i < N; i++) {
    for(int j = 1; j <= 2; j++) if(i - j >= 0)
      for(int k = 0; k < a[i - j].size(); k++) {
        U[j].u(a[i - j][k].x, d[i - j][k].x);
        D[j].u(a[i - j][k].x, d[i - j][k].y);
      }
    int K = a[i].size();
    if(i < N - 1) for(int j = 0; j < K; j++) {
      d[i][j].x = max(U[0].g(0, a[i][j].x - 1), D[1].g()) + a[i][j].y;
      U[0].u(a[i][j].x, d[i][j].x);
    }
    if(i) for(int j = K - 1; j >= 0; j--) {
      d[i][j].y = max({D[0].g(a[i][j].x + 1), U[2].g(), D[2].g()}) + a[i][j].y;
      D[0].u(a[i][j].x, d[i][j].y);
    }
  }

  ll ans = 0;
  for(auto &v : d) for(auto &p : v) ans = max({ans, p.x, p.y});
  return ans;
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, vint, vint, vint)':
fish.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |       for(int k = 0; k < a[i - j].size(); k++) {
      |                      ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 16308 KB Output is correct
2 Correct 74 ms 18644 KB Output is correct
3 Correct 4 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 220 ms 31472 KB Output is correct
6 Correct 479 ms 36460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 123 ms 22128 KB Output is correct
3 Correct 163 ms 25708 KB Output is correct
4 Correct 66 ms 16320 KB Output is correct
5 Correct 68 ms 18600 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 3 ms 5204 KB Output is correct
11 Correct 3 ms 5204 KB Output is correct
12 Correct 65 ms 17800 KB Output is correct
13 Correct 91 ms 20304 KB Output is correct
14 Correct 62 ms 17204 KB Output is correct
15 Correct 66 ms 15028 KB Output is correct
16 Correct 59 ms 17080 KB Output is correct
17 Correct 66 ms 18752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5204 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 51 ms 9408 KB Output is correct
4 Correct 33 ms 8760 KB Output is correct
5 Correct 98 ms 13924 KB Output is correct
6 Correct 115 ms 14412 KB Output is correct
7 Correct 111 ms 14388 KB Output is correct
8 Correct 150 ms 14336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 580 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 580 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 572 KB Output is correct
15 Correct 1 ms 564 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 30 ms 4040 KB Output is correct
18 Correct 48 ms 5308 KB Output is correct
19 Correct 40 ms 4976 KB Output is correct
20 Correct 45 ms 5060 KB Output is correct
21 Correct 40 ms 5028 KB Output is correct
22 Correct 79 ms 9560 KB Output is correct
23 Correct 7 ms 1340 KB Output is correct
24 Correct 21 ms 3028 KB Output is correct
25 Correct 2 ms 580 KB Output is correct
26 Correct 7 ms 1212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 580 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 572 KB Output is correct
15 Correct 1 ms 564 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 30 ms 4040 KB Output is correct
18 Correct 48 ms 5308 KB Output is correct
19 Correct 40 ms 4976 KB Output is correct
20 Correct 45 ms 5060 KB Output is correct
21 Correct 40 ms 5028 KB Output is correct
22 Correct 79 ms 9560 KB Output is correct
23 Correct 7 ms 1340 KB Output is correct
24 Correct 21 ms 3028 KB Output is correct
25 Correct 2 ms 580 KB Output is correct
26 Correct 7 ms 1212 KB Output is correct
27 Correct 5 ms 1236 KB Output is correct
28 Correct 148 ms 21140 KB Output is correct
29 Correct 291 ms 27972 KB Output is correct
30 Correct 219 ms 26656 KB Output is correct
31 Correct 218 ms 26772 KB Output is correct
32 Correct 236 ms 29652 KB Output is correct
33 Correct 228 ms 26732 KB Output is correct
34 Correct 260 ms 26052 KB Output is correct
35 Correct 93 ms 10980 KB Output is correct
36 Correct 250 ms 28032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5204 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 51 ms 9408 KB Output is correct
4 Correct 33 ms 8760 KB Output is correct
5 Correct 98 ms 13924 KB Output is correct
6 Correct 115 ms 14412 KB Output is correct
7 Correct 111 ms 14388 KB Output is correct
8 Correct 150 ms 14336 KB Output is correct
9 Correct 153 ms 23628 KB Output is correct
10 Correct 130 ms 10832 KB Output is correct
11 Correct 291 ms 21584 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 4 ms 5204 KB Output is correct
19 Correct 4 ms 5252 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 210 ms 22352 KB Output is correct
23 Correct 256 ms 20512 KB Output is correct
24 Correct 258 ms 22640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 16308 KB Output is correct
2 Correct 74 ms 18644 KB Output is correct
3 Correct 4 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 220 ms 31472 KB Output is correct
6 Correct 479 ms 36460 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 123 ms 22128 KB Output is correct
9 Correct 163 ms 25708 KB Output is correct
10 Correct 66 ms 16320 KB Output is correct
11 Correct 68 ms 18600 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 3 ms 5204 KB Output is correct
17 Correct 3 ms 5204 KB Output is correct
18 Correct 65 ms 17800 KB Output is correct
19 Correct 91 ms 20304 KB Output is correct
20 Correct 62 ms 17204 KB Output is correct
21 Correct 66 ms 15028 KB Output is correct
22 Correct 59 ms 17080 KB Output is correct
23 Correct 66 ms 18752 KB Output is correct
24 Correct 3 ms 5204 KB Output is correct
25 Correct 4 ms 4948 KB Output is correct
26 Correct 51 ms 9408 KB Output is correct
27 Correct 33 ms 8760 KB Output is correct
28 Correct 98 ms 13924 KB Output is correct
29 Correct 115 ms 14412 KB Output is correct
30 Correct 111 ms 14388 KB Output is correct
31 Correct 150 ms 14336 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 4 ms 724 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 3 ms 580 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 2 ms 572 KB Output is correct
46 Correct 1 ms 564 KB Output is correct
47 Correct 2 ms 724 KB Output is correct
48 Correct 30 ms 4040 KB Output is correct
49 Correct 48 ms 5308 KB Output is correct
50 Correct 40 ms 4976 KB Output is correct
51 Correct 45 ms 5060 KB Output is correct
52 Correct 40 ms 5028 KB Output is correct
53 Correct 79 ms 9560 KB Output is correct
54 Correct 7 ms 1340 KB Output is correct
55 Correct 21 ms 3028 KB Output is correct
56 Correct 2 ms 580 KB Output is correct
57 Correct 7 ms 1212 KB Output is correct
58 Correct 5 ms 1236 KB Output is correct
59 Correct 148 ms 21140 KB Output is correct
60 Correct 291 ms 27972 KB Output is correct
61 Correct 219 ms 26656 KB Output is correct
62 Correct 218 ms 26772 KB Output is correct
63 Correct 236 ms 29652 KB Output is correct
64 Correct 228 ms 26732 KB Output is correct
65 Correct 260 ms 26052 KB Output is correct
66 Correct 93 ms 10980 KB Output is correct
67 Correct 250 ms 28032 KB Output is correct
68 Correct 153 ms 23628 KB Output is correct
69 Correct 130 ms 10832 KB Output is correct
70 Correct 291 ms 21584 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 4 ms 5204 KB Output is correct
78 Correct 4 ms 5252 KB Output is correct
79 Correct 4 ms 4948 KB Output is correct
80 Correct 5 ms 4948 KB Output is correct
81 Correct 210 ms 22352 KB Output is correct
82 Correct 256 ms 20512 KB Output is correct
83 Correct 258 ms 22640 KB Output is correct
84 Correct 259 ms 32928 KB Output is correct
85 Correct 282 ms 34760 KB Output is correct
86 Correct 523 ms 36468 KB Output is correct
87 Correct 468 ms 37444 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 487 ms 38252 KB Output is correct
90 Correct 298 ms 27608 KB Output is correct
91 Correct 279 ms 27440 KB Output is correct