Submission #625776

# Submission time Handle Problem Language Result Execution time Memory
625776 2022-08-10T19:00:56 Z flashmt Catfish Farm (IOI22_fish) C++17
100 / 100
146 ms 15332 KB
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1LL << 60;

long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
  vector<vector<pair<int, int>>> fish(n);
  for (int i = 0; i < m; i++)
    fish[x[i]].push_back({y[i], w[i]});

  vector<long long> bestPrefix(n, -oo);
  // f: left, g: right
  vector<long long> f, g, lastF, lastG;
  for (int x = 0; x < n; x++)
  {
    sort(begin(fish[x]), end(fish[x]));
    int sz = size(fish[x]);
    swap(f, lastF);
    swap(g, lastG);
    f = g = vector<long long>(sz, -oo);

    long long bestLastF = -oo, bestCurF = -oo;
    for (int i = sz - 1, j = int(size(lastF)) - 1; i >= 0; i--)
      if (x)
      {
        auto [y, w] = fish[x][i];
        f[i] = max(bestCurF, 0LL) + w;
        if (x >= 2)
          f[i] = max(f[i], bestPrefix[x - 2] + w);
        while (j >= 0 && fish[x - 1][j].first > y)
          bestLastF = max(bestLastF, lastF[j--]);
        f[i] = max(f[i], bestLastF + w);
        bestCurF = max(bestCurF, f[i]);
      }

    if (!empty(lastF))
      bestLastF = *max_element(begin(lastF), end(lastF));

    long long bestLastG = -oo, bestCurG = -oo;
    for (int i = 0, j = 0; i < sz; i++)
      if (x < n - 1)
      {
        auto [y, w] = fish[x][i];
        g[i] = max(bestCurG, 0LL) + w;
        if (x >= 2)
          g[i] = max(g[i], bestPrefix[x - 2] + w);
        g[i] = max(g[i], bestLastF + w);
        while (j < size(lastG) && fish[x - 1][j].first < y)
          bestLastG = max(bestLastG, lastG[j++]);
        g[i] = max(g[i], bestLastG + w);
        bestCurG = max(bestCurG, g[i]);
      }

    if (x)
      bestPrefix[x] = bestPrefix[x - 1];
    bestPrefix[x] = max({bestPrefix[x], bestCurF, bestCurG});
  }

  return bestPrefix[n - 1];
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         while (j < size(lastG) && fish[x - 1][j].first < y)
      |                ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 6996 KB Output is correct
2 Correct 43 ms 8252 KB Output is correct
3 Correct 3 ms 3412 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 123 ms 14668 KB Output is correct
6 Correct 122 ms 14824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 63 ms 10796 KB Output is correct
3 Correct 79 ms 12988 KB Output is correct
4 Correct 32 ms 6984 KB Output is correct
5 Correct 39 ms 8244 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
10 Correct 3 ms 3412 KB Output is correct
11 Correct 3 ms 3412 KB Output is correct
12 Correct 33 ms 7008 KB Output is correct
13 Correct 53 ms 8240 KB Output is correct
14 Correct 36 ms 7092 KB Output is correct
15 Correct 37 ms 7848 KB Output is correct
16 Correct 32 ms 7104 KB Output is correct
17 Correct 36 ms 7780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 23 ms 6068 KB Output is correct
4 Correct 16 ms 5332 KB Output is correct
5 Correct 47 ms 8892 KB Output is correct
6 Correct 40 ms 8856 KB Output is correct
7 Correct 41 ms 8912 KB Output is correct
8 Correct 42 ms 8908 KB Output is correct
# Verdict Execution time Memory 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 272 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 1 ms 340 KB Output is correct
11 Correct 1 ms 212 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 248 KB Output is correct
# Verdict Execution time Memory 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 272 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 1 ms 340 KB Output is correct
11 Correct 1 ms 212 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 248 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 15 ms 1872 KB Output is correct
18 Correct 15 ms 2112 KB Output is correct
19 Correct 14 ms 2004 KB Output is correct
20 Correct 15 ms 2004 KB Output is correct
21 Correct 17 ms 2004 KB Output is correct
22 Correct 29 ms 3800 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 10 ms 1284 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 596 KB Output is correct
# Verdict Execution time Memory 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 272 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 1 ms 340 KB Output is correct
11 Correct 1 ms 212 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 248 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 15 ms 1872 KB Output is correct
18 Correct 15 ms 2112 KB Output is correct
19 Correct 14 ms 2004 KB Output is correct
20 Correct 15 ms 2004 KB Output is correct
21 Correct 17 ms 2004 KB Output is correct
22 Correct 29 ms 3800 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 10 ms 1284 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 596 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 71 ms 8596 KB Output is correct
29 Correct 107 ms 11228 KB Output is correct
30 Correct 109 ms 10736 KB Output is correct
31 Correct 104 ms 10820 KB Output is correct
32 Correct 98 ms 12240 KB Output is correct
33 Correct 103 ms 10728 KB Output is correct
34 Correct 110 ms 10720 KB Output is correct
35 Correct 43 ms 4608 KB Output is correct
36 Correct 107 ms 11744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 23 ms 6068 KB Output is correct
4 Correct 16 ms 5332 KB Output is correct
5 Correct 47 ms 8892 KB Output is correct
6 Correct 40 ms 8856 KB Output is correct
7 Correct 41 ms 8912 KB Output is correct
8 Correct 42 ms 8908 KB Output is correct
9 Correct 43 ms 8900 KB Output is correct
10 Correct 48 ms 5688 KB Output is correct
11 Correct 89 ms 11224 KB Output is correct
12 Correct 1 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 0 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 3 ms 3412 KB Output is correct
19 Correct 3 ms 3412 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 4 ms 3412 KB Output is correct
22 Correct 51 ms 7872 KB Output is correct
23 Correct 79 ms 11224 KB Output is correct
24 Correct 83 ms 11216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 6996 KB Output is correct
2 Correct 43 ms 8252 KB Output is correct
3 Correct 3 ms 3412 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 123 ms 14668 KB Output is correct
6 Correct 122 ms 14824 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 63 ms 10796 KB Output is correct
9 Correct 79 ms 12988 KB Output is correct
10 Correct 32 ms 6984 KB Output is correct
11 Correct 39 ms 8244 KB Output is correct
12 Correct 1 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 0 ms 212 KB Output is correct
16 Correct 3 ms 3412 KB Output is correct
17 Correct 3 ms 3412 KB Output is correct
18 Correct 33 ms 7008 KB Output is correct
19 Correct 53 ms 8240 KB Output is correct
20 Correct 36 ms 7092 KB Output is correct
21 Correct 37 ms 7848 KB Output is correct
22 Correct 32 ms 7104 KB Output is correct
23 Correct 36 ms 7780 KB Output is correct
24 Correct 3 ms 3412 KB Output is correct
25 Correct 3 ms 3412 KB Output is correct
26 Correct 23 ms 6068 KB Output is correct
27 Correct 16 ms 5332 KB Output is correct
28 Correct 47 ms 8892 KB Output is correct
29 Correct 40 ms 8856 KB Output is correct
30 Correct 41 ms 8912 KB Output is correct
31 Correct 42 ms 8908 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 272 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 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 212 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 248 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 15 ms 1872 KB Output is correct
49 Correct 15 ms 2112 KB Output is correct
50 Correct 14 ms 2004 KB Output is correct
51 Correct 15 ms 2004 KB Output is correct
52 Correct 17 ms 2004 KB Output is correct
53 Correct 29 ms 3800 KB Output is correct
54 Correct 3 ms 596 KB Output is correct
55 Correct 10 ms 1284 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 4 ms 596 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 71 ms 8596 KB Output is correct
60 Correct 107 ms 11228 KB Output is correct
61 Correct 109 ms 10736 KB Output is correct
62 Correct 104 ms 10820 KB Output is correct
63 Correct 98 ms 12240 KB Output is correct
64 Correct 103 ms 10728 KB Output is correct
65 Correct 110 ms 10720 KB Output is correct
66 Correct 43 ms 4608 KB Output is correct
67 Correct 107 ms 11744 KB Output is correct
68 Correct 43 ms 8900 KB Output is correct
69 Correct 48 ms 5688 KB Output is correct
70 Correct 89 ms 11224 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 3 ms 3412 KB Output is correct
78 Correct 3 ms 3412 KB Output is correct
79 Correct 3 ms 3412 KB Output is correct
80 Correct 4 ms 3412 KB Output is correct
81 Correct 51 ms 7872 KB Output is correct
82 Correct 79 ms 11224 KB Output is correct
83 Correct 83 ms 11216 KB Output is correct
84 Correct 120 ms 13964 KB Output is correct
85 Correct 124 ms 14168 KB Output is correct
86 Correct 146 ms 14924 KB Output is correct
87 Correct 127 ms 15332 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 133 ms 15332 KB Output is correct
90 Correct 116 ms 14840 KB Output is correct
91 Correct 115 ms 14692 KB Output is correct