Submission #644036

# Submission time Handle Problem Language Result Execution time Memory
644036 2022-09-23T15:31:18 Z NintsiChkhaidze Catfish Farm (IOI22_fish) C++17
52 / 100
753 ms 718496 KB
#include "fish.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int N = 3005;
ll p[N][N],dp[N][N][5],suff[N][N],pref[N][N],sfc[N][N],prc[N][N];
 
ll 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]++;
    p[X[i]][Y[i]] += W[i];
  }
 
  for (int j = 1; j <= n; j++)
    for (int i = 1; i <= n; i++)
      p[j][i] += p[j][i - 1];
 
  for (int j = 1; j <= n; j++){
    for (int a = 0; a <= n; a++){
      
      //update dp[j][a][0]
      dp[j][a][0] = max(dp[j][a][0], suff[j - 1][a] - p[j][a]);
 
      //update dp[j][a][1]
      dp[j][a][1] = max(dp[j][a][1], pref[j - 1][a] + p[j - 1][a]);
      
      //c 0 a
      
      if (j >= 3){
        dp[j][a][1] = max(dp[j][a][1], prc[j - 2][a] + p[j - 1][a]);
        dp[j][a][1] = max(dp[j][a][1], sfc[j - 2][a]);
      }
      
    }

    for (int a = n; a >= 0; a--)
      suff[j][a] = max(suff[j][a+1],max(dp[j][a][0],dp[j][a][1]) + p[j + 1][a]);

    pref[j][0] = dp[j][0][1] - p[j][0];
    for (int a =1; a <= n; a++)
      pref[j][a] = max(pref[j][a - 1],dp[j][a][1] - p[j][a]);

    prc[j][0] = max(dp[j][0][0],dp[j][0][1]);
    for (int a = 1; a <= n; a++)
        prc[j][a] = max(prc[j][a - 1], max(dp[j][a][0],dp[j][a][1])); 
    
    for (int a = n; a >= 0; a--)
        sfc[j][a] = max(sfc[j][a + 1],max(dp[j][a][0],dp[j][a][1]) + p[j + 1][a]);
  }
 
  ll ans = 0;
  for (int a = 0; a <= n; a++)
      ans=max(ans,max(dp[n][a][0],dp[n][a][1]));
  return ans;
}

# Verdict Execution time Memory Grader output
1 Runtime error 696 ms 74012 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 722 ms 77252 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 753 ms 70964 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 Correct 1 ms 468 KB Output is correct
3 Correct 1 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 1 ms 308 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
10 Correct 9 ms 14676 KB Output is correct
11 Correct 4 ms 5716 KB Output is correct
12 Correct 10 ms 14648 KB Output is correct
13 Correct 2 ms 2516 KB Output is correct
14 Correct 9 ms 14624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 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 1 ms 308 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
10 Correct 9 ms 14676 KB Output is correct
11 Correct 4 ms 5716 KB Output is correct
12 Correct 10 ms 14648 KB Output is correct
13 Correct 2 ms 2516 KB Output is correct
14 Correct 9 ms 14624 KB Output is correct
15 Correct 9 ms 14676 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 25 ms 16332 KB Output is correct
18 Correct 23 ms 16288 KB Output is correct
19 Correct 22 ms 16268 KB Output is correct
20 Correct 24 ms 16328 KB Output is correct
21 Correct 24 ms 16248 KB Output is correct
22 Correct 36 ms 18124 KB Output is correct
23 Correct 11 ms 14804 KB Output is correct
24 Correct 18 ms 15704 KB Output is correct
25 Correct 10 ms 14612 KB Output is correct
26 Correct 12 ms 14828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 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 1 ms 308 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
10 Correct 9 ms 14676 KB Output is correct
11 Correct 4 ms 5716 KB Output is correct
12 Correct 10 ms 14648 KB Output is correct
13 Correct 2 ms 2516 KB Output is correct
14 Correct 9 ms 14624 KB Output is correct
15 Correct 9 ms 14676 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 25 ms 16332 KB Output is correct
18 Correct 23 ms 16288 KB Output is correct
19 Correct 22 ms 16268 KB Output is correct
20 Correct 24 ms 16328 KB Output is correct
21 Correct 24 ms 16248 KB Output is correct
22 Correct 36 ms 18124 KB Output is correct
23 Correct 11 ms 14804 KB Output is correct
24 Correct 18 ms 15704 KB Output is correct
25 Correct 10 ms 14612 KB Output is correct
26 Correct 12 ms 14828 KB Output is correct
27 Correct 672 ms 705968 KB Output is correct
28 Correct 113 ms 71224 KB Output is correct
29 Correct 625 ms 718364 KB Output is correct
30 Correct 603 ms 718496 KB Output is correct
31 Correct 605 ms 718464 KB Output is correct
32 Correct 125 ms 48932 KB Output is correct
33 Correct 624 ms 718460 KB Output is correct
34 Correct 600 ms 717984 KB Output is correct
35 Correct 526 ms 710044 KB Output is correct
36 Correct 598 ms 716396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 753 ms 70964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 696 ms 74012 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -