답안 #639560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639560 2022-09-10T15:43:48 Z SlavicG 메기 농장 (IOI22_fish) C++17
0 / 100
789 ms 2097152 KB
#include "fish.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll inf = 1e16;
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    vector<vector<ll>> p(n, vector<ll>(n, 0));
    vector<int> len[n];
    for(int i = 0; i < m; ++i) {
        p[x[i]][y[i]] += w[i];
        len[x[i]].push_back(y[i]);
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 1; j < n; ++j) {
            p[i][j] += p[i][j - 1];
        }
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= n; ++j) len[i].push_back(j);
        len[i].push_back(n);
        len[i].push_back(0);
        sort(len[i].begin(), len[i].end());
        len[i].erase(unique(len[i].begin(), len[i].end()), len[i].end());
    }
    map<ll, ll> dp[n + 1][2];
    for(int i = 0; i <= n; ++i) {
        dp[0][0][i] = dp[0][1][i] = 0;
    }

    //0 - increasing, 1 - decreasing
    for(int i = 1; i < n; ++i) {
        vector<pair<ll, ll>> mx0, mx1;
        for(ll lastlen: len[i - 1]) {
            dp[i][0][0] = max({dp[i][0][0], dp[i - 1][0][lastlen], dp[i - 1][1][lastlen]});
            dp[i][1][0] = max({dp[i][1][0], dp[i - 1][0][lastlen], dp[i - 1][1][lastlen]});

            ll cur = 0;
            if(!mx0.empty()) cur = mx0.back().second;
            cur = max(cur, dp[i - 1][0][lastlen] - (lastlen ? p[i - 1][lastlen - 1] : 0));
            mx0.push_back({lastlen, cur});
        }

        reverse(len[i - 1].begin(), len[i - 1].end());

        for(ll lastlen: len[i - 1]) {
            ll cur = 0;
            if(!mx1.empty()) cur = mx1.back().second;
            cur = max(cur, dp[i - 1][0][lastlen] + (lastlen ? p[i][lastlen - 1] : 0));
            cur = max(cur, dp[i - 1][1][lastlen] + (lastlen ? p[i][lastlen - 1] : 0));
            mx1.push_back({lastlen, cur});
        }
        reverse(mx1.begin(), mx1.end());
        for(ll curlen: len[i]) {
            auto it1 = upper_bound(mx0.begin(), mx0.end(), make_pair(curlen, LLONG_MAX));
            assert(it1 != mx0.begin()); --it1;
            auto it2 = lower_bound(mx1.begin(), mx1.end(), make_pair(curlen, LLONG_MIN));
            assert(it2 != mx1.end());

            if(curlen) dp[i][0][curlen] = max(dp[i][0][curlen], p[i - 1][curlen - 1] + it1->second);
            if(curlen) dp[i][1][curlen] = max(dp[i][1][curlen], it2->second - p[i][curlen - 1]);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= n; ++i) {
        ans = max({ans, dp[n - 1][0][i], dp[n - 1][1][i]});
    }
    return ans;
}
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 762 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 789 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 706 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 706 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 762 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -