# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
626655 |
2022-08-11T15:31:25 Z |
d4xn |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
43224 KB |
#pragma GCC optimize ("Ofast")
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define tuple2 tuple<int, int>
#define tuple3 tuple<int, int, int>
const int N = 300;
int n, m;
vi c[N];
unordered_map<int, int> w[N];
map<int, ll> pre[N];
unordered_map<int, ll> dp[3][N];
ll preS(int col, int x) {
auto it = pre[col].upper_bound(x);
if (it == pre[col].begin()) return 0;
return (--it)->second;
}
ll mx(int curr, int h1, int state) {
if (curr == -1) return 0;
auto it = dp[state][curr].find(h1);
if (it != dp[state][curr].end()) return it->second;
if (state != 2) dp[state][curr][h1] = mx(curr-1, h1, 2);
else dp[state][curr][h1] = mx(curr-1, 0, 1);
it = dp[state][curr].find(h1);
if (!state) {
if (curr+1 < n) {
for (int h : c[curr+1]) {
h++;
if (h >= h1) break;
ll cnt = 0;
// ver si pillo los de la izquierda
if (curr-1 >= 0) {
cnt += preS(curr-1, h-1);
}
// ver si he eliminado alguno de los que he pillado
cnt -= preS(curr, h-1);
it->second = max(it->second, cnt + mx(curr-1, h, 0));
}
}
if (curr-1 >= 0) {
for (int h : c[curr-1]) {
h++;
if (h >= h1) break;
ll cnt = 0;
// ver si pillo los de la izquierda
if (curr-1 >= 0) {
cnt += preS(curr-1, h-1);
}
// ver si he eliminado alguno de los que he pillado
cnt -= preS(curr, h-1);
it->second = max(it->second, cnt + mx(curr-1, h, 0));
}
}
}
else if (state == 1) {
if (curr+1 < n) {
for (int h : c[curr+1]) {
h++;
ll cnt = 0;
// ver si pillo los de la izquierda
if (curr-1 >= 0) {
cnt += preS(curr-1, h-1);
}
// ver si pillo los de la derecha
if (h > h1 && curr+1 < n) {
cnt += preS(curr+1, h-1) - preS(curr+1, h1-1);
}
// ver si he eliminado alguno de los que he pillado
cnt -= preS(curr, min(h, h1)-1);
if (h <= h1) it->second = max(it->second, cnt + mx(curr-1, h, 0));
else it->second = max(it->second, cnt + mx(curr-1, h, 1));
}
}
if (curr-1 >= 0) {
for (int h : c[curr-1]) {
h++;
ll cnt = 0;
// ver si pillo los de la izquierda
if (curr-1 >= 0) {
cnt += preS(curr-1, h-1);
}
// ver si pillo los de la derecha
if (h > h1 && curr+1 < n) {
cnt += preS(curr+1, h-1) - preS(curr+1, h1-1);
}
// ver si he eliminado alguno de los que he pillado
cnt -= preS(curr, min(h, h1)-1);
if (h <= h1) it->second = max(it->second, cnt + mx(curr-1, h, 0));
else it->second = max(it->second, cnt + mx(curr-1, h, 1));
}
}
}
else {
if (curr+1 < n) {
for (int h : c[curr+1]) {
h++;
ll cnt = 0;
// ver si pillo los de la izquierda
if (curr-1 >= 0) {
cnt += preS(curr-1, h-1);
}
// ver si pillo los de la derecha
if (h > h1 && curr+1 < n) {
cnt += preS(curr+1, h-1) - preS(curr+1, h1-1);
}
it->second = max(it->second, cnt + mx(curr-1, h, 1));
}
}
if (curr-1 >= 0) {
for (int h : c[curr-1]) {
h++;
ll cnt = 0;
// ver si pillo los de la izquierda
if (curr-1 >= 0) {
cnt += preS(curr-1, h-1);
}
// ver si pillo los de la derecha
if (h > h1 && curr+1 < n) {
cnt += preS(curr+1, h-1) - preS(curr+1, h1-1);
}
it->second = max(it->second, cnt + mx(curr-1, h, 1));
}
}
}
return it->second;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
n = N;
m = M;
for (int i = 0; i < m; i++) {
c[X[i]].push_back(Y[i]);
w[X[i]][Y[i]] = W[i];
}
for (int i = 0; i < n; i++) {
sort(c[i].begin(), c[i].end());
ll sum = 0;
for (int &h : c[i]) {
sum += w[i][h];
pre[i][h] = sum;
}
pre[i][-1] = 0;
}
return mx(n-1, 0, 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
21812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
124 ms |
43224 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
49 ms |
968 KB |
Output is correct |
17 |
Execution timed out |
1078 ms |
7852 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
49 ms |
968 KB |
Output is correct |
17 |
Execution timed out |
1078 ms |
7852 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
21812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |