답안 #1023906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023906 2024-07-15T09:23:05 Z vjudge1 메기 농장 (IOI22_fish) C++17
9 / 100
750 ms 164600 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 B{
    map<int, ll> d[200100];
    map<int, ll> dp[200100];
    map<int, ll> pref[200100];
    map<int, ll> ddp[200100];
    vector<int> pos[200100];
    ll suf[200100];
    ll solve(){
        for(int i=1; i<=m; i++){
            d[a[i].ff][a[i].ss] += w[i];
            pos[a[i].ff].pb(a[i].ss);
        }
        d[0][0] = 1;
        pos[0].pb(0);
        for(int i=1; i<=n; i++){
            sort(pos[i].begin(), pos[i].end());
        }
        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++){
            //cout<<"_____________________\n";
            //cout<<i<<'\n';
            vector<int> alpos;
            for(auto h: pos[i-1]) alpos.pb(h);
            for(auto h: pos[i+1]) alpos.pb(h);
            sort(alpos.begin(), alpos.end());
            for(int  h: pos[i]){
                int j = h;
                pref[i][j] = pref[i][j - 1] + d[i][j];
            }
            vector<int> dpos;
            for(auto h: dp[i-1]){
                dpos.pb(h.ff);
            }
            ll mx = -1e18;
            int ls = pos[i].size()-1;
            for(int h = dpos.size()-1; h>=0; h--){
                int j = dpos[h];
                while(ls > 0 and pos[i][ls] > j) ls--;
                mx = max(mx, dp[i-1][j] + pref[i][j]);
                suf[j] = mx;
            }
            ll pddp = -1e18, pdp = -1e18;
            mx = -1e18;
            for(int h = dpos.size()-1; h>=0; h--){
                int j = dpos[h];
                mx = max(mx, dp[i-1][j]);
            }
            int pls=-1, dpls=-1;
            ls = -1;
            int lls = -1;
            for(int j: alpos){
                //cout<<j<<' ';
                while(ls + 1 < dpos.size() and dpos[ls + 1] <= j){
                    ls += 1;
                    while(lls + 1 < pos[i-1].size() and pos[i-1][lls + 1] <= dpos[ls]) lls++;
                    pdp = max(pdp, ddp[i-1][dpos[ls]]-pref[i-1][pos[i-1][lls]]);
                }
                while(pls + 1 < pos[i].size() and pos[i][pls + 1] <= j) pls ++;
                while(dpls + 1 < pos[i-1].size() and pos[i-1][dpls + 1] <= j) dpls ++;
                ddp[i][j] = mx;
                dp[i][j] = 0;
                //if(dpls < 0){
                //    cout<<"asdas\n";
                //    cout<<j<<'\n';
                //    cout<<dpls+1<<'\n';
                //    continue;
                //}
                ddp[i][j] = max(ddp[i][j], pdp + pref[i-1][pos[i-1][dpls]]);
                dp[i][j] = ddp[i][j];
                if(dpos.size() > ls + 1) dp[i][j] = max(dp[i][j], suf[dpos[ls + 1]]-pref[i][pos[i][pls]]);
                dp[i][j] = max(dp[i][j], pdp+pref[i-1][pos[i-1][dpls]]);
            }
            //cout<<'\n';
        }
        //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;
    }
}




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];
    }
    for(int i=1; i<=n; i++){
        a[i + m] = {i, 0};
        w[i+m] = 0;
    }
    m += n;
    return B::solve();
}

Compilation message

