답안 #654745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654745 2022-11-01T12:55:05 Z t6twotwo 메기 농장 (IOI22_fish) C++17
3 / 100
206 ms 43468 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const long long inf = -(1LL << 60);
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
  vector<vector<int>> b(n);
  for (int i = 0; i < m; i++) {
    b[x[i]].push_back(i);
  }
  vector d(n, vector<int>{-1});
  vector<vector<int>> r(n), p(n);
  for (int i = 0; i < n; i++) {
    sort(b[i].begin(), b[i].end(), [&](int j, int k) {
      return y[j] < y[k];
    });
    for (int j : b[i]) {
      r[i].push_back(y[j]);
      p[i].push_back(w[j]);
      if (i > 0) {
        d[i - 1].push_back(y[j]);
      }
      if (i < n - 1) {
        d[i + 1].push_back(y[j]);
      }
    }
  }
  vector<vector<long long>> s(n);
  for (int i = 0; i < n; i++) {
    int k = p[i].size();
    s[i] = vector<long long>(k + 1);
    for (int j = k - 1; j >= 0; j--) {
      s[i][j] = s[i][j + 1] + p[i][j];
    }
  }
  auto get_sum = [&](int i, int x) -> long long {
    if (i == -1) {
      return 0LL;
    }
    return s[i][upper_bound(r[i].begin(), r[i].end(), x) - r[i].begin()];
  };
  vector<int> e{-1};
  vector<array<long long, 2>> dp{{0, 0}};
  for (int i = 0; i < n; i++) {
    int k = dp.size();
    vector<long long> pmax(k + 1, inf);
    for (int j = 0; j < k; j++) {
      pmax[j + 1] = max(pmax[j], dp[j][0] + get_sum(i - 1, e[j]));
    }
    vector<long long> smax(k + 1, inf);
    for (int j = k - 1; j >= 0; j--) {
      smax[j] = max(smax[j + 1], dp[j][1] - get_sum(i, e[j]));
    }
    for (int j = 0; j < k; j++) {
      dp[0][0] = max(dp[0][0], dp[j][0]);
      dp[0][1] = max(dp[0][1], max(dp[j][0], dp[j][1]));
    }
    int l = d[i].size();
    dp.resize(l);
    for (int j = 1; j < l; j++) {
      dp[j][0] = pmax[upper_bound(e.begin(), e.end(), d[i][j]) - e.begin()] - get_sum(i - 1, d[i][j]);
      dp[j][1] = smax[lower_bound(e.begin(), e.end(), d[i][j]) - e.begin()] + get_sum(i, d[i][j]);
    }
    swap(e, d[i]);
  }
  long long ans = 0;
  for (auto v : dp) {
    ans = max(ans, max(v[0], v[1]));
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 24072 KB Output is correct
2 Correct 66 ms 27712 KB Output is correct
3 Correct 21 ms 18216 KB Output is correct
4 Correct 21 ms 18260 KB Output is correct
5 Correct 181 ms 42976 KB Output is correct
6 Correct 206 ms 43468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 128 ms 30980 KB Output is correct
3 Correct 153 ms 34548 KB Output is correct
4 Correct 58 ms 23912 KB Output is correct
5 Correct 68 ms 27624 KB Output is correct
6 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 18276 KB Output is correct
2 Incorrect 21 ms 18260 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 18276 KB Output is correct
2 Incorrect 21 ms 18260 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 24072 KB Output is correct
2 Correct 66 ms 27712 KB Output is correct
3 Correct 21 ms 18216 KB Output is correct
4 Correct 21 ms 18260 KB Output is correct
5 Correct 181 ms 42976 KB Output is correct
6 Correct 206 ms 43468 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 128 ms 30980 KB Output is correct
9 Correct 153 ms 34548 KB Output is correct
10 Correct 58 ms 23912 KB Output is correct
11 Correct 68 ms 27624 KB Output is correct
12 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
13 Halted 0 ms 0 KB -