답안 #1023968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023968 2024-07-15T10:16:23 Z Otalp 메기 농장 (IOI22_fish) C++17
18 / 100
598 ms 236740 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 = 500100;
int n, w[MAXN], m;
pii a[MAXN];

namespace B{
    unordered_map<ll, ll> d[200100];
    unordered_map<ll, ll> dp[200100];
    unordered_map<ll, ll> pref[200100];
    unordered_map<ll, ll> ddp[200100];
    vector<ll> pos[200100];
    ll suf[200100];
    ll solve(){
        for(ll i=1; i<=m; i++){
            d[a[i].ff][a[i].ss] += w[i];
        }
        for(int i=0; i<=n; i++){
            d[i][0] += 0;
        }
        for(int i=0; i<=n; i++){
            for(auto h: d[i]){
                pos[i].pb(h.ff);
            }
        }
        for(ll i=1; i<=n; i++){
            sort(pos[i].begin(), pos[i].end());
        }
        for(ll i=1; i<=n; i++){
            dp[0][i] = -1e18;
            ddp[0][i] = -1e18;
        }
        dp[0][0] = 0;
        ddp[0][0] = 0;
        for(ll i=1; i<=n; i++){
            //cout<<"_____________________\n";
            //cout<<i<<'\n';
            vector<ll> alpos;
            for(auto h: pos[i-1]) alpos.pb(h);
            for(auto h: pos[i+1]) alpos.pb(h);
            sort(alpos.begin(), alpos.end());
            int gls = 0;
            for(ll  h: pos[i]){
                ll j = h;
                pref[i][j] = pref[i][gls] + d[i][j];
                gls = j;
            }
            vector<ll> dpos;
            for(auto h: dp[i-1]){
                dpos.pb(h.ff);
            }
            sort(dpos.begin(), dpos.end());
            ll mx = -1e18;
            ll ls = pos[i].size()-1;
            for(ll h = dpos.size()-1; h>=0; h--){
                ll 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(ll h = dpos.size()-1; h>=0; h--){
                ll j = dpos[h];
                mx = max(mx, dp[i-1][j]);
            }
            ll pls=-1, dpls=-1;
            ls = -1;
            ll lls = -1;
            for(ll 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]]);
                else dp[i][j] = max(dp[i][j], suf[dpos[ls]]-pref[i][pos[i][pls]]);
                dp[i][j] = max(dp[i][j], pdp+pref[i-1][pos[i-1][dpls]]);
            }
            //cout<<'\n';
        }
        //for(ll i=1; i<=n; i++){
        //    for(ll j=0; j<=n; j++){
        //        cout<<pref[i][j]<<' ';
        //    }
        //    cout<<'\n';
        //}
        ll ans = 0;
        for(ll 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];
    }
    return B::solve();
}

Compilation message

fish.cpp: In function 'long long int B::solve()':
fish.cpp:79:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |                 while(ls + 1 < dpos.size() and dpos[ls + 1] <= j){
      |                       ~~~~~~~^~~~~~~~~~~~~
fish.cpp:81:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                     while(lls + 1 < pos[i-1].size() and pos[i-1][lls + 1] <= dpos[ls]) lls++;
      |                           ~~~~~~~~^~~~~~~~~~~~~~~~~
fish.cpp:84:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |                 while(pls + 1 < pos[i].size() and pos[i][pls + 1] <= j) pls ++;
      |                       ~~~~~~~~^~~~~~~~~~~~~~~
fish.cpp:85:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |                 while(dpls + 1 < pos[i-1].size() and pos[i-1][dpls + 1] <= j) dpls ++;
      |                       ~~~~~~~~~^~~~~~~~~~~~~~~~~
fish.cpp:96:32: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   96 |                 if(dpos.size() > ls + 1) dp[i][j] = max(dp[i][j], suf[dpos[ls + 1]]-pref[i][pos[i][pls]]);
      |                    ~~~~~~~~~~~~^~~~~~~~
fish.cpp:68:16: warning: unused variable 'pddp' [-Wunused-variable]
   68 |             ll pddp = -1e18, pdp = -1e18;
      |                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 137320 KB Output is correct
2 Correct 182 ms 150188 KB Output is correct
3 Correct 178 ms 128684 KB Output is correct
4 Correct 170 ms 128604 KB Output is correct
5 Correct 476 ms 236740 KB Output is correct
6 Correct 598 ms 221228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 50268 KB Output is correct
2 Correct 316 ms 162608 KB Output is correct
3 Correct 335 ms 185244 KB Output is correct
4 Correct 178 ms 137320 KB Output is correct
5 Correct 203 ms 150196 KB Output is correct
6 Correct 17 ms 50268 KB Output is correct
7 Correct 18 ms 50152 KB Output is correct
8 Correct 18 ms 50268 KB Output is correct
9 Correct 17 ms 50268 KB Output is correct
10 Correct 120 ms 128672 KB Output is correct
11 Correct 179 ms 128548 KB Output is correct
12 Correct 234 ms 146924 KB Output is correct
13 Correct 318 ms 163556 KB Output is correct
14 Correct 197 ms 142208 KB Output is correct
15 Correct 219 ms 154776 KB Output is correct
16 Correct 227 ms 142272 KB Output is correct
17 Correct 304 ms 154664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 128552 KB Output is correct
2 Correct 245 ms 128600 KB Output is correct
3 Correct 174 ms 130424 KB Output is correct
4 Correct 170 ms 134692 KB Output is correct
5 Correct 274 ms 143876 KB Output is correct
6 Correct 236 ms 143860 KB Output is correct
7 Correct 260 ms 143916 KB Output is correct
8 Correct 350 ms 143936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 50264 KB Output is correct
2 Correct 25 ms 50268 KB Output is correct
3 Correct 20 ms 50268 KB Output is correct
4 Correct 18 ms 50376 KB Output is correct
5 Correct 21 ms 50268 KB Output is correct
6 Correct 25 ms 50308 KB Output is correct
7 Correct 20 ms 50268 KB Output is correct
8 Correct 17 ms 50120 KB Output is correct
9 Correct 21 ms 50520 KB Output is correct
10 Correct 22 ms 50972 KB Output is correct
11 Incorrect 18 ms 50524 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '276017218506'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 50264 KB Output is correct
2 Correct 25 ms 50268 KB Output is correct
3 Correct 20 ms 50268 KB Output is correct
4 Correct 18 ms 50376 KB Output is correct
5 Correct 21 ms 50268 KB Output is correct
6 Correct 25 ms 50308 KB Output is correct
7 Correct 20 ms 50268 KB Output is correct
8 Correct 17 ms 50120 KB Output is correct
9 Correct 21 ms 50520 KB Output is correct
10 Correct 22 ms 50972 KB Output is correct
11 Incorrect 18 ms 50524 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '276017218506'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 50264 KB Output is correct
2 Correct 25 ms 50268 KB Output is correct
3 Correct 20 ms 50268 KB Output is correct
4 Correct 18 ms 50376 KB Output is correct
5 Correct 21 ms 50268 KB Output is correct
6 Correct 25 ms 50308 KB Output is correct
7 Correct 20 ms 50268 KB Output is correct
8 Correct 17 ms 50120 KB Output is correct
9 Correct 21 ms 50520 KB Output is correct
10 Correct 22 ms 50972 KB Output is correct
11 Incorrect 18 ms 50524 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '276017218506'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 128552 KB Output is correct
2 Correct 245 ms 128600 KB Output is correct
3 Correct 174 ms 130424 KB Output is correct
4 Correct 170 ms 134692 KB Output is correct
5 Correct 274 ms 143876 KB Output is correct
6 Correct 236 ms 143860 KB Output is correct
7 Correct 260 ms 143916 KB Output is correct
8 Correct 350 ms 143936 KB Output is correct
9 Correct 273 ms 153388 KB Output is correct
10 Correct 157 ms 105324 KB Output is correct
11 Correct 375 ms 161112 KB Output is correct
12 Correct 22 ms 50264 KB Output is correct
13 Correct 19 ms 50268 KB Output is correct
14 Correct 21 ms 50268 KB Output is correct
15 Correct 20 ms 50268 KB Output is correct
16 Correct 20 ms 50276 KB Output is correct
17 Correct 20 ms 50264 KB Output is correct
18 Correct 143 ms 128552 KB Output is correct
19 Correct 193 ms 128524 KB Output is correct
20 Correct 215 ms 128552 KB Output is correct
21 Correct 133 ms 128548 KB Output is correct
22 Incorrect 267 ms 153700 KB 1st lines differ - on the 1st token, expected: '45561826463480', found: '44977339281292'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 137320 KB Output is correct
2 Correct 182 ms 150188 KB Output is correct
3 Correct 178 ms 128684 KB Output is correct
4 Correct 170 ms 128604 KB Output is correct
5 Correct 476 ms 236740 KB Output is correct
6 Correct 598 ms 221228 KB Output is correct
7 Correct 17 ms 50268 KB Output is correct
8 Correct 316 ms 162608 KB Output is correct
9 Correct 335 ms 185244 KB Output is correct
10 Correct 178 ms 137320 KB Output is correct
11 Correct 203 ms 150196 KB Output is correct
12 Correct 17 ms 50268 KB Output is correct
13 Correct 18 ms 50152 KB Output is correct
14 Correct 18 ms 50268 KB Output is correct
15 Correct 17 ms 50268 KB Output is correct
16 Correct 120 ms 128672 KB Output is correct
17 Correct 179 ms 128548 KB Output is correct
18 Correct 234 ms 146924 KB Output is correct
19 Correct 318 ms 163556 KB Output is correct
20 Correct 197 ms 142208 KB Output is correct
21 Correct 219 ms 154776 KB Output is correct
22 Correct 227 ms 142272 KB Output is correct
23 Correct 304 ms 154664 KB Output is correct
24 Correct 191 ms 128552 KB Output is correct
25 Correct 245 ms 128600 KB Output is correct
26 Correct 174 ms 130424 KB Output is correct
27 Correct 170 ms 134692 KB Output is correct
28 Correct 274 ms 143876 KB Output is correct
29 Correct 236 ms 143860 KB Output is correct
30 Correct 260 ms 143916 KB Output is correct
31 Correct 350 ms 143936 KB Output is correct
32 Correct 21 ms 50264 KB Output is correct
33 Correct 25 ms 50268 KB Output is correct
34 Correct 20 ms 50268 KB Output is correct
35 Correct 18 ms 50376 KB Output is correct
36 Correct 21 ms 50268 KB Output is correct
37 Correct 25 ms 50308 KB Output is correct
38 Correct 20 ms 50268 KB Output is correct
39 Correct 17 ms 50120 KB Output is correct
40 Correct 21 ms 50520 KB Output is correct
41 Correct 22 ms 50972 KB Output is correct
42 Incorrect 18 ms 50524 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '276017218506'
43 Halted 0 ms 0 KB -