fish.cpp: In function 'long long int B::solve()':
fish.cpp:71:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |                 while(ls + 1 < dpos.size() and dpos[ls + 1] <= j){
      |                       ~~~~~~~^~~~~~~~~~~~~
fish.cpp:73:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |                     while(lls + 1 < pos[i-1].size() and pos[i-1][lls + 1] <= dpos[ls]) lls++;
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
fish.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |                 while(pls + 1 < pos[i].size() and pos[i][pls + 1] <= j) pls ++;
      |                       ~~~~~~~~^~~~~~~~~~~~~~~
fish.cpp:77:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |                 while(dpls + 1 < pos[i-1].size() and pos[i-1][dpls + 1] <= j) dpls ++;
      |                       ~~~~~~~~~^~~~~~~~~~~~~~~~~
fish.cpp:88:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |                 if(dpos.size() > ls + 1) dp[i][j] = max(dp[i][j], suf[dpos[ls + 1]]-pref[i][pos[i][pls]]);
      |                    ~~~~~~~~~~~~^~~~~~~~
fish.cpp:60:16: warning: unused variable 'pddp' [-Wunused-variable]
   60 |             ll pddp = -1e18, pdp = -1e18;
      |                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 354 ms 122620 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '36638591909'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 42584 KB Output is correct
2 Incorrect 750 ms 163368 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '84649862111'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 104176 KB Output is correct
2 Correct 188 ms 104096 KB Output is correct
3 Correct 195 ms 115048 KB Output is correct
4 Correct 194 ms 115756 KB Output is correct
5 Correct 256 ms 134320 KB Output is correct
6 Correct 256 ms 133692 KB Output is correct
7 Correct 290 ms 134208 KB Output is correct
8 Correct 257 ms 134080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 42584 KB Output is correct
2 Correct 20 ms 42588 KB Output is correct
3 Correct 20 ms 42588 KB Output is correct
4 Correct 19 ms 42716 KB Output is correct
5 Correct 20 ms 42584 KB Output is correct
6 Correct 19 ms 42584 KB Output is correct
7 Correct 19 ms 42584 KB Output is correct
8 Correct 18 ms 42584 KB Output is correct
9 Correct 25 ms 42840 KB Output is correct
10 Correct 23 ms 43612 KB Output is correct
11 Incorrect 21 ms 43100 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '209821364205'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 42584 KB Output is correct
2 Correct 20 ms 42588 KB Output is correct
3 Correct 20 ms 42588 KB Output is correct
4 Correct 19 ms 42716 KB Output is correct
5 Correct 20 ms 42584 KB Output is correct
6 Correct 19 ms 42584 KB Output is correct
7 Correct 19 ms 42584 KB Output is correct
8 Correct 18 ms 42584 KB Output is correct
9 Correct 25 ms 42840 KB Output is correct
10 Correct 23 ms 43612 KB Output is correct
11 Incorrect 21 ms 43100 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '209821364205'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 42584 KB Output is correct
2 Correct 20 ms 42588 KB Output is correct
3 Correct 20 ms 42588 KB Output is correct
4 Correct 19 ms 42716 KB Output is correct
5 Correct 20 ms 42584 KB Output is correct
6 Correct 19 ms 42584 KB Output is correct
7 Correct 19 ms 42584 KB Output is correct
8 Correct 18 ms 42584 KB Output is correct
9 Correct 25 ms 42840 KB Output is correct
10 Correct 23 ms 43612 KB Output is correct
11 Incorrect 21 ms 43100 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '209821364205'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 104176 KB Output is correct
2 Correct 188 ms 104096 KB Output is correct
3 Correct 195 ms 115048 KB Output is correct
4 Correct 194 ms 115756 KB Output is correct
5 Correct 256 ms 134320 KB Output is correct
6 Correct 256 ms 133692 KB Output is correct
7 Correct 290 ms 134208 KB Output is correct
8 Correct 257 ms 134080 KB Output is correct
9 Correct 320 ms 159040 KB Output is correct
10 Correct 192 ms 103732 KB Output is correct
11 Correct 392 ms 164600 KB Output is correct
12 Correct 23 ms 42584 KB Output is correct
13 Correct 19 ms 42584 KB Output is correct
14 Correct 21 ms 42588 KB Output is correct
15 Correct 19 ms 42592 KB Output is correct
16 Correct 21 ms 42584 KB Output is correct
17 Correct 27 ms 42580 KB Output is correct
18 Correct 155 ms 104152 KB Output is correct
19 Correct 158 ms 104152 KB Output is correct
20 Correct 157 ms 104108 KB Output is correct
21 Correct 159 ms 104096 KB Output is correct
22 Incorrect 367 ms 159632 KB 1st lines differ - on the 1st token, expected: '45561826463480', found: '35041184705483'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 354 ms 122620 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '36638591909'
2 Halted 0 ms 0 KB -