답안 #635095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635095 2022-08-25T12:17:10 Z ruhanhabib39 메기 농장 (IOI22_fish) C++17
53 / 100
1000 ms 1976680 KB
#include "fish.h"

#include <vector>
#include <array>
#include <iostream>

namespace ruhan {
   using namespace std;

   int N, M;

   int H;
   vector<vector<long long>> ss;
   vector<vector<array<long long, 2>>> dp;

   vector<int> X, Y, W;

   bool is_subtask1;
   bool is_subtask2;

   void init (int N_, int M_, vector<int> X_, vector<int> Y_, vector<int> W_) {
      N = N_;
      M = M_;
      X = X_;
      Y = Y_;
      W = W_;

      H = 0;
      for (int i = 0; i < M; i++) {
         H = max(H, Y[i]);
      }
      H++;

      is_subtask1 = true;
      for (int i = 0; i < M; i++) {
         is_subtask1 = is_subtask1 && (X[i] % 2 == 0);
      }

      is_subtask2 = true;
      for (int i = 0; i < M; i++) {
         is_subtask2 = is_subtask2 && X[i] <= 1;
      }

      if (is_subtask1) return;

      if (is_subtask2) {
         ss = vector<vector<long long>>(2, vector<long long>(H, 0LL));
      } else {
         ss = vector<vector<long long>>(N, vector<long long>(H, 0LL));
         dp = vector<vector<array<long long, 2>>>(N + 1, vector<array<long long, 2>>(H + 1));
      }

      for (int i = 0; i < M; i++) {
         ss[X[i]][Y[i]] += W[i];
      }

      for (int x = 0; x < (int)ss.size(); x++) {
         for (int y = 1; y < H; y++) {
            ss[x][y] += ss[x][y-1];
         }
      }
   }

   long long get_sum (int x, int ly, int ry) {
      ly = max(0, ly);
      ry = min(H - 1, ry);

      if (x < 0 || x >= N || ry < ly) return 0;
      if (ly == 0) return ss[x][ry];
      return ss[x][ry] - ss[x][ly-1];
   }

   long long subtask345 () {
      //fill(dp[N].begin(), dp[N].end(), 0LL);
      for (int x = N - 1; x >= 0; x--) {
         for (int h = 0; h <= H; h++) {
            for (int s : {0, 1}) {
               const int H1 = s ? h : H;
               for (int y = 0; y <= H1; y++) {
                  long long val = get_sum(x-1,h,y-1) + get_sum(x+1,0,y-1);

                  val -= get_sum(x, 0, min(h-1,y-1));
                  val += dp[x+1][y][y < h];

                  if (x == 4 && h == 0 && s == 1) {
                     //cerr << "left adding " << get_sum(x-1,h,y-1) << "\n";
                     //cerr << "right adding " << get_sum(x+1,0,y-1) << "\n";
                     //cerr << "mid removing " << get_sum(x, 0, min(h-1,y-1)) << "\n";
                     //cerr << "val(" << y << ") = " << val << "\n";
                  }
                  dp[x][h][s] = max(dp[x][h][s], val);
               }

               if (x < N - 1) {
                  for (int y = 0; y <= H; y++) {
                     long long val = get_sum(x, h, y-1);

                     if (x == 4 && h == 0 && s == 1) {
                        //cerr << "for y = " << y << ", middle adding " << get_sum(x, h, y-1) << "\n";
                     }

                     val += get_sum(x+2, 0, y - 1);
                     val += x + 2 <= N ? dp[x+2][y][0] : 0;
                     dp[x][h][s] = max(dp[x][h][s], val);
                  }

                  if (x == 4 && h == 0 && s == 1) {
                     //cerr << "dp -> " << dp[x][h][s] << "\n";
                  }
               }
            }
         }
      }

      return dp[0][0][0];
   }

   long long subtask1 () {
      long long res = 0;
      for (int i = 0; i < M; i++) {
         res += W[i];
      }
      return res;
   }

   long long subtask2 () {
      long long res = max(get_sum(0, 0,  H - 1), get_sum(1, 0, H - 1));

      if (N > 2) {
         for (int y = 0; y <= H; y++) {
            long long val = get_sum(0, 0, y - 1) + get_sum(1, y, H - 1);
            res = max(res, val);
         }
      }

      return res;
   }

   long long calc () {
      if (is_subtask1) return subtask1();
      if (is_subtask2) return subtask2();
      return subtask345();
   }
};

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
   ruhan::init(N, M, X, Y, W);
   return ruhan::calc();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5100 KB Output is correct
