# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1106960 | 2024-10-31T10:09:25 Z | I_am_Polish_Girl | Catfish Farm (IOI22_fish) | C++17 | 127 ms | 24176 KB |
#include "fish.h" #include <vector> #include <algorithm> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <stack> #include <queue> #include <cmath> #include <random> #include <chrono> #include <iomanip> #include <iostream> #include <bitset> #include <cmath> #include <string> using namespace std; int log_ = 23; int inf = 2000000007; int mod = 1000000007; int p = 523; #include <vector> long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { int n = N; vector <vector <pair <int, int>>> vp(n); for (int i = 0; i < X.size(); i++) { vp[X[i]].push_back({ Y[i] , W[i] }); } for (int i = 0; i < n; i++) { sort(vp[i].begin(), vp[i].end()); } vector <vector <long long>> dp0(n); vector <vector <long long>> dp1(n); for (int i = 0; i < n; i++) { dp0[i].resize(vp[i].size()); dp1[i].resize(vp[i].size()); } long long ans = 0; long long mx_ = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < vp[i].size(); j++) { ans = max(ans , mx_ + vp[i][j].second); } if (i > 0) { if (i != n - 1) { int ind = 0; int sz = vp[i].size(); long long mx = 0; for (int j = 0; j < sz; j++) { while ((ind < vp[i - 1].size()) and (vp[i - 1][ind].first < vp[i][j].first)) { mx = max(mx, dp0[i - 1][ind]); ind++; } mx = max(mx, mx_); dp0[i][j] = mx + vp[i][j].second; mx = max(mx, dp0[i][j]); } } if (i != 0) { int ind = vp[i - 1].size(); ind--; int sz = vp[i].size(); long long mx = 0; for (int j = sz - 1; j >= 0; j--) { while ((ind >= 0) and (vp[i - 1][ind].first > vp[i][j].first)) { mx = max(mx, dp1[i - 1][ind]); ind--; } mx = max(mx, mx_); dp1[i][j] = mx + vp[i][j].second; mx = max(mx, dp1[i][j]); } } } else { long long s = 0; for (int j = 0; j < vp[i].size(); j++) { s += vp[i][j].second; dp0[i][j] = s; dp1[i][j] = 0; } } for (int j = 0; j < vp[i].size(); j++) { ans = max(ans, dp0[i][j]); ans = max(ans, dp1[i][j]); } if (i - 1 >= 0) { for (int j = 0; j < vp[i - 1].size(); j++) { mx_ = max(mx_, dp0[i - 1][j]); mx_ = max(mx_, dp1[i - 1][j]); } } } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 10692 KB | Output is correct |
2 | Correct | 29 ms | 12224 KB | Output is correct |
3 | Correct | 3 ms | 7248 KB | Output is correct |
4 | Correct | 3 ms | 7248 KB | Output is correct |
5 | Correct | 86 ms | 21420 KB | Output is correct |
6 | Correct | 127 ms | 24176 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 47 ms | 14520 KB | Output is correct |
3 | Correct | 62 ms | 16968 KB | Output is correct |
4 | Correct | 24 ms | 10692 KB | Output is correct |
5 | Correct | 31 ms | 13996 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 0 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 508 KB | Output is correct |
10 | Correct | 4 ms | 7248 KB | Output is correct |
11 | Correct | 2 ms | 7248 KB | Output is correct |
12 | Correct | 23 ms | 10612 KB | Output is correct |
13 | Correct | 29 ms | 12228 KB | Output is correct |
14 | Correct | 24 ms | 12124 KB | Output is correct |
15 | Correct | 26 ms | 11964 KB | Output is correct |
16 | Correct | 24 ms | 12108 KB | Output is correct |
17 | Correct | 29 ms | 11716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Incorrect | 22 ms | 12872 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 0 ms | 336 KB | Output is correct |
7 | Correct | 0 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Incorrect | 1 ms | 336 KB | 1st lines differ - on the 1st token, expected: '216624184325', found: '165331649672' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 0 ms | 336 KB | Output is correct |
7 | Correct | 0 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Incorrect | 1 ms | 336 KB | 1st lines differ - on the 1st token, expected: '216624184325', found: '165331649672' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 0 ms | 336 KB | Output is correct |
7 | Correct | 0 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Incorrect | 1 ms | 336 KB | 1st lines differ - on the 1st token, expected: '216624184325', found: '165331649672' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 7248 KB | Output is correct |
2 | Correct | 2 ms | 7248 KB | Output is correct |
3 | Incorrect | 22 ms | 12872 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 10692 KB | Output is correct |
2 | Correct | 29 ms | 12224 KB | Output is correct |
3 | Correct | 3 ms | 7248 KB | Output is correct |
4 | Correct | 3 ms | 7248 KB | Output is correct |
5 | Correct | 86 ms | 21420 KB | Output is correct |
6 | Correct | 127 ms | 24176 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 47 ms | 14520 KB | Output is correct |
9 | Correct | 62 ms | 16968 KB | Output is correct |
10 | Correct | 24 ms | 10692 KB | Output is correct |
11 | Correct | 31 ms | 13996 KB | Output is correct |
12 | Correct | 1 ms | 336 KB | Output is correct |
13 | Correct | 0 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 508 KB | Output is correct |
16 | Correct | 4 ms | 7248 KB | Output is correct |
17 | Correct | 2 ms | 7248 KB | Output is correct |
18 | Correct | 23 ms | 10612 KB | Output is correct |
19 | Correct | 29 ms | 12228 KB | Output is correct |
20 | Correct | 24 ms | 12124 KB | Output is correct |
21 | Correct | 26 ms | 11964 KB | Output is correct |
22 | Correct | 24 ms | 12108 KB | Output is correct |
23 | Correct | 29 ms | 11716 KB | Output is correct |
24 | Correct | 2 ms | 7248 KB | Output is correct |
25 | Correct | 2 ms | 7248 KB | Output is correct |
26 | Incorrect | 22 ms | 12872 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
27 | Halted | 0 ms | 0 KB | - |