답안 #626663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626663 2022-08-11T15:35:45 Z ITO 메기 농장 (IOI22_fish) C++17
100 / 100
166 ms 22260 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  vector<vector<pair<int, ll>>> v(N, vector<pair<int, ll>>(0));
  vector<ll> ru[2], rd[2];
  int p0 = 1, p1 = 0;
  ll co = 0;

  for (int i = 0; i < M; i++) {
    v[X[i]].push_back({Y[i], W[i]});
  }
  for (int i = 0; i < N; i++) {
    v[i].push_back({0, 0});
    v[i].push_back({N, 0});
    sort(v[i].begin(), v[i].end());
    for (int j = 1; j < v[i].size(); j++) v[i][j].second += v[i][j - 1].second;
  }
  for (int j = 0; j < v[0].size(); j++) {
    ru[0].push_back(0);
    rd[0].push_back(0);
  }
  for (int i = 1; i < N; i++) {
    ru[p0].clear();
    rd[p0].clear();
    int j, k = 1;
    ll te = ru[p1][0];
    for (j = 0; j < v[i].size(); j++) {
      while (k < v[i - 1].size() && v[i - 1][k].first <= v[i][j].first) {
        te = max(te, ru[p1][k] - v[i - 1][k - 1].second);
        k++;
      }
      if (k >= 2 && v[i - 1][k - 1].first == v[i][j].first) {
        ru[p0].push_back(max(te + v[i - 1][k - 2].second, rd[p1][0]));
      } else {
        ru[p0].push_back(max(te + v[i - 1][k - 1].second, rd[p1][0]));
      }
      rd[p0].push_back(ru[p0].back());
    }
    k = v[i - 1].size() - 2;
    te = rd[p1].back() + v[i].back().second;
    for (j = v[i].size() - 1; j > 0; j--) {
      while (k >= 0 && v[i - 1][k].first >= v[i][j].first) {
        if (v[i - 1][k].first > v[i][j].first) {
          te = max(te, rd[p1][k] + v[i][j].second);
        } else {
          te = max(te, rd[p1][k] + v[i][j - 1].second);
        }
        k--;
      }
      rd[p0][j] = max(rd[p0][j], te - v[i][j - 1].second);
    }
    while (k >= 0 && v[i - 1][k].first >= v[i][j].first) {
      te = max(te, rd[p1][k]);
      k--;
    }
    rd[p0][0] = max(rd[p0][0], te);
    swap(p0, p1);
  }
  for (int i = 0; i < ru[p1].size(); i++) co = max(co, max(ru[p1][i], rd[p1][i]));
  return co;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:20:23: 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]
   20 |     for (int j = 1; j < v[i].size(); j++) v[i][j].second += v[i][j - 1].second;
      |                     ~~^~~~~~~~~~~~~
