답안 #625404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625404 2022-08-10T11:27:56 Z model_code 메기 농장 (IOI22_fish) C++17
100 / 100
216 ms 39332 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int kUp = 0;
constexpr int kDown = 1;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  vector<vector<pair<int, int>>> fishes(N);

  for (int i = 0; i < M; ++i) {
    fishes[X[i]].push_back(make_pair(Y[i], i));
  }

  long long largest = 0;
  vector<pair<int, long long>> up, down;
  vector<vector<long long>> dp(M, vector<long long>(2, LLONG_MIN / 2));
  for (int x = 0; x < N; ++x) {
    sort(fishes[x].begin(), fishes[x].end());

    if (x > 0) {
      long long max_down = 0;
      for (int j = (int)fishes[x].size() - 1; j >= 0; --j) {
        int y = fishes[x][j].first;
        int i = fishes[x][j].second;
        while (down.size() > 0 && down.back().first > y) {
          max_down = max(max_down, down.back().second);
          down.pop_back();
        }

        long long &ret = dp[i][kDown];
        ret = largest + W[i];
        ret = max(ret, max_down + W[i]);
        if (j + 1 < static_cast<int>(fishes[x].size())) {
          ret = max(ret, dp[fishes[x][j + 1].second][kDown] + W[i]);
        }
      }
    }

    if (x >= 1) {
      for (auto [y, i] : fishes[x - 1]) {
        largest = max(largest, dp[i][kDown]);
      }
    }

    long long max_up = 0;
    for (int j = 0; j < static_cast<int>(fishes[x].size()); ++j) {
      int y = fishes[x][j].first;
      int i = fishes[x][j].second;
      while (up.size() > 0 && up.back().first < y) {
        max_up = max(max_up, up.back().second);
        up.pop_back();
      }

      long long &ret = dp[i][kUp];
      ret = largest + W[i];
      ret = max(ret, max_up + W[i]);
      if (j > 0) {
        ret = max(ret, dp[fishes[x][j - 1].second][kUp] + W[i]);
      }
    }

    if (x >= 1) {
      for (auto [y, i] : fishes[x - 1]) {
        largest = max(largest, dp[i][kUp]);
      }
    }

    down.clear();
    for (int j = 0; j < static_cast<int>(fishes[x].size()); ++j) {
      down.push_back(make_pair(fishes[x][j].first, dp[fishes[x][j].second][kDown]));
    }
    up.clear();
    for (int j = static_cast<int>(fishes[x].size()) - 1; j >= 0; --j) {
      up.push_back(make_pair(fishes[x][j].first, dp[fishes[x][j].second][kUp]));
    }  
  }

  long long answer = 0;
  for (int i = 0; i < M; ++i) {
    answer = max(answer, dp[i][kDown]);
    if (X[i] + 1 < N) {
      answer = max(answer, dp[i][kUp]);
    }
  }
  return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 15072 KB Output is correct
