Submission #1056948

# Submission time Handle Problem Language Result Execution time Memory
1056948 2024-08-13T12:38:02 Z noyancanturk Catfish Farm (IOI22_fish) C++17
35 / 100
1000 ms 163920 KB
#include "fish.h"

#include<bits/stdc++.h>
using namespace std;

using lint=long long;

const int lim=3e3+100;

using pii=pair<int,lint>;

int n,m;
lint dp[lim][lim],up[lim][lim];
vector<pii>pref[lim];
lint p(int i,int l,int r){
  auto rp=lower_bound(pref[i].begin(),pref[i].end(),pii{r+1,0}),
       lp=lower_bound(pref[i].begin(),pref[i].end(),pii{l,0});
  rp--;
  if(lp==pref[i].begin())return rp->second;
  lp--;
  return rp->second-lp->second;
}

lint 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++){
    pref[X[i]].push_back({Y[i]+1,W[i]});
  }
  for(int i=0;i<=n;i++){
    pref[i].push_back({0,0});
    sort(pref[i].begin(),pref[i].end());
    for(int j=1;j<pref[i].size();j++){
      pref[i][j].second+=pref[i][j-1].second;
    }
  }
  n=N,m=M;
  for(int i=0;i<=n;i++){
    dp[0][i]=p(1,0,i);
  }
  for(int i=1;i<n;i++){
    lint max1=0;
    for(int j=0;j<=n;j++){
      max1=max(max1,up[i-1][j]-p(i-1,0,j));
      dp[i][j]=max(dp[i][j],max1+p(i-1,0,j)+p(i+1,0,j));
      up[i][j]=max(up[i][j],max1+p(i-1,0,j));
      up[i][j]=max(up[i][j],dp[i-1][j]);
    }  
    max1=0;
    for(int j=n;0<=j;j--){
      max1=max(max1,dp[i-1][j]);
      dp[i][j]=max(dp[i][j],max1-p(i,0,j)+p(i+1,0,j));
    }
  }
  lint ans=0;
  for(int i=0;i<=n;i++){
    ans=max(ans,dp[n-1][i]);
  }
  return ans;
}

Compilation message

fish.cpp: In function 'lint max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int j=1;j<pref[i].size();j++){
      |                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 22808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Execution timed out 1061 ms 24948 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 18256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 2 ms 3932 KB Output is correct
10 Correct 8 ms 6232 KB Output is correct
11 Correct 2 ms 3932 KB Output is correct
12 Correct 7 ms 6236 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 7 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 2 ms 3932 KB Output is correct
10 Correct 8 ms 6232 KB Output is correct
11 Correct 2 ms 3932 KB Output is correct
12 Correct 7 ms 6236 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 7 ms 5980 KB Output is correct
15 Correct 7 ms 5980 KB Output is correct
16 Correct 2 ms 3164 KB Output is correct
17 Correct 22 ms 7936 KB Output is correct
18 Correct 21 ms 8720 KB Output is correct
19 Correct 20 ms 8540 KB Output is correct
20 Correct 20 ms 8532 KB Output is correct
21 Correct 19 ms 8540 KB Output is correct
22 Correct 33 ms 10908 KB Output is correct
23 Correct 13 ms 6492 KB Output is correct
24 Correct 21 ms 7512 KB Output is correct
25 Correct 7 ms 6236 KB Output is correct
26 Correct 12 ms 6560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 2 ms 3932 KB Output is correct
10 Correct 8 ms 6232 KB Output is correct
11 Correct 2 ms 3932 KB Output is correct
12 Correct 7 ms 6236 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 7 ms 5980 KB Output is correct
15 Correct 7 ms 5980 KB Output is correct
16 Correct 2 ms 3164 KB Output is correct
17 Correct 22 ms 7936 KB Output is correct
18 Correct 21 ms 8720 KB Output is correct
19 Correct 20 ms 8540 KB Output is correct
20 Correct 20 ms 8532 KB Output is correct
21 Correct 19 ms 8540 KB Output is correct
22 Correct 33 ms 10908 KB Output is correct
23 Correct 13 ms 6492 KB Output is correct
24 Correct 21 ms 7512 KB Output is correct
25 Correct 7 ms 6236 KB Output is correct
26 Correct 12 ms 6560 KB Output is correct
27 Correct 499 ms 147536 KB Output is correct
28 Correct 115 ms 29776 KB Output is correct
29 Correct 549 ms 163920 KB Output is correct
30 Execution timed out 1054 ms 163372 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 18256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 22808 KB Time limit exceeded
2 Halted 0 ms 0 KB -