Submission #922294

# Submission time Handle Problem Language Result Execution time Memory
922294 2024-02-05T11:24:18 Z AkibAzmain Catfish Farm (IOI22_fish) C++17
64 / 100
1000 ms 80684 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> x, std::vector<int> y,
                      std::vector<int> w)
{
  n += 2;
  vector < map < int, ll > > a (n);
  for (int i = 0; i < m; ++i) a[x[i] + 1][y[i]] += w[i];
  ll mxdp = 0;
  vector < map < 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;
      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][x] = 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][x] = max (dp[0][x], ls + rs + mxp);
          dp[0][x] = max (dp[0][x], 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][x] = max (dp[0][x], rs + mxp);
          q[0][x] = dp[0][x] - ms - rs;
          dp[0][x] = max (dp[0][x], rs + mxq - ms);
          p[0][x] = dp[0][x] - rs;
        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;
}
# Verdict Execution time Memory Grader output
1 Correct 203 ms 31828 KB Output is correct
2 Correct 270 ms 38932 KB Output is correct
3 Correct 7 ms 4956 KB Output is correct
4 Correct 7 ms 4952 KB Output is correct
5 Execution timed out 1045 ms 69792 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 703 ms 65756 KB Output is correct
3 Correct 914 ms 80684 KB Output is correct
4 Correct 239 ms 31988 KB Output is correct
5 Correct 302 ms 38768 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 1 ms 604 KB Output is correct
10 Correct 9 ms 4956 KB Output is correct
11 Correct 7 ms 4956 KB Output is correct
12 Correct 401 ms 42048 KB Output is correct
13 Correct 569 ms 51528 KB Output is correct
14 Correct 303 ms 35044 KB Output is correct
15 Correct 307 ms 39036 KB Output is correct
16 Correct 314 ms 35472 KB Output is correct
17 Correct 329 ms 39348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4956 KB Output is correct
2 Correct 7 ms 4956 KB Output is correct
3 Correct 36 ms 10076 KB Output is correct
4 Correct 26 ms 8792 KB Output is correct
5 Correct 62 ms 15368 KB Output is correct
6 Correct 73 ms 14704 KB Output is correct
7 Correct 61 ms 15184 KB Output is correct
8 Correct 58 ms 15320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 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 3 ms 604 KB Output is correct
11 Correct 1 ms 520 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 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 3 ms 604 KB Output is correct
11 Correct 1 ms 520 KB Output is correct
12 Correct 2 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 408 KB Output is correct
16 Correct 5 ms 704 KB Output is correct
17 Correct 108 ms 5308 KB Output is correct
18 Correct 86 ms 5224 KB Output is correct
19 Correct 83 ms 5212 KB Output is correct
20 Correct 80 ms 5212 KB Output is correct
21 Correct 90 ms 5124 KB Output is correct
22 Correct 172 ms 9860 KB Output is correct
23 Correct 22 ms 1368 KB Output is correct
24 Correct 76 ms 3416 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 19 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 432 KB Output is correct
4 Correct 1 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 3 ms 604 KB Output is correct
11 Correct 1 ms 520 KB Output is correct
12 Correct 2 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 408 KB Output is correct
16 Correct 5 ms 704 KB Output is correct
17 Correct 108 ms 5308 KB Output is correct
18 Correct 86 ms 5224 KB Output is correct
19 Correct 83 ms 5212 KB Output is correct
20 Correct 80 ms 5212 KB Output is correct
21 Correct 90 ms 5124 KB Output is correct
22 Correct 172 ms 9860 KB Output is correct
23 Correct 22 ms 1368 KB Output is correct
24 Correct 76 ms 3416 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 19 ms 1116 KB Output is correct
27 Correct 3 ms 736 KB Output is correct
28 Correct 568 ms 23176 KB Output is correct
29 Correct 922 ms 33576 KB Output is correct
30 Execution timed out 1032 ms 32140 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4956 KB Output is correct
2 Correct 7 ms 4956 KB Output is correct
3 Correct 36 ms 10076 KB Output is correct
4 Correct 26 ms 8792 KB Output is correct
5 Correct 62 ms 15368 KB Output is correct
6 Correct 73 ms 14704 KB Output is correct
7 Correct 61 ms 15184 KB Output is correct
8 Correct 58 ms 15320 KB Output is correct
9 Correct 95 ms 15084 KB Output is correct
10 Correct 63 ms 13116 KB Output is correct
11 Correct 151 ms 25684 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 7 ms 4952 KB Output is correct
19 Correct 6 ms 4956 KB Output is correct
20 Correct 7 ms 4956 KB Output is correct
21 Correct 7 ms 4956 KB Output is correct
22 Correct 125 ms 15708 KB Output is correct
23 Correct 251 ms 25936 KB Output is correct
24 Correct 247 ms 26328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 31828 KB Output is correct
2 Correct 270 ms 38932 KB Output is correct
3 Correct 7 ms 4956 KB Output is correct
4 Correct 7 ms 4952 KB Output is correct
5 Execution timed out 1045 ms 69792 KB Time limit exceeded
6 Halted 0 ms 0 KB -