답안 #1022968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022968 2024-07-14T08:04:37 Z vjudge1 메기 농장 (IOI22_fish) C++17
61 / 100
232 ms 298520 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second

const int MAXN = 300100;
int n, w[MAXN], m;
pii a[MAXN];

namespace A{
    ll solve(){
        ll ans = 0;
        for(int i=1; i<=m; i++){
            ans += w[i];
        }
        return ans;
    }
}

namespace B{
    ll d[3001][3001];
    ll dp[3001][3001];
    ll pref[3001][3001];
    ll ddp[3001][3001];
    ll suf[3001];
    ll solve(){
        for(int i=1; i<=m; i++){
            d[a[i].ff][a[i].ss] += w[i];
        }
        for(int i=1; i<=n; i++){
            dp[0][i] = -1e18;
            ddp[0][i] = -1e18;
        }
        dp[0][0] = 0;
        ddp[0][0] = 0;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                pref[i][j] = pref[i][j - 1] + d[i][j];
            }
            ll mx = -1e18;
            for(int j=n; j>=0; j--){
                mx = max(mx, dp[i-1][j] + pref[i][j]);
                suf[j] = mx;
            }
            ll pddp = -1e18, pdp = -1e18;
            mx = -1e18;
            for(int j=0; j<=n; j++) mx = max(mx, dp[i-1][j]);
            for(int j=0; j<=n; j++){
                ddp[i][j] = mx;
                dp[i][j] = 0;
                pddp = max(pddp, ddp[i-1][j]-pref[i-1][j]);
                ddp[i][j] = max(ddp[i][j], pddp + pref[i-1][j]);
                dp[i][j] = ddp[i][j];
                dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
                pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
                dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
            }
        }
        //for(int i=1; i<=n; i++){
        //    for(int j=0; j<=n; j++){
        //        cout<<dp[i][j]<<' ';
        //    }
        //    cout<<'\n';
        //}
        ll ans = 0;
        for(int i=0; i<=n; i++) ans = max(ans, dp[n][i]);
        return ans;
    }
}

namespace C{
    ll d[5][100100];
    ll dp[5][100100];
    ll pref[5][100100];
    ll ddp[5][100100];
    ll suf[100100];
    ll solve(){
        for(int i=1; i<=m; i++){
            d[a[i].ff][a[i].ss] += w[i];
        }
        for(int i=1; i<=n; i++){
            dp[0][i] = -1e18;
            ddp[0][i] = -1e18;
        }
        dp[0][0] = 0;
        ddp[0][0] = 0;
        for(int i=1; i<=3; i++){
            for(int j=1; j<=n; j++){
                pref[i][j] = pref[i][j - 1] + d[i][j];
            }
            ll mx = -1e18;
            for(int j=n; j>=0; j--){
                mx = max(mx, dp[i-1][j] + pref[i][j]);
                suf[j] = mx;
            }
            ll pddp = -1e18, pdp = -1e18;
            mx = -1e18;
            for(int j=0; j<=n; j++) mx = max(mx, dp[i-1][j]);
            for(int j=0; j<=n; j++){
                ddp[i][j] = mx;
                dp[i][j] = 0;
                pddp = max(pddp, ddp[i-1][j]-pref[i-1][j]);
                ddp[i][j] = max(ddp[i][j], pddp + pref[i-1][j]);
                dp[i][j] = ddp[i][j];
                dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
                pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
                dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
            }
        }
        //for(int i=1; i<=n; i++){
        //    for(int j=0; j<=n; j++){
        //        cout<<dp[i][j]<<' ';
        //    }
        //    cout<<'\n';
        //}
        ll ans = 0;
        for(int i=0; i<=n; i++) ans = max(ans, dp[3][i]);
        return ans;
    }
}



long long max_weights(int N, int M, vector<int> X, vector<int> Y,
                      vector<int> W) {
    n = N;
    m = M;
    for(int i=1; i<=m; i++){
        a[i] = {X[i-1]+1, Y[i-1]+1};
    }
    for(int i=1; i<=m; i++){
        w[i] = W[i-1];
    }
    int ok1 = 1;
    int ok2 = 1, ok3 = 1;
    for(int i=1; i<=m; i++){
        ok1 &= (a[i].ff % 2 == 1);
        ok2 &= (a[i].ff <= 2);
    }
    if(ok1) return A::solve();
    if(n <= 3000) return B::solve();
    if(ok2) return C::solve();
    return 0;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:139:18: warning: unused variable 'ok3' [-Wunused-variable]
  139 |     int ok2 = 1, ok3 = 1;
      |                  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4436 KB Output is correct
2 Correct 21 ms 5464 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 60 ms 16876 KB Output is correct
6 Correct 63 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 37 ms 18772 KB Output is correct
3 Correct 47 ms 21728 KB Output is correct
4 Correct 16 ms 4696 KB Output is correct
5 Correct 19 ms 5700 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 31 ms 13884 KB Output is correct
13 Correct 32 ms 15824 KB Output is correct
14 Correct 22 ms 13912 KB Output is correct
15 Correct 22 ms 15452 KB Output is correct
16 Correct 20 ms 13904 KB Output is correct
17 Correct 24 ms 15352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 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 0 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 1 ms 3420 KB Output is correct
10 Correct 4 ms 7768 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 1 ms 1624 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 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 0 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 1 ms 3420 KB Output is correct
10 Correct 4 ms 7768 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 1 ms 1624 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7256 KB Output is correct
16 Correct 2 ms 1628 KB Output is correct
17 Correct 13 ms 9680 KB Output is correct
18 Correct 13 ms 9412 KB Output is correct
19 Correct 12 ms 10072 KB Output is correct
20 Correct 12 ms 10076 KB Output is correct
21 Correct 12 ms 10076 KB Output is correct
22 Correct 25 ms 12564 KB Output is correct
23 Correct 6 ms 8540 KB Output is correct
24 Correct 9 ms 9564 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 7 ms 8028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 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 0 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 1 ms 3420 KB Output is correct
10 Correct 4 ms 7768 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 1 ms 1624 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7256 KB Output is correct
16 Correct 2 ms 1628 KB Output is correct
17 Correct 13 ms 9680 KB Output is correct
18 Correct 13 ms 9412 KB Output is correct
19 Correct 12 ms 10072 KB Output is correct
20 Correct 12 ms 10076 KB Output is correct
21 Correct 12 ms 10076 KB Output is correct
22 Correct 25 ms 12564 KB Output is correct
23 Correct 6 ms 8540 KB Output is correct
24 Correct 9 ms 9564 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 7 ms 8028 KB Output is correct
27 Correct 131 ms 223956 KB Output is correct
28 Correct 60 ms 37460 KB Output is correct
29 Correct 187 ms 230992 KB Output is correct
30 Correct 232 ms 274136 KB Output is correct
31 Correct 203 ms 274668 KB Output is correct
32 Correct 65 ms 34128 KB Output is correct
33 Correct 211 ms 298348 KB Output is correct
34 Correct 216 ms 298520 KB Output is correct
35 Correct 161 ms 232908 KB Output is correct
36 Correct 203 ms 244304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4436 KB Output is correct
2 Correct 21 ms 5464 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 60 ms 16876 KB Output is correct
6 Correct 63 ms 17232 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 37 ms 18772 KB Output is correct
9 Correct 47 ms 21728 KB Output is correct
10 Correct 16 ms 4696 KB Output is correct
11 Correct 19 ms 5700 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 31 ms 13884 KB Output is correct
19 Correct 32 ms 15824 KB Output is correct
20 Correct 22 ms 13912 KB Output is correct
21 Correct 22 ms 15452 KB Output is correct
22 Correct 20 ms 13904 KB Output is correct
23 Correct 24 ms 15352 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
26 Halted 0 ms 0 KB -