답안 #922405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922405 2024-02-05T13:27:06 Z AkibAzmain 메기 농장 (IOI22_fish) C++17
100 / 100
834 ms 53728 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

long long max_weights(int n, int m, std::vector<int> fx, std::vector<int> fy,
                      std::vector<int> fw)
{
  n += 2;
  vector < map < int, ll > > a (n);
  for (int i = 0; i < m; ++i) a[fx[i] + 1][fy[i]] += fw[i];
  ll mxdp = 0;
  vector < vector < pair < int, ll > > > p (3), q (2), dp (3);
  for (int i = 2; i < n; ++i)
    {
      set < int > is;
      for (int j = 0; j < 3; ++j) for (auto &x : a[i - j]) is.insert (x.first);
      ll ls = 0, rs = 0, ms = 0;
      ll mxp = -1e18, mxq = -1e18;
      ll id = -1;
      stack < int > st;
      auto itp = p[2].begin ();
      auto itq = q[1].begin ();
      for (auto &x : is)
        {
          st.push (x);
          ls += a[i - 2].count (x) ? a[i - 2][x] : 0ll;
          ms += a[i - 1].count (x) ? a[i - 1][x] : 0ll;
          rs += a[i].count (x) ? a[i][x] : 0ll;
          if (a[i].count (x) + a[i - 2].count (x) == 0) continue;
          dp[0].push_back ({ x, 0 });
          p[0].push_back ({ x, 0 });
          q[0].push_back ({ x, 0 });
          ++id;
          dp[0][id].second = ls + rs + mxdp;
          while (itp != p[2].end () && itp->first <= x)
            mxp = max (mxp, itp->second), ++itp;
          while (itq != q[1].end () && itq->first <= x)
            mxq = max (mxq, itq->second), ++itq;
          dp[0][id].second = max (dp[0][id].second, ls + rs + mxp);
          dp[0][id].second = max (dp[0][id].second, ls + rs + mxq);
        }
      mxp = -1e18, mxq = -1e18;
      auto ritp = dp[2].rbegin (), ritq = dp[1].rbegin ();
      while (st.size ())
        {
          int x = st.top ();
          st.pop ();
          if (a[i].count (x) + a[i - 2].count (x) == 0) goto cont;
          while (ritp != dp[2].rend () && ritp->first >= x)
            mxp = max (mxp, ritp->second), ++ritp;
          while (ritq != dp[1].rend () && ritq->first >= x)
            mxq = max (mxq, ritq->second), ++ritq;
          dp[0][id].second = max (dp[0][id].second, rs + mxp);
          q[0][id].second = dp[0][id].second - ms - rs;
          dp[0][id].second = max (dp[0][id].second, rs + mxq - ms);
          p[0][id].second = dp[0][id].second - rs;
          --id;
        cont:
          ls -= a[i - 2].count (x) ? a[i - 2][x] : 0ll;
          ms -= a[i - 1].count (x) ? a[i - 1][x] : 0ll;
          rs -= a[i].count (x) ? a[i][x] : 0ll;
        }
      swap (p[2], p[1]);
      swap (p[1], p[0]);
      p[0].clear ();
      swap (q[1], q[0]);
      q[0].clear ();
      swap (dp[2], dp[1]);
      swap (dp[1], dp[0]);
      for (auto &x : dp[0]) mxdp = max (mxdp, x.second);
      dp[0].clear ();
    }
  for (int i = 1; i <= 2; ++i) for (auto &x : dp[i]) mxdp = max (mxdp, x.second);
  return mxdp;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 21376 KB Output is correct
2 Correct 165 ms 25260 KB Output is correct
3 Correct 5 ms 4956 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 806 ms 53728 KB Output is correct
6 Correct 386 ms 37460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 354 ms 38088 KB Output is correct
3 Correct 483 ms 44980 KB Output is correct
4 Correct 127 ms 21160 KB Output is correct
5 Correct 187 ms 25220 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 6 ms 4956 KB Output is correct
11 Correct 5 ms 4896 KB Output is correct
12 Correct 191 ms 25628 KB Output is correct
13 Correct 239 ms 29904 KB Output is correct
14 Correct 171 ms 21912 KB Output is correct
15 Correct 157 ms 23260 KB Output is correct
16 Correct 151 ms 22392 KB Output is correct
17 Correct 182 ms 24948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4956 KB Output is correct
2 Correct 6 ms 4956 KB Output is correct
3 Correct 27 ms 10176 KB Output is correct
4 Correct 20 ms 8792 KB Output is correct
5 Correct 56 ms 15364 KB Output is correct
6 Correct 63 ms 14704 KB Output is correct
7 Correct 58 ms 15032 KB Output is correct
8 Correct 54 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 71 ms 4444 KB Output is correct
18 Correct 61 ms 4396 KB Output is correct
19 Correct 58 ms 4188 KB Output is correct
20 Correct 57 ms 4432 KB Output is correct
21 Correct 54 ms 4368 KB Output is correct
22 Correct 115 ms 8288 KB Output is correct
23 Correct 14 ms 1116 KB Output is correct
24 Correct 50 ms 2828 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 13 ms 1188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 71 ms 4444 KB Output is correct
18 Correct 61 ms 4396 KB Output is correct
19 Correct 58 ms 4188 KB Output is correct
20 Correct 57 ms 4432 KB Output is correct
21 Correct 54 ms 4368 KB Output is correct
22 Correct 115 ms 8288 KB Output is correct
23 Correct 14 ms 1116 KB Output is correct
24 Correct 50 ms 2828 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 13 ms 1188 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 400 ms 22868 KB Output is correct
29 Correct 579 ms 32800 KB Output is correct
30 Correct 681 ms 32084 KB Output is correct
31 Correct 644 ms 32076 KB Output is correct
32 Correct 530 ms 31316 KB Output is correct
33 Correct 674 ms 32064 KB Output is correct
34 Correct 703 ms 32072 KB Output is correct
35 Correct 190 ms 12396 KB Output is correct
36 Correct 707 ms 32220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4956 KB Output is correct
2 Correct 6 ms 4956 KB Output is correct
3 Correct 27 ms 10176 KB Output is correct
4 Correct 20 ms 8792 KB Output is correct
5 Correct 56 ms 15364 KB Output is correct
6 Correct 63 ms 14704 KB Output is correct
7 Correct 58 ms 15032 KB Output is correct
8 Correct 54 ms 15184 KB Output is correct
9 Correct 55 ms 14932 KB Output is correct
10 Correct 58 ms 12884 KB Output is correct
11 Correct 150 ms 25812 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 5 ms 4956 KB Output is correct
19 Correct 5 ms 4956 KB Output is correct
20 Correct 6 ms 4952 KB Output is correct
21 Correct 6 ms 4956 KB Output is correct
22 Correct 100 ms 15948 KB Output is correct
23 Correct 170 ms 25820 KB Output is correct
24 Correct 170 ms 26312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 21376 KB Output is correct
2 Correct 165 ms 25260 KB Output is correct
3 Correct 5 ms 4956 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 806 ms 53728 KB Output is correct
6 Correct 386 ms 37460 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 354 ms 38088 KB Output is correct
9 Correct 483 ms 44980 KB Output is correct
10 Correct 127 ms 21160 KB Output is correct
11 Correct 187 ms 25220 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 4956 KB Output is correct
17 Correct 5 ms 4896 KB Output is correct
18 Correct 191 ms 25628 KB Output is correct
19 Correct 239 ms 29904 KB Output is correct
20 Correct 171 ms 21912 KB Output is correct
21 Correct 157 ms 23260 KB Output is correct
22 Correct 151 ms 22392 KB Output is correct
23 Correct 182 ms 24948 KB Output is correct
24 Correct 6 ms 4956 KB Output is correct
25 Correct 6 ms 4956 KB Output is correct
26 Correct 27 ms 10176 KB Output is correct
27 Correct 20 ms 8792 KB Output is correct
28 Correct 56 ms 15364 KB Output is correct
29 Correct 63 ms 14704 KB Output is correct
30 Correct 58 ms 15032 KB Output is correct
31 Correct 54 ms 15184 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 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 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 71 ms 4444 KB Output is correct
49 Correct 61 ms 4396 KB Output is correct
50 Correct 58 ms 4188 KB Output is correct
51 Correct 57 ms 4432 KB Output is correct
52 Correct 54 ms 4368 KB Output is correct
53 Correct 115 ms 8288 KB Output is correct
54 Correct 14 ms 1116 KB Output is correct
55 Correct 50 ms 2828 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 13 ms 1188 KB Output is correct
58 Correct 2 ms 600 KB Output is correct
59 Correct 400 ms 22868 KB Output is correct
60 Correct 579 ms 32800 KB Output is correct
61 Correct 681 ms 32084 KB Output is correct
62 Correct 644 ms 32076 KB Output is correct
63 Correct 530 ms 31316 KB Output is correct
64 Correct 674 ms 32064 KB Output is correct
65 Correct 703 ms 32072 KB Output is correct
66 Correct 190 ms 12396 KB Output is correct
67 Correct 707 ms 32220 KB Output is correct
68 Correct 55 ms 14932 KB Output is correct
69 Correct 58 ms 12884 KB Output is correct
70 Correct 150 ms 25812 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 0 ms 432 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 5 ms 4956 KB Output is correct
78 Correct 5 ms 4956 KB Output is correct
79 Correct 6 ms 4952 KB Output is correct
80 Correct 6 ms 4956 KB Output is correct
81 Correct 100 ms 15948 KB Output is correct
82 Correct 170 ms 25820 KB Output is correct
83 Correct 170 ms 26312 KB Output is correct
84 Correct 818 ms 42900 KB Output is correct
85 Correct 834 ms 44508 KB Output is correct
86 Correct 440 ms 36692 KB Output is correct
87 Correct 439 ms 37200 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 393 ms 37076 KB Output is correct
90 Correct 442 ms 36304 KB Output is correct
91 Correct 357 ms 36076 KB Output is correct