답안 #953701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953701 2024-03-26T13:41:22 Z tleSquared 메기 농장 (IOI22_fish) C++17
0 / 100
59 ms 62720 KB
#include "fish.h"

#include <bits/stdc++.h>
#define ll long long
#define INF 1e16
#define MAX 500005

using namespace std;

ll N, M;
ll up[MAX], down[MAX], sum[MAX], in[MAX], out[MAX];
vector<ll> X, Y, W;
vector<pair<ll, ll>> pos[MAX];

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
    N = n, M = m;
    X.resize(M);
    Y.resize(M);
    W.resize(M);
    for (ll i = 0; i < M; i++)
    {
        X[i] = x[i]+1;
        Y[i] = y[i]+1;
        W[i] = w[i];
    }
    for (ll i = 0; i < M; i++) pos[X[i]].push_back({Y[i], W[i]});
    for (ll i = 1; i <= N; i++) pos[i].push_back({N + 1, 0});
    for (ll i = 1; i <= N; i++) sort(pos[i].begin(), pos[i].end());

    ll cnt = 0;
    for (ll i = 1; i <= N; i++)
    {
        sum[++cnt] = pos[i][0].second;
        in[i] = cnt;
        Y[cnt] = pos[i][0].first;
        for(ll j = 1; j < pos[i].size(); ++j)
        {
            ++cnt;
            sum[cnt] = sum[cnt - 1] + pos[i][j].second;
            Y[cnt] = pos[i][j].first;
        }
        out[i] = cnt;
    }
    
    for(ll i = 0; i <= N; ++i) up[i] = down[i] = -INF;
    
    up[0] = down[0] = 0;
    Y[0] = -1;
    for(ll x = 1; x <= N; ++x)
    {
        ll k = in[x - 1], mx = -INF, p = -1;
        for (ll i = in[x]; i <= out[x]; ++i)
        {
            while(k <= out[x - 1] && Y[k] < Y[i])
            {
                mx = max(mx, up[k] - (k == in[x - 1] ? 0 : sum[k - 1]));
                p = k;
                k++;
            }
            
            up[i] = max(up[i], mx + (p == -1 ? 0 : sum[p]));
        }
        
        k = out[x - 1], mx = -INF, p = out[x];
        for(ll i = out[x]; i >= in[x]; --i)
        {
            while(k >= in[x - 1] && Y[k] > Y[i])
            {
                while(p >= in[x] && Y[k] <= Y[p]) --p;
                mx = max(mx, max(down[k], up[k]) + sum[p]);
                --k;
            }
            
            down[i] = max(down[i], mx - (i == in[x] ? 0 : sum[i - 1]));
            if(k >= in[x - 1] && Y[k] == Y[i]) down[i] = max(down[i], max(down[k], up[k]));
        }
        
        if(x < 2) continue;
        k = in[x - 2], mx = -INF, p = in[x - 1]; ll p2 = -1;
        for(ll i = in[x]; i <= out[x]; ++i)
        {
            while(k <= out[x - 2] && Y[k] <= Y[i])
            {
                mx = max(mx, max(up[k], down[k]));
                ++k;
            }
            while(p <= out[x - 1] && Y[p] < Y[i]) p2 = p++;
            up[i] = max(up[i], mx + (p2 == -1 ? 0 : sum[p2]));
        }
        
        k = out[x - 2], mx = -INF, p = out[x - 1];
        for(ll i = out[x]; i >= in[x]; --i)
        {
            while(k >= in[x - 2] && Y[k] > Y[i])
            {
                while(p >= in[x - 1] && Y[k] <= Y[p]) p--;
                mx = max(mx, max(up[k], down[k]) + (p == in[x - 1] - 1 ? 0 : sum[p]));
                --k;
            }
            up[i] = max(up[i], mx);
        }
    }
    
    ll res = 0;
    for(ll i = 0; i <= N + M; ++i) res = max(res, max(up[i], down[i]));
    return res;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:37:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(ll j = 1; j < pos[i].size(); ++j)
      |                       ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 59 ms 62720 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 42328 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 52820 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 22 ms 42504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 22 ms 42504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 22 ms 42504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 52820 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 59 ms 62720 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -