제출 #922248

#제출 시각아이디문제언어결과실행 시간메모리
922248AkibAzmain메기 농장 (IOI22_fish)C++17
9 / 100
1080 ms92756 KiB
#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 < n; ++i) a[i][n - 3] = 0;
  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;
          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 ();
          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);
          dp[0][x] = max (dp[0][x], rs + mxq - ms);
          p[0][x] = dp[0][x] - rs;
          q[0][x] = dp[0][x] - ms - rs;
          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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...