fish.cpp:22:21: 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]
   22 |   for (int j = 0; j < v[0].size(); j++) {
      |                   ~~^~~~~~~~~~~~~
fish.cpp:31:19: 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]
   31 |     for (j = 0; j < v[i].size(); j++) {
      |                 ~~^~~~~~~~~~~~~
fish.cpp:32:16: 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]
   32 |       while (k < v[i - 1].size() && v[i - 1][k].first <= v[i][j].first) {
      |              ~~^~~~~~~~~~~~~~~~~
fish.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for (int i = 0; i < ru[p1].size(); i++) co = max(co, max(ru[p1][i], rd[p1][i]));
      |                   ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 12348 KB Output is correct
2 Correct 56 ms 14140 KB Output is correct
3 Correct 19 ms 7260 KB Output is correct
4 Correct 17 ms 7288 KB Output is correct
5 Correct 122 ms 21828 KB Output is correct
6 Correct 144 ms 21584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 91 ms 16836 KB Output is correct
3 Correct 100 ms 19696 KB Output is correct
4 Correct 44 ms 12380 KB Output is correct
5 Correct 54 ms 14140 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 1 ms 212 KB Output is correct
10 Correct 15 ms 7340 KB Output is correct
11 Correct 15 ms 7252 KB Output is correct
12 Correct 45 ms 12360 KB Output is correct
13 Correct 56 ms 14132 KB Output is correct
14 Correct 48 ms 12160 KB Output is correct
15 Correct 53 ms 13240 KB Output is correct
16 Correct 45 ms 12088 KB Output is correct
17 Correct 48 ms 13284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7252 KB Output is correct
2 Correct 16 ms 7252 KB Output is correct
3 Correct 35 ms 10028 KB Output is correct
4 Correct 32 ms 9564 KB Output is correct
5 Correct 59 ms 13516 KB Output is correct
6 Correct 58 ms 13508 KB Output is correct
7 Correct 58 ms 13524 KB Output is correct
8 Correct 54 ms 13520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 15 ms 2260 KB Output is correct
18 Correct 14 ms 2900 KB Output is correct
19 Correct 14 ms 2776 KB Output is correct
20 Correct 19 ms 2644 KB Output is correct
21 Correct 14 ms 2644 KB Output is correct
22 Correct 28 ms 5076 KB Output is correct
23 Correct 3 ms 736 KB Output is correct
24 Correct 10 ms 1672 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 15 ms 2260 KB Output is correct
18 Correct 14 ms 2900 KB Output is correct
19 Correct 14 ms 2776 KB Output is correct
20 Correct 19 ms 2644 KB Output is correct
21 Correct 14 ms 2644 KB Output is correct
22 Correct 28 ms 5076 KB Output is correct
23 Correct 3 ms 736 KB Output is correct
24 Correct 10 ms 1672 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 70 ms 11016 KB Output is correct
29 Correct 106 ms 14696 KB Output is correct
30 Correct 103 ms 14064 KB Output is correct
31 Correct 107 ms 14180 KB Output is correct
32 Correct 98 ms 15972 KB Output is correct
33 Correct 106 ms 14056 KB Output is correct
34 Correct 107 ms 14064 KB Output is correct
35 Correct 42 ms 6304 KB Output is correct
36 Correct 102 ms 16100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7252 KB Output is correct
2 Correct 16 ms 7252 KB Output is correct
3 Correct 35 ms 10028 KB Output is correct
4 Correct 32 ms 9564 KB Output is correct
5 Correct 59 ms 13516 KB Output is correct
6 Correct 58 ms 13508 KB Output is correct
7 Correct 58 ms 13524 KB Output is correct
8 Correct 54 ms 13520 KB Output is correct
9 Correct 54 ms 13448 KB Output is correct
10 Correct 49 ms 8260 KB Output is correct
11 Correct 101 ms 16348 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 19 ms 7252 KB Output is correct
19 Correct 17 ms 7252 KB Output is correct
20 Correct 16 ms 7352 KB Output is correct
21 Correct 15 ms 7332 KB Output is correct
22 Correct 54 ms 12080 KB Output is correct
23 Correct 99 ms 16352 KB Output is correct
24 Correct 96 ms 16356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 12348 KB Output is correct
2 Correct 56 ms 14140 KB Output is correct
3 Correct 19 ms 7260 KB Output is correct
4 Correct 17 ms 7288 KB Output is correct
5 Correct 122 ms 21828 KB Output is correct
6 Correct 144 ms 21584 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 91 ms 16836 KB Output is correct
9 Correct 100 ms 19696 KB Output is correct
10 Correct 44 ms 12380 KB Output is correct
11 Correct 54 ms 14140 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 1 ms 212 KB Output is correct
16 Correct 15 ms 7340 KB Output is correct
17 Correct 15 ms 7252 KB Output is correct
18 Correct 45 ms 12360 KB Output is correct
19 Correct 56 ms 14132 KB Output is correct
20 Correct 48 ms 12160 KB Output is correct
21 Correct 53 ms 13240 KB Output is correct
22 Correct 45 ms 12088 KB Output is correct
23 Correct 48 ms 13284 KB Output is correct
24 Correct 15 ms 7252 KB Output is correct
25 Correct 16 ms 7252 KB Output is correct
26 Correct 35 ms 10028 KB Output is correct
27 Correct 32 ms 9564 KB Output is correct
28 Correct 59 ms 13516 KB Output is correct
29 Correct 58 ms 13508 KB Output is correct
30 Correct 58 ms 13524 KB Output is correct
31 Correct 54 ms 13520 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 15 ms 2260 KB Output is correct
49 Correct 14 ms 2900 KB Output is correct
50 Correct 14 ms 2776 KB Output is correct
51 Correct 19 ms 2644 KB Output is correct
52 Correct 14 ms 2644 KB Output is correct
53 Correct 28 ms 5076 KB Output is correct
54 Correct 3 ms 736 KB Output is correct
55 Correct 10 ms 1672 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
59 Correct 70 ms 11016 KB Output is correct
60 Correct 106 ms 14696 KB Output is correct
61 Correct 103 ms 14064 KB Output is correct
62 Correct 107 ms 14180 KB Output is correct
63 Correct 98 ms 15972 KB Output is correct
64 Correct 106 ms 14056 KB Output is correct
65 Correct 107 ms 14064 KB Output is correct
66 Correct 42 ms 6304 KB Output is correct
67 Correct 102 ms 16100 KB Output is correct
68 Correct 54 ms 13448 KB Output is correct
69 Correct 49 ms 8260 KB Output is correct
70 Correct 101 ms 16348 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 19 ms 7252 KB Output is correct
78 Correct 17 ms 7252 KB Output is correct
79 Correct 16 ms 7352 KB Output is correct
80 Correct 15 ms 7332 KB Output is correct
81 Correct 54 ms 12080 KB Output is correct
82 Correct 99 ms 16352 KB Output is correct
83 Correct 96 ms 16356 KB Output is correct
84 Correct 129 ms 19672 KB Output is correct
85 Correct 139 ms 20244 KB Output is correct
86 Correct 166 ms 21580 KB Output is correct
87 Correct 152 ms 22248 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 147 ms 22260 KB Output is correct
90 Correct 134 ms 21336 KB Output is correct
91 Correct 141 ms 21472 KB Output is correct