Submission #628384

# Submission time Handle Problem Language Result Execution time Memory
628384 2022-08-13T11:08:27 Z abeker Catfish Farm (IOI22_fish) C++17
100 / 100
652 ms 50388 KB
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;

typedef long long ll;

const ll INF = 1e18;

ll max_weights(int N, int M, vector <int> x, vector <int> y, vector <int> w) {
  for (auto &it : x)
    it++;
  vector <ll> sum(N + 2);
  vector <map <int, ll>> diff(N + 2);
  for (int i = 0; i < M; i++) {
    sum[x[i]] += w[i];
    diff[x[i] + 1][y[i]] += w[i];
    diff[x[i]][y[i]] -= w[i];
  }
  vector <pair <int, int>> edges;
  for (int i = 0; i < 5; i++)
    edges.emplace_back(i, (i + 1) % 5);
  for (auto it : {0, 1, 4})
    edges.emplace_back(it, it);
  for (auto it : {2, 3}) {
    edges.emplace_back(0, it);
    edges.emplace_back(it, 0);
  }
  vector <ll> dp(5);
  dp[3] = dp[4] = -INF;
  for (int i = 1; ; i++) {
    auto update = [&](ll &ref, ll val) {
      if (val > ref)
        ref = val;
    };
    ll curr = 0;
    vector <ll> trans(5);
    for (auto it : diff[i]) {
      curr += it.second;
      update(trans[1], curr);
      update(trans[4], -curr);
    }
    trans[2] = sum[i - 1];
    trans[3] = sum[i];
    for (int j = 0; j < 5; j++)
      dp[j] += trans[j];
    if (i == N + 1)
      break;
    vector <ll> nxt(5, -INF);
    for (auto it : edges)
      update(nxt[it.second], dp[it.first]);
    dp = nxt;
  }
  return max({dp[0], dp[3], dp[4], 0ll});
}
# Verdict Execution time Memory Grader output
1 Correct 121 ms 17228 KB Output is correct
2 Correct 155 ms 20532 KB Output is correct
3 Correct 10 ms 5716 KB Output is correct
4 Correct 10 ms 5716 KB Output is correct
5 Correct 652 ms 50388 KB Output is correct
6 Correct 358 ms 50264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 272 ms 24840 KB Output is correct
3 Correct 360 ms 29228 KB Output is correct
4 Correct 125 ms 17124 KB Output is correct
5 Correct 179 ms 20592 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 0 ms 212 KB Output is correct
10 Correct 10 ms 5716 KB Output is correct
11 Correct 10 ms 5716 KB Output is correct
12 Correct 114 ms 17260 KB Output is correct
13 Correct 161 ms 20648 KB Output is correct
14 Correct 124 ms 17232 KB Output is correct
15 Correct 111 ms 16588 KB Output is correct
16 Correct 109 ms 17308 KB Output is correct
17 Correct 130 ms 19160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5716 KB Output is correct
2 Correct 11 ms 5716 KB Output is correct
3 Correct 40 ms 10032 KB Output is correct
4 Correct 27 ms 9568 KB Output is correct
5 Correct 66 ms 14556 KB Output is correct
6 Correct 58 ms 15356 KB Output is correct
7 Correct 62 ms 15936 KB Output is correct
8 Correct 66 ms 15880 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 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 340 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 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 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 340 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 0 ms 340 KB Output is correct
16 Correct 2 ms 424 KB Output is correct
17 Correct 34 ms 4804 KB Output is correct
18 Correct 37 ms 4436 KB Output is correct
19 Correct 32 ms 4404 KB Output is correct
20 Correct 31 ms 4200 KB Output is correct
21 Correct 27 ms 4180 KB Output is correct
22 Correct 66 ms 8012 KB Output is correct
23 Correct 7 ms 1492 KB Output is correct
24 Correct 22 ms 4052 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 6 ms 1364 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 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 340 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 0 ms 340 KB Output is correct
16 Correct 2 ms 424 KB Output is correct
17 Correct 34 ms 4804 KB Output is correct
18 Correct 37 ms 4436 KB Output is correct
19 Correct 32 ms 4404 KB Output is correct
20 Correct 31 ms 4200 KB Output is correct
21 Correct 27 ms 4180 KB Output is correct
22 Correct 66 ms 8012 KB Output is correct
23 Correct 7 ms 1492 KB Output is correct
24 Correct 22 ms 4052 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 6 ms 1364 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 274 ms 21840 KB Output is correct
29 Correct 515 ms 32928 KB Output is correct
30 Correct 499 ms 43852 KB Output is correct
31 Correct 529 ms 43732 KB Output is correct
32 Correct 387 ms 26156 KB Output is correct
33 Correct 520 ms 44496 KB Output is correct
34 Correct 505 ms 44420 KB Output is correct
35 Correct 155 ms 15564 KB Output is correct
36 Correct 494 ms 41268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5716 KB Output is correct
2 Correct 11 ms 5716 KB Output is correct
3 Correct 40 ms 10032 KB Output is correct
4 Correct 27 ms 9568 KB Output is correct
5 Correct 66 ms 14556 KB Output is correct
6 Correct 58 ms 15356 KB Output is correct
7 Correct 62 ms 15936 KB Output is correct
8 Correct 66 ms 15880 KB Output is correct
9 Correct 94 ms 21460 KB Output is correct
10 Correct 85 ms 12868 KB Output is correct
11 Correct 154 ms 24284 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 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 9 ms 5716 KB Output is correct
19 Correct 9 ms 5716 KB Output is correct
20 Correct 10 ms 5716 KB Output is correct
21 Correct 11 ms 5716 KB Output is correct
22 Correct 101 ms 20828 KB Output is correct
23 Correct 190 ms 29616 KB Output is correct
24 Correct 206 ms 31288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 17228 KB Output is correct
2 Correct 155 ms 20532 KB Output is correct
3 Correct 10 ms 5716 KB Output is correct
4 Correct 10 ms 5716 KB Output is correct
5 Correct 652 ms 50388 KB Output is correct
6 Correct 358 ms 50264 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 272 ms 24840 KB Output is correct
9 Correct 360 ms 29228 KB Output is correct
10 Correct 125 ms 17124 KB Output is correct
11 Correct 179 ms 20592 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 0 ms 212 KB Output is correct
16 Correct 10 ms 5716 KB Output is correct
17 Correct 10 ms 5716 KB Output is correct
18 Correct 114 ms 17260 KB Output is correct
19 Correct 161 ms 20648 KB Output is correct
20 Correct 124 ms 17232 KB Output is correct
21 Correct 111 ms 16588 KB Output is correct
22 Correct 109 ms 17308 KB Output is correct
23 Correct 130 ms 19160 KB Output is correct
24 Correct 13 ms 5716 KB Output is correct
25 Correct 11 ms 5716 KB Output is correct
26 Correct 40 ms 10032 KB Output is correct
27 Correct 27 ms 9568 KB Output is correct
28 Correct 66 ms 14556 KB Output is correct
29 Correct 58 ms 15356 KB Output is correct
30 Correct 62 ms 15936 KB Output is correct
31 Correct 66 ms 15880 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 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 0 ms 340 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 0 ms 340 KB Output is correct
47 Correct 2 ms 424 KB Output is correct
48 Correct 34 ms 4804 KB Output is correct
49 Correct 37 ms 4436 KB Output is correct
50 Correct 32 ms 4404 KB Output is correct
51 Correct 31 ms 4200 KB Output is correct
52 Correct 27 ms 4180 KB Output is correct
53 Correct 66 ms 8012 KB Output is correct
54 Correct 7 ms 1492 KB Output is correct
55 Correct 22 ms 4052 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 6 ms 1364 KB Output is correct
58 Correct 2 ms 852 KB Output is correct
59 Correct 274 ms 21840 KB Output is correct
60 Correct 515 ms 32928 KB Output is correct
61 Correct 499 ms 43852 KB Output is correct
62 Correct 529 ms 43732 KB Output is correct
63 Correct 387 ms 26156 KB Output is correct
64 Correct 520 ms 44496 KB Output is correct
65 Correct 505 ms 44420 KB Output is correct
66 Correct 155 ms 15564 KB Output is correct
67 Correct 494 ms 41268 KB Output is correct
68 Correct 94 ms 21460 KB Output is correct
69 Correct 85 ms 12868 KB Output is correct
70 Correct 154 ms 24284 KB Output is correct
71 Correct 0 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 9 ms 5716 KB Output is correct
78 Correct 9 ms 5716 KB Output is correct
79 Correct 10 ms 5716 KB Output is correct
80 Correct 11 ms 5716 KB Output is correct
81 Correct 101 ms 20828 KB Output is correct
82 Correct 190 ms 29616 KB Output is correct
83 Correct 206 ms 31288 KB Output is correct
84 Correct 610 ms 46920 KB Output is correct
85 Correct 597 ms 47372 KB Output is correct
86 Correct 375 ms 49460 KB Output is correct
87 Correct 397 ms 50364 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 378 ms 50316 KB Output is correct
90 Correct 376 ms 44892 KB Output is correct
91 Correct 338 ms 35884 KB Output is correct