2 Correct 56 ms 17644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 213 ms 39332 KB Output is correct
6 Correct 193 ms 36784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 103 ms 23424 KB Output is correct
3 Correct 130 ms 27960 KB Output is correct
4 Correct 46 ms 15036 KB Output is correct
5 Correct 64 ms 17624 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 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 48 ms 15044 KB Output is correct
13 Correct 63 ms 17576 KB Output is correct
14 Correct 45 ms 12936 KB Output is correct
15 Correct 55 ms 14144 KB Output is correct
16 Correct 47 ms 12888 KB Output is correct
17 Correct 53 ms 14124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 29 ms 9116 KB Output is correct
4 Correct 20 ms 6864 KB Output is correct
5 Correct 59 ms 13768 KB Output is correct
6 Correct 59 ms 14504 KB Output is correct
7 Correct 61 ms 15012 KB Output is correct
8 Correct 59 ms 13512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 288 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 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 308 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 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 0 ms 288 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 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 308 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 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 2 ms 452 KB Output is correct
17 Correct 21 ms 4568 KB Output is correct
18 Correct 21 ms 5160 KB Output is correct
19 Correct 22 ms 4484 KB Output is correct
20 Correct 21 ms 4412 KB Output is correct
21 Correct 23 ms 5068 KB Output is correct
22 Correct 44 ms 8928 KB Output is correct
23 Correct 5 ms 1236 KB Output is correct
24 Correct 18 ms 3028 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 5 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 288 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 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 308 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 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 2 ms 452 KB Output is correct
17 Correct 21 ms 4568 KB Output is correct
18 Correct 21 ms 5160 KB Output is correct
19 Correct 22 ms 4484 KB Output is correct
20 Correct 21 ms 4412 KB Output is correct
21 Correct 23 ms 5068 KB Output is correct
22 Correct 44 ms 8928 KB Output is correct
23 Correct 5 ms 1236 KB Output is correct
24 Correct 18 ms 3028 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 5 ms 980 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 118 ms 23836 KB Output is correct
29 Correct 190 ms 32712 KB Output is correct
30 Correct 156 ms 28448 KB Output is correct
31 Correct 155 ms 31040 KB Output is correct
32 Correct 160 ms 28656 KB Output is correct
33 Correct 174 ms 30124 KB Output is correct
34 Correct 154 ms 26944 KB Output is correct
35 Correct 57 ms 10808 KB Output is correct
36 Correct 184 ms 27616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 29 ms 9116 KB Output is correct
4 Correct 20 ms 6864 KB Output is correct
5 Correct 59 ms 13768 KB Output is correct
6 Correct 59 ms 14504 KB Output is correct
7 Correct 61 ms 15012 KB Output is correct
8 Correct 59 ms 13512 KB Output is correct
9 Correct 59 ms 13512 KB Output is correct
10 Correct 53 ms 10864 KB Output is correct
11 Correct 127 ms 21444 KB Output is correct
12 Correct 0 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 0 ms 212 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 77 ms 12636 KB Output is correct
23 Correct 129 ms 21728 KB Output is correct
24 Correct 133 ms 21964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 15072 KB Output is correct
2 Correct 56 ms 17644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 213 ms 39332 KB Output is correct
6 Correct 193 ms 36784 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 103 ms 23424 KB Output is correct
9 Correct 130 ms 27960 KB Output is correct
10 Correct 46 ms 15036 KB Output is correct
11 Correct 64 ms 17624 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 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 48 ms 15044 KB Output is correct
19 Correct 63 ms 17576 KB Output is correct
20 Correct 45 ms 12936 KB Output is correct
21 Correct 55 ms 14144 KB Output is correct
22 Correct 47 ms 12888 KB Output is correct
23 Correct 53 ms 14124 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 29 ms 9116 KB Output is correct
27 Correct 20 ms 6864 KB Output is correct
28 Correct 59 ms 13768 KB Output is correct
29 Correct 59 ms 14504 KB Output is correct
30 Correct 61 ms 15012 KB Output is correct
31 Correct 59 ms 13512 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 288 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 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 308 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 312 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 2 ms 452 KB Output is correct
48 Correct 21 ms 4568 KB Output is correct
49 Correct 21 ms 5160 KB Output is correct
50 Correct 22 ms 4484 KB Output is correct
51 Correct 21 ms 4412 KB Output is correct
52 Correct 23 ms 5068 KB Output is correct
53 Correct 44 ms 8928 KB Output is correct
54 Correct 5 ms 1236 KB Output is correct
55 Correct 18 ms 3028 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 5 ms 980 KB Output is correct
58 Correct 2 ms 604 KB Output is correct
59 Correct 118 ms 23836 KB Output is correct
60 Correct 190 ms 32712 KB Output is correct
61 Correct 156 ms 28448 KB Output is correct
62 Correct 155 ms 31040 KB Output is correct
63 Correct 160 ms 28656 KB Output is correct
64 Correct 174 ms 30124 KB Output is correct
65 Correct 154 ms 26944 KB Output is correct
66 Correct 57 ms 10808 KB Output is correct
67 Correct 184 ms 27616 KB Output is correct
68 Correct 59 ms 13512 KB Output is correct
69 Correct 53 ms 10864 KB Output is correct
70 Correct 127 ms 21444 KB Output is correct
71 Correct 0 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 0 ms 212 KB Output is correct
77 Correct 2 ms 2644 KB Output is correct
78 Correct 2 ms 2644 KB Output is correct
79 Correct 2 ms 2644 KB Output is correct
80 Correct 3 ms 2644 KB Output is correct
81 Correct 77 ms 12636 KB Output is correct
82 Correct 129 ms 21728 KB Output is correct
83 Correct 133 ms 21964 KB Output is correct
84 Correct 216 ms 29768 KB Output is correct
85 Correct 207 ms 29832 KB Output is correct
86 Correct 194 ms 30072 KB Output is correct
87 Correct 206 ms 30672 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 195 ms 30716 KB Output is correct
90 Correct 173 ms 30048 KB Output is correct
91 Correct 192 ms 29800 KB Output is correct