2 Correct 34 ms 5524 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 88 ms 16108 KB Output is correct
6 Correct 97 ms 16588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 49 ms 10688 KB Output is correct
3 Correct 73 ms 12696 KB Output is correct
4 Correct 24 ms 4700 KB Output is correct
5 Correct 31 ms 5612 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 28 ms 6848 KB Output is correct
13 Correct 39 ms 7948 KB Output is correct
14 Correct 26 ms 6880 KB Output is correct
15 Correct 32 ms 7556 KB Output is correct
16 Correct 27 ms 6868 KB Output is correct
17 Correct 32 ms 7488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 21 ms 12820 KB Output is correct
3 Correct 37 ms 14072 KB Output is correct
4 Correct 33 ms 14540 KB Output is correct
5 Correct 51 ms 17492 KB Output is correct
6 Correct 47 ms 17576 KB Output is correct
7 Correct 51 ms 18244 KB Output is correct
8 Correct 53 ms 18252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 288 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 288 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 596 ms 2440 KB Output is correct
16 Correct 10 ms 468 KB Output is correct
17 Correct 610 ms 5124 KB Output is correct
18 Correct 584 ms 5076 KB Output is correct
19 Correct 617 ms 5024 KB Output is correct
20 Correct 599 ms 4988 KB Output is correct
21 Correct 170 ms 3964 KB Output is correct
22 Correct 608 ms 7912 KB Output is correct
23 Correct 596 ms 2876 KB Output is correct
24 Correct 589 ms 4184 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 580 ms 2840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 288 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 596 ms 2440 KB Output is correct
16 Correct 10 ms 468 KB Output is correct
17 Correct 610 ms 5124 KB Output is correct
18 Correct 584 ms 5076 KB Output is correct
19 Correct 617 ms 5024 KB Output is correct
20 Correct 599 ms 4988 KB Output is correct
21 Correct 170 ms 3964 KB Output is correct
22 Correct 608 ms 7912 KB Output is correct
23 Correct 596 ms 2876 KB Output is correct
24 Correct 589 ms 4184 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 580 ms 2840 KB Output is correct
27 Execution timed out 1108 ms 212004 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 21 ms 12820 KB Output is correct
3 Correct 37 ms 14072 KB Output is correct
4 Correct 33 ms 14540 KB Output is correct
5 Correct 51 ms 17492 KB Output is correct
6 Correct 47 ms 17576 KB Output is correct
7 Correct 51 ms 18244 KB Output is correct
8 Correct 53 ms 18252 KB Output is correct
9 Execution timed out 1161 ms 1976680 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5100 KB Output is correct
2 Correct 34 ms 5524 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 88 ms 16108 KB Output is correct
6 Correct 97 ms 16588 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 49 ms 10688 KB Output is correct
9 Correct 73 ms 12696 KB Output is correct
10 Correct 24 ms 4700 KB Output is correct
11 Correct 31 ms 5612 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 28 ms 6848 KB Output is correct
19 Correct 39 ms 7948 KB Output is correct
20 Correct 26 ms 6880 KB Output is correct
21 Correct 32 ms 7556 KB Output is correct
22 Correct 27 ms 6868 KB Output is correct
23 Correct 32 ms 7488 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 21 ms 12820 KB Output is correct
26 Correct 37 ms 14072 KB Output is correct
27 Correct 33 ms 14540 KB Output is correct
28 Correct 51 ms 17492 KB Output is correct
29 Correct 47 ms 17576 KB Output is correct
30 Correct 51 ms 18244 KB Output is correct
31 Correct 53 ms 18252 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 288 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 596 ms 2440 KB Output is correct
47 Correct 10 ms 468 KB Output is correct
48 Correct 610 ms 5124 KB Output is correct
49 Correct 584 ms 5076 KB Output is correct
50 Correct 617 ms 5024 KB Output is correct
51 Correct 599 ms 4988 KB Output is correct
52 Correct 170 ms 3964 KB Output is correct
53 Correct 608 ms 7912 KB Output is correct
54 Correct 596 ms 2876 KB Output is correct
55 Correct 589 ms 4184 KB Output is correct
56 Correct 5 ms 468 KB Output is correct
57 Correct 580 ms 2840 KB Output is correct
58 Execution timed out 1108 ms 212004 KB Time limit exceeded
59 Halted 0 ms 0 KB -