# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
702974 |
2023-02-25T11:44:00 Z |
n1k |
Catfish Farm (IOI22_fish) |
C++17 |
|
756 ms |
2097152 KB |
#include <bits/stdc++.h>
#define ll long long
#define vt vector
#define pb push_back
#define ar array
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
using namespace std;
/*
## TAKE IT EASY ##
1. simplify
2. add new elements
3. brute force solution
4. optimize
5. start implementing
*/
// --- templates ---
// --- code ---
const int N = 300 + 10, FLOW = 3;
ll dp[N][FLOW][N];
ll max_weights(int n, int m, vt<int> X, vt<int> Y, vt<int> W){
memset(dp, 0, sizeof dp);
int h = n + 5;
vt<vt<ll>> a(n + 5, vt<ll>(h));
for(int i = 0; i < m; i++){
a[X[i]][Y[i] + 1] = W[i];
}
for(int i = 0; i < n; i++){
for(int j = 1; j < h; j++){
a[i][j] += a[i][j - 1];
}
}
for(int i = 0; i < n; i++){
for(int flow = 0; flow < FLOW; flow++){
for(int h1 = 0; h1 < h; h1++){
for(int h2 = 0; h2 < (flow == 0 ? h1 + 1 : h); h2++){
int nflow = h1 <= h2;
if(i == 0){
dp[i][nflow][h2] = max(dp[i][nflow][h2], a[i + 1][h2]);
}else{
if(flow == 0){
dp[i][nflow][h2] = max(dp[i][nflow][h2], dp[i - 1][flow][h1] + a[i + 1][h2] - a[i][h2]);
}else if(flow == 1){
dp[i][nflow][h2] = max(dp[i][nflow][h2], dp[i - 1][flow][h1] + a[i + 1][h2] + max((ll)0, (a[i - 1][h2] - a[i - 1][h1])) - min(a[i][h1], a[i][h1]));
}else{
nflow = 1;
dp[i][nflow][h2] = max(dp[i][nflow][h2], dp[i - 1][flow][h1] + a[i + 1][h2] + max((ll)0, (a[i - 1][h2] - a[i - 1][h1])));
}
}
}
if(i)
dp[i][2][h1] = max(dp[i - 1][0][h1], dp[i - 1][1][h1]);
}
}
}
ll ans = 0;
for(int flow = 0; flow < FLOW; flow++){
for(int h1 = 0; h1 < h; h1++){
ans = max(ans, dp[n - 1][flow][h1]);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
744 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2516 KB |
Output is correct |
2 |
Runtime error |
756 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
725 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2516 KB |
Output is correct |
2 |
Correct |
1 ms |
2516 KB |
Output is correct |
3 |
Correct |
1 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
2516 KB |
Output is correct |
5 |
Correct |
1 ms |
2516 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2516 KB |
Output is correct |
9 |
Correct |
29 ms |
2644 KB |
Output is correct |
10 |
Incorrect |
212 ms |
3284 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2516 KB |
Output is correct |
2 |
Correct |
1 ms |
2516 KB |
Output is correct |
3 |
Correct |
1 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
2516 KB |
Output is correct |
5 |
Correct |
1 ms |
2516 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2516 KB |
Output is correct |
9 |
Correct |
29 ms |
2644 KB |
Output is correct |
10 |
Incorrect |
212 ms |
3284 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2516 KB |
Output is correct |
2 |
Correct |
1 ms |
2516 KB |
Output is correct |
3 |
Correct |
1 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
2516 KB |
Output is correct |
5 |
Correct |
1 ms |
2516 KB |
Output is correct |
6 |
Correct |
1 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2516 KB |
Output is correct |
9 |
Correct |
29 ms |
2644 KB |
Output is correct |
10 |
Incorrect |
212 ms |
3284 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
725 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
744 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |