Submission #647999

# Submission time Handle Problem Language Result Execution time Memory
647999 2022-10-04T19:32:42 Z gurkot Catfish Farm (IOI22_fish) C++17
100 / 100
208 ms 38636 KB
//https://oj.uz/problem/submit/IOI22_fish

#include <bits/stdc++.h>
using namespace std;

int kUp = 0, kDown = 1;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  vector<vector<pair<int, int>>> fishes(N);

  for (int i = 0; i < M; ++i) {
    fishes[X[i]].push_back(make_pair(Y[i], i));
  }

  long long largest = 0;
  vector<pair<int, long long>> up, down;
  vector<vector<long long>> dp(M, vector<long long>(2,-1));
  
  for (int x = 0; x < N; ++x) {
    sort(fishes[x].begin(), fishes[x].end());

    if (x >=1) {    	
      long long max_down = 0;
      for (int j = (int)fishes[x].size() - 1; j >= 0; --j) {
        int y = fishes[x][j].first;
        int i = fishes[x][j].second;
        while (down.size() > 0 && down.back().first > y) {
          max_down = max(max_down, down.back().second);
          down.pop_back();
        }

        long long &ret = dp[i][kDown];
        ret = largest + W[i];
        ret = max(ret, max_down + W[i]);
        if (j + 1 < (int)fishes[x].size()) {
          ret = max(ret, dp[fishes[x][j + 1].second][kDown] + W[i]);
        }
      }
    }

    if (x >= 1)
      for (int ii=0;ii<fishes[x - 1].size();ii++){	    
	    pair<int, int> tmp=fishes[x - 1][ii];	    
        largest = max(largest, dp[tmp.second][kDown]);
      }
    

    long long max_up = 0;
    for (int j = 0; j < (int)fishes[x].size(); ++j) {
      int y = fishes[x][j].first;
      int i = fishes[x][j].second;
      while (up.size() > 0 && up.back().first < y) {
        max_up = max(max_up, up.back().second);
        up.pop_back();
      }

      long long &ret = dp[i][kUp];
      ret = largest + W[i];
      ret = max(ret, max_up + W[i]);
      if (j > 0) {
        ret = max(ret, dp[fishes[x][j - 1].second][kUp] + W[i]);
       
      }
    }

    if (x >= 1)
	for (int ii=0;ii<fishes[x - 1].size();ii++){ 
      pair<int, int> tmp=fishes[x - 1][ii];	    
        largest = max(largest, dp[tmp.second][kUp]);
    }

    down.clear();
    for (int j = 0; j < (int)fishes[x].size(); ++j) 
      down.push_back(make_pair(fishes[x][j].first, dp[fishes[x][j].second][kDown]));
   
    up.clear();
    for (int j = (int)(fishes[x].size()) - 1; j >= 0; --j) 
      up.push_back(make_pair(fishes[x][j].first, dp[fishes[x][j].second][kUp]));    
  }
  long long answer = 0;
  for (int i = 0; i < M; ++i) {
    answer = max(answer, dp[i][kDown]);
    if (X[i] + 1 < N)     answer = max(answer, dp[i][kUp]);  
  }
  return answer;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |       for (int ii=0;ii<fishes[x - 1].size();ii++){
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int ii=0;ii<fishes[x - 1].size();ii++){
      |                ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 51 ms 15216 KB Output is correct
2 Correct 58 ms 17444 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 208 ms 38636 KB Output is correct
6 Correct 189 ms 35824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 103 ms 23204 KB Output is correct
3 Correct 140 ms 27656 KB Output is correct
4 Correct 46 ms 14760 KB Output is correct
5 Correct 55 ms 17372 KB Output is correct
6 Correct 0 ms 212 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 212 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 54 ms 14804 KB Output is correct
13 Correct 59 ms 17364 KB Output is correct
14 Correct 45 ms 12672 KB Output is correct
15 Correct 52 ms 13908 KB Output is correct
16 Correct 46 ms 12668 KB Output is correct
17 Correct 52 ms 13888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 35 ms 8912 KB Output is correct
4 Correct 20 ms 6644 KB Output is correct
5 Correct 58 ms 14336 KB Output is correct
6 Correct 55 ms 14336 KB Output is correct
7 Correct 66 ms 14816 KB Output is correct
8 Correct 61 ms 14924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 276 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 276 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 22 ms 4924 KB Output is correct
18 Correct 23 ms 5068 KB Output is correct
19 Correct 21 ms 4964 KB Output is correct
20 Correct 21 ms 5068 KB Output is correct
21 Correct 20 ms 5068 KB Output is correct
22 Correct 45 ms 9980 KB Output is correct
23 Correct 5 ms 1108 KB Output is correct
24 Correct 14 ms 3284 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 276 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 22 ms 4924 KB Output is correct
18 Correct 23 ms 5068 KB Output is correct
19 Correct 21 ms 4964 KB Output is correct
20 Correct 21 ms 5068 KB Output is correct
21 Correct 20 ms 5068 KB Output is correct
22 Correct 45 ms 9980 KB Output is correct
23 Correct 5 ms 1108 KB Output is correct
24 Correct 14 ms 3284 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 118 ms 23672 KB Output is correct
29 Correct 175 ms 32860 KB Output is correct
30 Correct 159 ms 32420 KB Output is correct
31 Correct 156 ms 32412 KB Output is correct
32 Correct 164 ms 32968 KB Output is correct
33 Correct 159 ms 32400 KB Output is correct
34 Correct 161 ms 31692 KB Output is correct
35 Correct 59 ms 12248 KB Output is correct
36 Correct 159 ms 30992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 35 ms 8912 KB Output is correct
4 Correct 20 ms 6644 KB Output is correct
5 Correct 58 ms 14336 KB Output is correct
6 Correct 55 ms 14336 KB Output is correct
7 Correct 66 ms 14816 KB Output is correct
8 Correct 61 ms 14924 KB Output is correct
9 Correct 64 ms 14320 KB Output is correct
10 Correct 55 ms 11972 KB Output is correct
11 Correct 128 ms 24076 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2604 KB Output is correct
22 Correct 62 ms 13980 KB Output is correct
23 Correct 123 ms 22352 KB Output is correct
24 Correct 127 ms 24084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 15216 KB Output is correct
2 Correct 58 ms 17444 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 208 ms 38636 KB Output is correct
6 Correct 189 ms 35824 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 103 ms 23204 KB Output is correct
9 Correct 140 ms 27656 KB Output is correct
10 Correct 46 ms 14760 KB Output is correct
11 Correct 55 ms 17372 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 54 ms 14804 KB Output is correct
19 Correct 59 ms 17364 KB Output is correct
20 Correct 45 ms 12672 KB Output is correct
21 Correct 52 ms 13908 KB Output is correct
22 Correct 46 ms 12668 KB Output is correct
23 Correct 52 ms 13888 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 35 ms 8912 KB Output is correct
27 Correct 20 ms 6644 KB Output is correct
28 Correct 58 ms 14336 KB Output is correct
29 Correct 55 ms 14336 KB Output is correct
30 Correct 66 ms 14816 KB Output is correct
31 Correct 61 ms 14924 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 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 276 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 22 ms 4924 KB Output is correct
49 Correct 23 ms 5068 KB Output is correct
50 Correct 21 ms 4964 KB Output is correct
51 Correct 21 ms 5068 KB Output is correct
52 Correct 20 ms 5068 KB Output is correct
53 Correct 45 ms 9980 KB Output is correct
54 Correct 5 ms 1108 KB Output is correct
55 Correct 14 ms 3284 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 4 ms 980 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 118 ms 23672 KB Output is correct
60 Correct 175 ms 32860 KB Output is correct
61 Correct 159 ms 32420 KB Output is correct
62 Correct 156 ms 32412 KB Output is correct
63 Correct 164 ms 32968 KB Output is correct
64 Correct 159 ms 32400 KB Output is correct
65 Correct 161 ms 31692 KB Output is correct
66 Correct 59 ms 12248 KB Output is correct
67 Correct 159 ms 30992 KB Output is correct
68 Correct 64 ms 14320 KB Output is correct
69 Correct 55 ms 11972 KB Output is correct
70 Correct 128 ms 24076 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 296 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 300 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 2 ms 2644 KB Output is correct
78 Correct 2 ms 2644 KB Output is correct
79 Correct 2 ms 2644 KB Output is correct
80 Correct 2 ms 2604 KB Output is correct
81 Correct 62 ms 13980 KB Output is correct
82 Correct 123 ms 22352 KB Output is correct
83 Correct 127 ms 24084 KB Output is correct
84 Correct 188 ms 34340 KB Output is correct
85 Correct 196 ms 33220 KB Output is correct
86 Correct 194 ms 33968 KB Output is correct
87 Correct 189 ms 33524 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 189 ms 34468 KB Output is correct
90 Correct 170 ms 31896 KB Output is correct
91 Correct 162 ms 31692 KB Output is correct