답안 #839077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839077 2023-08-28T15:10:00 Z abczz 메기 농장 (IOI22_fish) C++17
18 / 100
192 ms 39660 KB
#include "fish.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <map>
#include <queue>
#define ll long long
using namespace std;

vector <array<ll, 2>> V[100000];
vector <ll> pre;
vector <array<ll, 3>> dp[100000];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  ll f = -1e18, j, k, l, s = 0, t = 0, v, x, u, p = -1e18, mx, mx2, cur;
  map <ll, ll> mp;
  for (int i=0; i<M; ++i) {
    V[X[i]].push_back({Y[i], W[i]});
  }
  for (int i=0; i<N; ++i) {
    sort(V[i].begin(), V[i].end());
  }
  j = 0;
  s = 0;
  for (auto [y, w] : V[1]) {
    s += w;
    dp[0].push_back({y, 0, (ll)-1e18});
    f = max(f, s);
  }
  for (int i=1; i<N; ++i) {
    if (i >= 3) {
      j = 0;
      s = 0;
      for (auto [y, w, a] : dp[i-3]) {
        w = max(w, a);
        while (j < V[i-2].size() && V[i-2][j][0] <= y) {
          s += V[i-2][j][1];
          ++j;
        }
        p = max(p, s+w);
      }
    }
    mp.clear();
    mx = mx2 = -1e18, s = 0;
    if (i >= 2) {
      j = 0;
      for (auto [y, w, a] : dp[i-2]) {
        w = max(w, a);
        while (j < V[i-1].size() && V[i-1][j][0] <= y) {
          s += V[i-1][j][1];
          ++j;
        }
        mx = max(mx, w);
        mx2 = max(mx2, w+s);
      }
    }
    for (auto [y, w] : V[i-1]) {
      ++mp[y];
    }
    if (i != N-1) {
      for (auto [y, w] : V[i+1]) {
        ++mp[y];
      }
    }
    s = j = k = t = 0;
    v = x = -1e18;
    pre.clear();
    for (auto [y, w, a] : dp[i-1]) {
      while (j < V[i].size() && V[i][j][0] <= y) {
        s += V[i][j][1];
        ++j;
      }
      while (k < V[i-1].size() && V[i-1][k][0] <= y) {
        t += V[i-1][k][1];
        ++k;
      }
      v = max(v, max(w, a)+s);
      x = max(x, w-t);
    }
    s = j = k = t = l = u = 0;
    for (auto [y, z] : mp) {
      while (j < V[i].size() && V[i][j][0] <= y) {
        s += V[i][j][1];
        ++j;
      }
      while (k < V[i-1].size() && V[i-1][k][0] <= y) {
        t += V[i-1][k][1];
        ++k;
      }
      while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) {
        u += V[i+1][l][1];
        ++l;
      }
      cur = max(max(t, p+t), max(mx2, mx+t));
      //cout << v << " " << x << " " << s << " " << t << endl;
      //cout << cur << endl;
      cur = max(cur, x+t);
      //cout << cur << endl;
      dp[i].push_back({y, cur, v-s});
      //cout << i << " " << y << " " << cur << "/" << v-s << endl;
      cur = max(cur, x+t);
      f = max(f, cur + u);
    }
  }
  return f;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:37:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         while (j < V[i-2].size() && V[i-2][j][0] <= y) {
      |                ~~^~~~~~~~~~~~~~~
fish.cpp:50:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while (j < V[i-1].size() && V[i-1][j][0] <= y) {
      |                ~~^~~~~~~~~~~~~~~
fish.cpp:70:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |       while (j < V[i].size() && V[i][j][0] <= y) {
      |              ~~^~~~~~~~~~~~~
fish.cpp:74:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |       while (k < V[i-1].size() && V[i-1][k][0] <= y) {
      |              ~~^~~~~~~~~~~~~~~
fish.cpp:83:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |       while (j < V[i].size() && V[i][j][0] <= y) {
      |              ~~^~~~~~~~~~~~~
fish.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |       while (k < V[i-1].size() && V[i-1][k][0] <= y) {
      |              ~~^~~~~~~~~~~~~~~
fish.cpp:91:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |       while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) {
      |                          ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 17732 KB Output is correct
2 Correct 56 ms 19728 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 192 ms 39132 KB Output is correct
6 Correct 164 ms 39660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 86 ms 24740 KB Output is correct
3 Correct 107 ms 29484 KB Output is correct
4 Correct 49 ms 18920 KB Output is correct
5 Correct 55 ms 20828 KB Output is correct
6 Correct 2 ms 4996 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 51 ms 20792 KB Output is correct
13 Correct 58 ms 23144 KB Output is correct
14 Correct 42 ms 15964 KB Output is correct
15 Correct 48 ms 16832 KB Output is correct
16 Correct 43 ms 15868 KB Output is correct
17 Correct 48 ms 16788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4980 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 25 ms 9704 KB Output is correct
4 Correct 18 ms 8256 KB Output is correct
5 Correct 45 ms 13592 KB Output is correct
6 Correct 40 ms 13516 KB Output is correct
7 Correct 54 ms 13528 KB Output is correct
8 Correct 43 ms 13616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4972 KB Output is correct
8 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4972 KB Output is correct
8 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4972 KB Output is correct
8 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4980 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 25 ms 9704 KB Output is correct
4 Correct 18 ms 8256 KB Output is correct
5 Correct 45 ms 13592 KB Output is correct
6 Correct 40 ms 13516 KB Output is correct
7 Correct 54 ms 13528 KB Output is correct
8 Correct 43 ms 13616 KB Output is correct
9 Correct 50 ms 16652 KB Output is correct
10 Correct 42 ms 12952 KB Output is correct
11 Correct 83 ms 22164 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4996 KB Output is correct
14 Correct 3 ms 4916 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 5000 KB Output is correct
17 Incorrect 3 ms 5000 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 17732 KB Output is correct
2 Correct 56 ms 19728 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 192 ms 39132 KB Output is correct
6 Correct 164 ms 39660 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 86 ms 24740 KB Output is correct
9 Correct 107 ms 29484 KB Output is correct
10 Correct 49 ms 18920 KB Output is correct
11 Correct 55 ms 20828 KB Output is correct
12 Correct 2 ms 4996 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 51 ms 20792 KB Output is correct
19 Correct 58 ms 23144 KB Output is correct
20 Correct 42 ms 15964 KB Output is correct
21 Correct 48 ms 16832 KB Output is correct
22 Correct 43 ms 15868 KB Output is correct
23 Correct 48 ms 16788 KB Output is correct
24 Correct 3 ms 4980 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 25 ms 9704 KB Output is correct
27 Correct 18 ms 8256 KB Output is correct
28 Correct 45 ms 13592 KB Output is correct
29 Correct 40 ms 13516 KB Output is correct
30 Correct 54 ms 13528 KB Output is correct
31 Correct 43 ms 13616 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 2 ms 4948 KB Output is correct
38 Correct 2 ms 4972 KB Output is correct
39 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
40 Halted 0 ms 0 KB -