Submission #644071

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

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

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

# Verdict Execution time Memory Grader output
1 Runtime error 746 ms 149288 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 769 ms 154344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 790 ms 143812 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 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 2684 KB Output is correct
10 Correct 5 ms 6228 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 5 ms 6100 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 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 2684 KB Output is correct
10 Correct 5 ms 6228 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 5 ms 6100 KB Output is correct
15 Correct 5 ms 6100 KB Output is correct
16 Correct 2 ms 1492 KB Output is correct
17 Correct 21 ms 7884 KB Output is correct
18 Correct 17 ms 8192 KB Output is correct
19 Correct 25 ms 8196 KB Output is correct
20 Correct 18 ms 8084 KB Output is correct
21 Correct 17 ms 8148 KB Output is correct
22 Correct 34 ms 9896 KB Output is correct
23 Correct 8 ms 6512 KB Output is correct
24 Correct 14 ms 7380 KB Output is correct
25 Correct 4 ms 6188 KB Output is correct
26 Correct 7 ms 6484 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 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 2684 KB Output is correct
10 Correct 5 ms 6228 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 5 ms 6100 KB Output is correct
15 Correct 5 ms 6100 KB Output is correct
16 Correct 2 ms 1492 KB Output is correct
17 Correct 21 ms 7884 KB Output is correct
18 Correct 17 ms 8192 KB Output is correct
19 Correct 25 ms 8196 KB Output is correct
20 Correct 18 ms 8084 KB Output is correct
21 Correct 17 ms 8148 KB Output is correct
22 Correct 34 ms 9896 KB Output is correct
23 Correct 8 ms 6512 KB Output is correct
24 Correct 14 ms 7380 KB Output is correct
25 Correct 4 ms 6188 KB Output is correct
26 Correct 7 ms 6484 KB Output is correct
27 Correct 191 ms 212296 KB Output is correct
28 Correct 88 ms 34584 KB Output is correct
29 Correct 307 ms 226608 KB Output is correct
30 Correct 310 ms 226336 KB Output is correct
31 Correct 345 ms 225748 KB Output is correct
32 Correct 112 ms 29044 KB Output is correct
33 Correct 311 ms 223856 KB Output is correct
34 Correct 319 ms 223076 KB Output is correct
35 Correct 242 ms 216976 KB Output is correct
36 Correct 308 ms 223564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 790 ms 143812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 746 ms 149288 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -