Submission #630510

# Submission time Handle Problem Language Result Execution time Memory
630510 2022-08-16T12:46:13 Z CSQ31 Catfish Farm (IOI22_fish) C++17
52 / 100
548 ms 365632 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int f[3001][3001];
ll dp[2][3001][3001];
//0 -> previous is lower
//1 -> previous is higher
const ll INF = -1e17;
long long max_weights(int n, int m, vector<int> X, vector<int> Y,vector<int> W) {
	for(int i=0;i<m;i++){
		X[i]++;
		Y[i]++;
		f[X[i]][Y[i]] = W[i];
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++)dp[0][i][j] = dp[1][i][j] = INF;	
	}
	dp[0][0][0] = 0;
	for(int i=1;i<=n;i++){
		ll mx = INF;
		ll sum = 0;
		for(int j=0;j<=n;j++){
			sum+=f[i-1][j];
			mx = max(mx,dp[0][i-1][j] - sum);
			dp[0][i][j] = max(dp[0][i][j],mx+sum);
		}
		mx = INF;
		sum = 0;
		for(int j=0;j<=n;j++)sum+=f[i][j];
		for(int j=n;j>=0;j--){
			mx = max(dp[0][i-1][j]+sum,mx);
			mx = max(dp[1][i-1][j]+sum,mx);
			dp[1][i][j] = max(dp[1][i][j],mx - sum);
			sum-=f[i][j];
		}
		if(i>=2){
			sum = 0;
			mx = INF;
			for(int j=0;j<=n;j++){
				sum+=f[i-1][j];
				mx = max(mx,dp[0][i-2][j]);
				mx = max(mx,dp[1][i-2][j]);
				dp[0][i][j] = max(dp[0][i][j],mx+sum);
			}
			mx = INF;
			for(int j=n;j>=0;j--){
				mx = max(mx,dp[0][i-2][j]+sum);
				mx = max(mx,dp[1][i-2][j]+sum);
				dp[0][i][j] = max(dp[0][i][j],mx-sum);
				sum-=f[i-1][j];
			}
			
			
		}
	}
  ll ans = 0;
  for(int i=0;i<=n;i++){
	  ans = max(ans,dp[0][n][i]);
	  ans = max(ans,dp[1][n][i]);
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 511 ms 361964 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 Runtime error 548 ms 365632 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 526 ms 357636 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 0 ms 340 KB Output is correct
4 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 2 ms 2388 KB Output is correct
10 Correct 4 ms 5404 KB Output is correct
11 Correct 1 ms 2516 KB Output is correct
12 Correct 3 ms 5392 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 4 ms 5368 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 0 ms 340 KB Output is correct
4 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 2 ms 2388 KB Output is correct
10 Correct 4 ms 5404 KB Output is correct
11 Correct 1 ms 2516 KB Output is correct
12 Correct 3 ms 5392 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 4 ms 5368 KB Output is correct
15 Correct 3 ms 5332 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 17 ms 6876 KB Output is correct
18 Correct 15 ms 6612 KB Output is correct
19 Correct 16 ms 7236 KB Output is correct
20 Correct 18 ms 7116 KB Output is correct
21 Correct 17 ms 7128 KB Output is correct
22 Correct 39 ms 9080 KB Output is correct
23 Correct 6 ms 5844 KB Output is correct
24 Correct 13 ms 6688 KB Output is correct
25 Correct 3 ms 5332 KB Output is correct
26 Correct 6 ms 5716 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 0 ms 340 KB Output is correct
4 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 2 ms 2388 KB Output is correct
10 Correct 4 ms 5404 KB Output is correct
11 Correct 1 ms 2516 KB Output is correct
12 Correct 3 ms 5392 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 4 ms 5368 KB Output is correct
15 Correct 3 ms 5332 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 17 ms 6876 KB Output is correct
18 Correct 15 ms 6612 KB Output is correct
19 Correct 16 ms 7236 KB Output is correct
20 Correct 18 ms 7116 KB Output is correct
21 Correct 17 ms 7128 KB Output is correct
22 Correct 39 ms 9080 KB Output is correct
23 Correct 6 ms 5844 KB Output is correct
24 Correct 13 ms 6688 KB Output is correct
25 Correct 3 ms 5332 KB Output is correct
26 Correct 6 ms 5716 KB Output is correct
27 Correct 146 ms 153412 KB Output is correct
28 Correct 82 ms 24784 KB Output is correct
29 Correct 239 ms 153252 KB Output is correct
30 Correct 269 ms 180336 KB Output is correct
31 Correct 264 ms 180972 KB Output is correct
32 Correct 95 ms 22984 KB Output is correct
33 Correct 258 ms 186740 KB Output is correct
34 Correct 263 ms 186820 KB Output is correct
35 Correct 180 ms 158936 KB Output is correct
36 Correct 260 ms 161100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 526 ms 357636 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 511 ms 361964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -