답안 #1046731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046731 2024-08-06T21:14:11 Z Trent 메기 농장 (IOI22_fish) C++17
61 / 100
809 ms 2097152 KB
#include "fish.h"
#include "bits/stdc++.h";
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct pii{int a, b;};

ll INF = 1e16;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  int MH = Y[0] + 1;
  for(int i : Y) MH = max(MH, i + 1);
  vvll wp(N, vll(MH));
  vvll wpsa(N, vll(MH));
  forR(i, M) wp[X[i]][Y[i]] = W[i];
  forR(x, N) {
    wpsa[x][0] = wp[x][0];
    REP(y, 1, MH) wpsa[x][y] = wpsa[x][y-1] + wp[x][y];
  }

  vector<set<int>> sCare(N);
  forR(i, M) {
    if(X[i] > 0) sCare[X[i]-1].insert(Y[i] + 1);
    if(X[i] + 1 < N) sCare[X[i] + 1].insert(Y[i] + 1);
    if(X[i] > 1) sCare[X[i]-2].insert(Y[i] + 1);
    if(X[i] + 2 < N) sCare[X[i] + 2].insert(Y[i] + 1);
    sCare[X[i]].insert(Y[i]+1);
  }
  forR(i, N) sCare[i].insert(0);
  vector<vi> care(N);
  forR(i, N) for(int j : sCare[i]) care[i].push_back(j);
  vvll I(N), D(N), E(N);
  forR(i, N) I[i].resize(care[i].size()), D[i].resize(care[i].size()), E[i].resize(care[i].size());
  // h = HEIGHT, not the index of last element!
  forR(i, N) {
    ll besIE = -INF, besII = -INF;
    if(i > 0) {
      forR(ki, care[i-1].size()) {
        int k = care[i-1][ki];
        besIE = max(besIE, E[i-1][ki] - (k > 0 ? wpsa[i-1][k-1] : 0));
      }
    }
    int api = 0;
    forR(hi, care[i].size()) {
      int h = care[i][hi];
      if(h > 0) {
        if(i == 0) I[i][hi] = 0;
        else {
          I[i][hi] = max(I[i][hi], besIE + wpsa[i-1][h-1]);
          while(api < care[i-1].size() && care[i-1][api] <= h) {
            int k = care[i-1][api];
            besII = max(besII, I[i-1][api] - (k > 0 ? wpsa[i-1][k-1] : 0));
            ++api;
          }
          I[i][hi] = max(I[i][hi], besII + wpsa[i-1][h-1]);
        }
      }
    }

    api = (int) care[i-1].size() - 1;
    ll besD = -INF;
    for(int hi = (int) care[i].size() - 1; hi >= 0; --hi){
      int h = care[i][hi];
      if(h > 0) {
        if(i == 0) D[i][hi] = 0;
        else {
          while(api >= 0 && care[i-1][api] >= h + 1) {
            int k = care[i-1][api];
            if(k <= MH) {
              besD = max(besD, max(I[i-1][api], D[i-1][api]) + wpsa[i][k - 1]);
            }
            --api;
          }
          D[i][hi] = max(D[i][hi], besD - (h > 0 ? wpsa[i][h-1] : 0));
        }
      }
    }

    ll besE = -INF;
    if(i > 0) {
      forR(yi, care[i-1].size()) besE = max(besE, E[i-1][yi]);
    }
    forR(hi, care[i].size()){
      int h = care[i][hi];
      if(i == 0) E[i][hi] = 0;
      else {
        int pInd = lower_bound(all(care[i-1]), h) - care[i-1].begin();
        if(care[i-1][pInd] == h) {
          ll tot = max(I[i-1][pInd], D[i-1][pInd]) + (h > 0 ? wpsa[i][h-1] : 0);
          E[i][hi] = max(E[i][hi], max(tot, besE));
        }
      }
    }
  }
  ll mx = 0;
  forR(hi, care[N-1].size()) if(care[N-1][hi] > 0) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
  forR(hi, care[N-1].size()) mx = max(mx, E[N-1][hi]);
  return mx;
}

Compilation message

fish.cpp:2:25: warning: extra tokens at end of #include directive
    2 | #include "bits/stdc++.h";
      |                         ^
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
fish.cpp:45:7: note: in expansion of macro 'forR'
   45 |       forR(ki, care[i-1].size()) {
      |       ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
fish.cpp:51:5: note: in expansion of macro 'forR'
   51 |     forR(hi, care[i].size()) {
      |     ^~~~
fish.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |           while(api < care[i-1].size() && care[i-1][api] <= h) {
      |                 ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
fish.cpp:88:7: note: in expansion of macro 'forR'
   88 |       forR(yi, care[i-1].size()) besE = max(besE, E[i-1][yi]);
      |       ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
fish.cpp:90:5: note: in expansion of macro 'forR'
   90 |     forR(hi, care[i].size()){
      |     ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
fish.cpp:103:3: note: in expansion of macro 'forR'
  103 |   forR(hi, care[N-1].size()) if(care[N-1][hi] > 0) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
      |   ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
fish.cpp:104:3: note: in expansion of macro 'forR'
  104 |   forR(hi, care[N-1].size()) mx = max(mx, E[N-1][hi]);
      |   ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 676 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 676 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 42492 KB Output is correct
2 Correct 33 ms 42588 KB Output is correct
3 Correct 47 ms 42324 KB Output is correct
4 Correct 51 ms 45648 KB Output is correct
5 Correct 69 ms 49724 KB Output is correct
6 Correct 64 ms 49492 KB Output is correct
7 Correct 60 ms 49708 KB Output is correct
8 Correct 70 ms 49744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 28 ms 8172 KB Output is correct
18 Correct 26 ms 6936 KB Output is correct
19 Correct 27 ms 7720 KB Output is correct
20 Correct 25 ms 6412 KB Output is correct
21 Correct 27 ms 5720 KB Output is correct
22 Correct 53 ms 10832 KB Output is correct
23 Correct 9 ms 4700 KB Output is correct
24 Correct 31 ms 9124 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 9 ms 4408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 28 ms 8172 KB Output is correct
18 Correct 26 ms 6936 KB Output is correct
19 Correct 27 ms 7720 KB Output is correct
20 Correct 25 ms 6412 KB Output is correct
21 Correct 27 ms 5720 KB Output is correct
22 Correct 53 ms 10832 KB Output is correct
23 Correct 9 ms 4700 KB Output is correct
24 Correct 31 ms 9124 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 9 ms 4408 KB Output is correct
27 Correct 63 ms 143468 KB Output is correct
28 Correct 172 ms 37976 KB Output is correct
29 Correct 469 ms 201376 KB Output is correct
30 Correct 777 ms 253928 KB Output is correct
31 Correct 761 ms 251260 KB Output is correct
32 Correct 221 ms 38468 KB Output is correct
33 Correct 809 ms 257748 KB Output is correct
34 Correct 787 ms 257768 KB Output is correct
35 Correct 118 ms 37396 KB Output is correct
36 Correct 601 ms 228712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 42492 KB Output is correct
2 Correct 33 ms 42588 KB Output is correct
3 Correct 47 ms 42324 KB Output is correct
4 Correct 51 ms 45648 KB Output is correct
5 Correct 69 ms 49724 KB Output is correct
6 Correct 64 ms 49492 KB Output is correct
7 Correct 60 ms 49708 KB Output is correct
8 Correct 70 ms 49744 KB Output is correct
9 Runtime error 659 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 676 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -