답안 #829408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829408 2023-08-18T10:22:40 Z erkam 메기 농장 (IOI22_fish) C++17
67 / 100
747 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
  
const int N=1e5+5;
const ll inf=1e18;
  
int n,m;
vector<vector<ll>> w;
vector<vector<vector<ll>>> dp;
ll suff[N];
ll val[N];
  
long long max_weights(int _n,int _m,vector<int> X,vector<int> Y,vector<int> W) {
    n=_n,m=_m;
    int mxy=0,mxx=0;
    for(auto x:X)mxx=max(mxx,x+1);
    for(auto x:Y)mxy=max(mxy,x+1);
    n=min(n,mxx+1);
    w=vector<vector<ll>>(n+5,vector<ll>(mxy+5));
    dp=vector<vector<vector<ll>>>(n+5,vector<vector<ll>>(mxy+5,vector<ll>(2)));
    for(int i=0;i<m;i++)w[X[i]+1][Y[i]+1]=W[i];
    for(int i=1;i<=n;i++)for(int j=1;j<=mxy;j++)w[i][j]+=w[i][j-1];
    for(int i=1;i<=n;i++)for(int j=0;j<=mxy;j++)dp[i][j][0]=dp[i][j][1]=-inf;
    for(int i=1;i<=n;i++){
        if(i>=2)for(int j=mxy;j>=0;j--)suff[j]=max(suff[j+1],dp[i-2][j][1]);
        ll tmp=-inf,tmp2=-inf;
        for(int j=0;j<=mxy;j++){
            tmp=max(tmp,dp[i-1][j][0]-w[i][j]-w[i-1][j]);
            dp[i][j][0]=w[i-1][j]+tmp+w[i+1][j];
            if(i>=2){
                tmp2=max(tmp2,dp[i-2][j][0]-w[i-1][j]);
                dp[i][j][0]=max(dp[i][j][0],w[i-1][j]+tmp+w[i+1][j]);
                dp[i][j][0]=max(dp[i][j][0],suff[j]+w[i+1][j]);
            }
        }
        tmp=-inf;
        for(int j=mxy;j>=0;j--){
            tmp=max(tmp,dp[i-1][j][1]);
            dp[i][j][1]=tmp-w[i][j]+w[i+1][j];
            dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]);
        }
    }
    ll ans=0;
    for(int i=0;i<=mxy;i++)ans=max(ans,dp[n][i][1]);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 46764 KB Output is correct
2 Correct 65 ms 51944 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 44 ms 49628 KB Output is correct
5 Runtime error 747 ms 2097152 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 82 ms 54124 KB Output is correct
3 Correct 96 ms 60488 KB Output is correct
4 Correct 59 ms 46552 KB Output is correct
5 Correct 66 ms 51900 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 44 ms 49636 KB Output is correct
12 Correct 69 ms 52236 KB Output is correct
13 Correct 73 ms 58184 KB Output is correct
14 Correct 73 ms 52212 KB Output is correct
15 Correct 71 ms 57928 KB Output is correct
16 Correct 63 ms 52152 KB Output is correct
17 Correct 72 ms 57996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 47 ms 45580 KB Output is correct
3 Correct 54 ms 41936 KB Output is correct
4 Correct 50 ms 42032 KB Output is correct
5 Correct 68 ms 48060 KB Output is correct
6 Correct 80 ms 47940 KB Output is correct
7 Correct 68 ms 47948 KB Output is correct
8 Correct 68 ms 48004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 6 ms 6160 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 15 ms 7252 KB Output is correct
18 Correct 17 ms 7892 KB Output is correct
19 Correct 16 ms 7936 KB Output is correct
20 Correct 18 ms 7884 KB Output is correct
21 Correct 13 ms 5036 KB Output is correct
22 Correct 31 ms 9672 KB Output is correct
23 Correct 11 ms 6460 KB Output is correct
24 Correct 16 ms 7368 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 9 ms 6460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 6 ms 6160 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 15 ms 7252 KB Output is correct
18 Correct 17 ms 7892 KB Output is correct
19 Correct 16 ms 7936 KB Output is correct
20 Correct 18 ms 7884 KB Output is correct
21 Correct 13 ms 5036 KB Output is correct
22 Correct 31 ms 9672 KB Output is correct
23 Correct 11 ms 6460 KB Output is correct
24 Correct 16 ms 7368 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 9 ms 6460 KB Output is correct
27 Correct 588 ms 566032 KB Output is correct
28 Correct 83 ms 41168 KB Output is correct
29 Correct 601 ms 484804 KB Output is correct
30 Correct 688 ms 573164 KB Output is correct
31 Correct 638 ms 573196 KB Output is correct
32 Correct 83 ms 26380 KB Output is correct
33 Correct 656 ms 573168 KB Output is correct
34 Correct 643 ms 573184 KB Output is correct
35 Correct 60 ms 33868 KB Output is correct
36 Correct 293 ms 224568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 47 ms 45580 KB Output is correct
3 Correct 54 ms 41936 KB Output is correct
4 Correct 50 ms 42032 KB Output is correct
5 Correct 68 ms 48060 KB Output is correct
6 Correct 80 ms 47940 KB Output is correct
7 Correct 68 ms 47948 KB Output is correct
8 Correct 68 ms 48004 KB Output is correct
9 Runtime error 628 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 46764 KB Output is correct
2 Correct 65 ms 51944 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 44 ms 49628 KB Output is correct
5 Runtime error 747 ms 2097152 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -