답안 #908631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908631 2024-01-16T15:39:30 Z vjudge1 메기 농장 (IOI22_fish) C++17
100 / 100
171 ms 33100 KB
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

enum {
    UP = 0,
    DOWN = 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);

  F(i, 0, M) fishes[X[i]].push_back(make_pair(Y[i], i));

  long long largest = 0;
  vector<pl> up, down;
  vector<vl> dp(M, vl(2, -1e18));

  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].V;
        while (down.size() > 0 && down.back().first > y) {
          max_down = max(max_down, down.back().V);
          down.pop_back();
        }

        long long &ret = dp[i][DOWN];
        ret = largest + W[i];
        ret = max(ret, max_down + W[i]);
        if (j + 1 < fishes[x].size()) {
          ret = max(ret, dp[fishes[x][j + 1].V][DOWN] + W[i]);
        }
      }
    }

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

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

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

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

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

  long long answer = 0;
  for (int i = 0; i < M; ++i) {
    answer = max(answer, dp[i][DOWN]);
    if (X[i] + 1 < N) {
      answer = max(answer, dp[i][UP]);
    }
  }

  return answer;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         if (j + 1 < fishes[x].size()) {
      |             ~~~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for (int j = 0; j < fishes[x].size(); ++j) {
      |                     ~~^~~~~~~~~~~~~~~~~~
fish.cpp:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for (int j = 0; j < fishes[x].size(); ++j) {
      |                     ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 13636 KB Output is correct
2 Correct 48 ms 15940 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 157 ms 33100 KB Output is correct
6 Correct 149 ms 30292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 76 ms 20700 KB Output is correct
3 Correct 100 ms 24532 KB Output is correct
4 Correct 36 ms 14020 KB Output is correct
5 Correct 43 ms 15940 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 44 ms 13684 KB Output is correct
13 Correct 44 ms 15876 KB Output is correct
14 Correct 35 ms 11480 KB Output is correct
15 Correct 39 ms 12608 KB Output is correct
16 Correct 35 ms 11600 KB Output is correct
17 Correct 39 ms 12680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2728 KB Output is correct
3 Correct 23 ms 8284 KB Output is correct
4 Correct 17 ms 6704 KB Output is correct
5 Correct 48 ms 13648 KB Output is correct
6 Correct 57 ms 13740 KB Output is correct
7 Correct 45 ms 13652 KB Output is correct
8 Correct 47 ms 13652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 16 ms 4444 KB Output is correct
18 Correct 16 ms 4444 KB Output is correct
19 Correct 19 ms 4444 KB Output is correct
20 Correct 16 ms 4440 KB Output is correct
21 Correct 16 ms 4444 KB Output is correct
22 Correct 33 ms 8540 KB Output is correct
23 Correct 4 ms 1116 KB Output is correct
24 Correct 16 ms 3088 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 16 ms 4444 KB Output is correct
18 Correct 16 ms 4444 KB Output is correct
19 Correct 19 ms 4444 KB Output is correct
20 Correct 16 ms 4440 KB Output is correct
21 Correct 16 ms 4444 KB Output is correct
22 Correct 33 ms 8540 KB Output is correct
23 Correct 4 ms 1116 KB Output is correct
24 Correct 16 ms 3088 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 1116 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 85 ms 20304 KB Output is correct
29 Correct 145 ms 27668 KB Output is correct
30 Correct 135 ms 26996 KB Output is correct
31 Correct 129 ms 26964 KB Output is correct
32 Correct 136 ms 28240 KB Output is correct
33 Correct 129 ms 26996 KB Output is correct
34 Correct 129 ms 27072 KB Output is correct
35 Correct 45 ms 10832 KB Output is correct
36 Correct 128 ms 27732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2728 KB Output is correct
3 Correct 23 ms 8284 KB Output is correct
4 Correct 17 ms 6704 KB Output is correct
5 Correct 48 ms 13648 KB Output is correct
6 Correct 57 ms 13740 KB Output is correct
7 Correct 45 ms 13652 KB Output is correct
8 Correct 47 ms 13652 KB Output is correct
9 Correct 52 ms 13904 KB Output is correct
10 Correct 43 ms 10836 KB Output is correct
11 Correct 109 ms 21588 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 43 ms 12620 KB Output is correct
23 Correct 105 ms 21576 KB Output is correct
24 Correct 105 ms 21568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 13636 KB Output is correct
2 Correct 48 ms 15940 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 157 ms 33100 KB Output is correct
6 Correct 149 ms 30292 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 76 ms 20700 KB Output is correct
9 Correct 100 ms 24532 KB Output is correct
10 Correct 36 ms 14020 KB Output is correct
11 Correct 43 ms 15940 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2648 KB Output is correct
18 Correct 44 ms 13684 KB Output is correct
19 Correct 44 ms 15876 KB Output is correct
20 Correct 35 ms 11480 KB Output is correct
21 Correct 39 ms 12608 KB Output is correct
22 Correct 35 ms 11600 KB Output is correct
23 Correct 39 ms 12680 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2728 KB Output is correct
26 Correct 23 ms 8284 KB Output is correct
27 Correct 17 ms 6704 KB Output is correct
28 Correct 48 ms 13648 KB Output is correct
29 Correct 57 ms 13740 KB Output is correct
30 Correct 45 ms 13652 KB Output is correct
31 Correct 47 ms 13652 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 440 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 600 KB Output is correct
48 Correct 16 ms 4444 KB Output is correct
49 Correct 16 ms 4444 KB Output is correct
50 Correct 19 ms 4444 KB Output is correct
51 Correct 16 ms 4440 KB Output is correct
52 Correct 16 ms 4444 KB Output is correct
53 Correct 33 ms 8540 KB Output is correct
54 Correct 4 ms 1116 KB Output is correct
55 Correct 16 ms 3088 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 4 ms 1116 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 85 ms 20304 KB Output is correct
60 Correct 145 ms 27668 KB Output is correct
61 Correct 135 ms 26996 KB Output is correct
62 Correct 129 ms 26964 KB Output is correct
63 Correct 136 ms 28240 KB Output is correct
64 Correct 129 ms 26996 KB Output is correct
65 Correct 129 ms 27072 KB Output is correct
66 Correct 45 ms 10832 KB Output is correct
67 Correct 128 ms 27732 KB Output is correct
68 Correct 52 ms 13904 KB Output is correct
69 Correct 43 ms 10836 KB Output is correct
70 Correct 109 ms 21588 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 2 ms 2652 KB Output is correct
78 Correct 1 ms 2652 KB Output is correct
79 Correct 2 ms 2652 KB Output is correct
80 Correct 2 ms 2652 KB Output is correct
81 Correct 43 ms 12620 KB Output is correct
82 Correct 105 ms 21576 KB Output is correct
83 Correct 105 ms 21568 KB Output is correct
84 Correct 137 ms 29764 KB Output is correct
85 Correct 147 ms 29920 KB Output is correct
86 Correct 170 ms 30228 KB Output is correct
87 Correct 171 ms 30544 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 167 ms 30568 KB Output is correct
90 Correct 154 ms 30056 KB Output is correct
91 Correct 139 ms 29944 KB Output is correct