답안 #1075530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075530 2024-08-26T07:26:01 Z Faisal_Saqib 메기 농장 (IOI22_fish) C++17
70 / 100
244 ms 366928 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
const int N=3e3+1;
ll val[N][N],pre[N][N];
ll dp[N][N][3];
ll solve(ll&n,ll&m,vll&x,vll&y,vll&w)
{
    ll ans=0;
    for(int i=0;i<n;i++)for(int j=0;j<=n;j++)val[i][j]=pre[i][j]=0;
    for(int j=0;j<m;j++)val[x[j]][y[j]+1]+=w[j];
    for(int i=0;i<=n;i++)
    {
        pre[i][0]=val[i][0];
        for(int j=1;j<=n;j++)
            pre[i][j]=pre[i][j-1]+val[i][j];
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<=n;j++)
            for(int k=0;k<2;k++)
                dp[i][j][k]=0;
    for(int i=1;i<n;i++)
    {
        // ll sum=0;
        ll mx1=-2e18;
        ll mx2=-2e18;
        ll mx11=0,mx22=0;
        for(int hp=0;hp<=n;hp++)
        {
            mx11=max(mx11,dp[i-1][hp][0]);
            mx22=max(mx22,dp[i-1][hp][1]);

            mx1=max(mx1,dp[i-1][hp][0]-pre[i-1][hp]);
            mx2=max(mx2,dp[i-1][hp][1]+pre[i][hp]);
        }
        for(int h=0;h<=n;h++)
        {
            dp[i][h][0]=max(dp[i][h][0],mx1+pre[i-1][h]);
            dp[i][h][1]=max(dp[i][h][1],mx1+pre[i-1][h]);
            dp[i][h][1]=max(dp[i][h][1],mx2-pre[i][h]);

            dp[i][h][0]=max(dp[i][h][0],mx11);
            dp[i][h][0]=max(dp[i][h][0],mx22);

            dp[i][h][1]=max(dp[i][h][1],mx11);
            dp[i][h][1]=max(dp[i][h][1],mx22);
            // sum+=val[i-1][h];
            // ll aux=0;
            // for(int nh=h+1;nh<=n;nh++)
            // {
            //     // aux+=val[i][nh];
            //     dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][0]);
            //     dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][1]);
                
            //     dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][0]);
            //     dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][1]+pre[i][nh]-pre[i][h]);

            // }
            // // ll og=sum;
            // for(int nh=0;nh<=h;nh++)
            // {
            //     // sum-=val[i-1][nh];
            //     dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][0]+pre[i-1][h]-pre[i-1][nh]);
            //     dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][1]);
                
            //     dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][0]+pre[i-1][j]-pre[i-1][nh]);
            //     dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][1]);
            // }
            // sum=og;
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int h=0;h<=n;h++)
        {
            // cout<<"For: "<<i<<' '<<h<<' '<<dp[i][h][0]<<' '<<dp[i][h][1]<<endl;
            ans=max(ans,dp[i][h][0]);
            ans=max(ans,dp[i][h][1]);
        }
    }
    return ans;
}
ll subtask2(ll&n,ll&m,vll&x,vll&y,vll&w)
{
    ll ans=0;
    ll val[2][n]={0};
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<n;j++)
        {
            val[i][j]=0;
        }
    }
    ll sum1=0,sum0=0;
    for(int j=0;j<m;j++)
    {
        val[x[j]][y[j]]+=w[j];
        if(x[j]==1)
        {
            sum1+=w[j];
        }
        else
        {
            sum0+=w[j];
        }
    }
    ans=max(sum0,sum1);
    ll taken=0;
    ll cur=0;
    for(int j=0;j<n;j++)
    {
        cur+=val[0][j];
        taken+=val[1][j];
        ans=max(ans,cur);
        if(n>2)
            ans=max(ans,cur+sum1-taken);
    }
    return ans;
}
ll subtask3(ll&n,ll&m,vll&x,vll&y,vll&w)
{
    ll ans=0;
    ll val[n+1];
    for(int i=0;i<n;i++)val[i]=0;
    for(int j=0;j<m;j++)val[x[j]]+=w[j];
    ll dp[n+1][3][3];
    for(int i=0;i<n;i++)
        for(int j=0;j<2;j++)
            for(int k=0;k<2;k++)
                dp[i][j][k]=0;
    for(int i=1;i<n;i++)
    {
        // wall not at i
        dp[i][0][0]=max(max(dp[i-1][0][0],dp[i-1][0][1]),dp[i-1][1][0]);
        dp[i][0][1]=max(max(dp[i-1][0][0],dp[i-1][0][1]),dp[i-1][1][0]+val[i]);

        dp[i][1][0]=max(max(dp[i-1][0][1],dp[i-1][0][0]+val[i-1]),dp[i-1][1][0]);
    }
    for(int i=0;i<n;i++)
    {
        ans=max({ans,dp[i][0][0],dp[i][0][1],dp[i][1][0],dp[i][1][1]});
    }
    return ans;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W)
{
    ll n=N,m=M,ans=0;
    vector<ll> x(all(X)),y(all(Y)),w(all(W));
    ll mx_x=*max_element(all(x));
    if(n<=3000)
        return solve(n,m,x,y,w);
    if(mx_x<=1)
        return subtask2(n,m,x,y,w);
    return subtask3(n,m,x,y,w);
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:149:16: warning: unused variable 'ans' [-Wunused-variable]
  149 |     ll n=N,m=M,ans=0;
      |                ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5468 KB Output is correct
2 Correct 21 ms 6492 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 71 ms 22124 KB Output is correct
6 Correct 72 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 41 ms 9268 KB Output is correct
3 Correct 42 ms 11344 KB Output is correct
4 Correct 31 ms 5460 KB Output is correct
5 Correct 19 ms 6492 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 15 ms 5720 KB Output is correct
13 Correct 27 ms 6480 KB Output is correct
14 Correct 16 ms 5468 KB Output is correct
15 Correct 22 ms 6124 KB Output is correct
16 Correct 16 ms 5508 KB Output is correct
17 Correct 26 ms 6104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1884 KB Output is correct
2 Correct 4 ms 8028 KB Output is correct
3 Correct 18 ms 9792 KB Output is correct
4 Correct 21 ms 9896 KB Output is correct
5 Correct 23 ms 12884 KB Output is correct
6 Correct 26 ms 12884 KB Output is correct
7 Correct 23 ms 12892 KB Output is correct
8 Correct 22 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 3164 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 3 ms 7528 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 3164 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 3 ms 7528 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 3 ms 7512 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 12 ms 9560 KB Output is correct
18 Correct 11 ms 9564 KB Output is correct
19 Correct 11 ms 9564 KB Output is correct
20 Correct 13 ms 9564 KB Output is correct
21 Correct 12 ms 9564 KB Output is correct
22 Correct 19 ms 11868 KB Output is correct
23 Correct 5 ms 8028 KB Output is correct
24 Correct 11 ms 9052 KB Output is correct
25 Correct 5 ms 7516 KB Output is correct
26 Correct 6 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 3164 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 3 ms 7528 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 3 ms 7512 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 12 ms 9560 KB Output is correct
18 Correct 11 ms 9564 KB Output is correct
19 Correct 11 ms 9564 KB Output is correct
20 Correct 13 ms 9564 KB Output is correct
21 Correct 12 ms 9564 KB Output is correct
22 Correct 19 ms 11868 KB Output is correct
23 Correct 5 ms 8028 KB Output is correct
24 Correct 11 ms 9052 KB Output is correct
25 Correct 5 ms 7516 KB Output is correct
26 Correct 6 ms 8028 KB Output is correct
27 Correct 170 ms 352848 KB Output is correct
28 Correct 55 ms 41556 KB Output is correct
29 Correct 232 ms 366684 KB Output is correct
30 Correct 238 ms 366928 KB Output is correct
31 Correct 237 ms 366704 KB Output is correct
32 Correct 93 ms 32852 KB Output is correct
33 Correct 242 ms 366716 KB Output is correct
34 Correct 244 ms 366720 KB Output is correct
35 Correct 237 ms 358228 KB Output is correct
36 Correct 231 ms 366712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1884 KB Output is correct
2 Correct 4 ms 8028 KB Output is correct
3 Correct 18 ms 9792 KB Output is correct
4 Correct 21 ms 9896 KB Output is correct
5 Correct 23 ms 12884 KB Output is correct
6 Correct 26 ms 12884 KB Output is correct
7 Correct 23 ms 12892 KB Output is correct
8 Correct 22 ms 12888 KB Output is correct
9 Incorrect 20 ms 12892 KB 1st lines differ - on the 1st token, expected: '99999', found: '66666'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5468 KB Output is correct
2 Correct 21 ms 6492 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 71 ms 22124 KB Output is correct
6 Correct 72 ms 22100 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 41 ms 9268 KB Output is correct
9 Correct 42 ms 11344 KB Output is correct
10 Correct 31 ms 5460 KB Output is correct
11 Correct 19 ms 6492 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 15 ms 5720 KB Output is correct
19 Correct 27 ms 6480 KB Output is correct
20 Correct 16 ms 5468 KB Output is correct
21 Correct 22 ms 6124 KB Output is correct
22 Correct 16 ms 5508 KB Output is correct
23 Correct 26 ms 6104 KB Output is correct
24 Correct 2 ms 1884 KB Output is correct
25 Correct 4 ms 8028 KB Output is correct
26 Correct 18 ms 9792 KB Output is correct
27 Correct 21 ms 9896 KB Output is correct
28 Correct 23 ms 12884 KB Output is correct
29 Correct 26 ms 12884 KB Output is correct
30 Correct 23 ms 12892 KB Output is correct
31 Correct 22 ms 12888 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 2 ms 3164 KB Output is correct
41 Correct 3 ms 7516 KB Output is correct
42 Correct 1 ms 3164 KB Output is correct
43 Correct 3 ms 7528 KB Output is correct
44 Correct 1 ms 1372 KB Output is correct
45 Correct 4 ms 7516 KB Output is correct
46 Correct 3 ms 7512 KB Output is correct
47 Correct 1 ms 1628 KB Output is correct
48 Correct 12 ms 9560 KB Output is correct
49 Correct 11 ms 9564 KB Output is correct
50 Correct 11 ms 9564 KB Output is correct
51 Correct 13 ms 9564 KB Output is correct
52 Correct 12 ms 9564 KB Output is correct
53 Correct 19 ms 11868 KB Output is correct
54 Correct 5 ms 8028 KB Output is correct
55 Correct 11 ms 9052 KB Output is correct
56 Correct 5 ms 7516 KB Output is correct
57 Correct 6 ms 8028 KB Output is correct
58 Correct 170 ms 352848 KB Output is correct
59 Correct 55 ms 41556 KB Output is correct
60 Correct 232 ms 366684 KB Output is correct
61 Correct 238 ms 366928 KB Output is correct
62 Correct 237 ms 366704 KB Output is correct
63 Correct 93 ms 32852 KB Output is correct
64 Correct 242 ms 366716 KB Output is correct
65 Correct 244 ms 366720 KB Output is correct
66 Correct 237 ms 358228 KB Output is correct
67 Correct 231 ms 366712 KB Output is correct
68 Incorrect 20 ms 12892 KB 1st lines differ - on the 1st token, expected: '99999', found: '66666'
69 Halted 0 ms 0 KB -