Submission #1079666

# Submission time Handle Problem Language Result Execution time Memory
1079666 2024-08-28T20:53:14 Z ArthuroWich Catfish Farm (IOI22_fish) C++17
9 / 100
100 ms 19284 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<vector<int>> ind;
vector<vector<pair<int, int>>> pref;
int query(int i, int j) {
    pair<int, int> c = {j, INT64_MAX};
    if (pref[i].size() <= 1) {
        return 0;
    }
    auto ind = upper_bound(pref[i].begin(), pref[i].end(), c);
    ind--;
    c = *ind;
    return c.second;
}
int max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) {
    int n = N, m = M;
    pref.resize(n+1);
    ind.resize(n+1);
    vector<vector<int>> dp(2, vector<int>(1, 0)); // 0 is increasing, 1 is decreasing, increasing can go to decreasing, decreasing cant go to increasing if next to eachother
    for (int i = 0; i < m; i++) {
        pref[X[i]].push_back({Y[i], W[i]});
    }
    pref[n] = {{-1, 0}};
    for (int i = 0; i <= n; i++) {
        pref[i].push_back({-1, 0}); // to make 1-indexed
        sort(pref[i].begin(), pref[i].end());
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 1; j < pref[i].size(); i++) {
            pref[i][j].second += pref[i][j-1].second;
        }
    }
    for (int i = 0; i < n; i++) {
        if (i != 0) {
            for (auto [a, b] : pref[i-1]) {
                ind[i].push_back(a);
            }
        }
        for (auto [a, b] : pref[i+1]) {
            ind[i].push_back(a);
        }
        sort(ind[i].begin(), ind[i].end());
        ind[i].erase(unique(ind[i].begin(), ind[i].end()), ind[i].end());
    }
    ind[n].push_back(-1);
    for (int j = 1; j <= n; j++) {
        vector<vector<int>> tdp(2, vector<int>(ind[j].size()+1, 0));
        int v = 0, k = 0;
        for (int i = 0; i < ind[j].size(); i++) {
            int x = ind[j][i];
            while(k < ind[j-1].size() && ind[j-1][k] <= x) {
                v = max(v, dp[0][k]-query(j-1, ind[j-1][k]));
                k++;
            }
            tdp[0][i] = max(v+query(j-1, x), dp[1][0]);
        }
        v = 0;
        k = ind[j-1].size();
        for (int i = ind[j].size()-1; i >= 0; i--) {
            int x = ind[j][i];
            while(k > 0 && ind[j-1][k-1] >= x) {
                k--;
                v = max(v, max(dp[0][k], dp[1][k])+query(j, ind[j-1][k]));
            }
            tdp[1][i] = v - query(j, x);
        }
        swap(dp, tdp);
    }
    int ans = max(dp[0][0], dp[1][0]);
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:31:27: 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]
   31 |         for (int j = 1; j < pref[i].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~
fish.cpp:51:27: 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]
   51 |         for (int i = 0; i < ind[j].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:53:21: 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]
   53 |             while(k < ind[j-1].size() && ind[j-1][k] <= x) {
      |                   ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 17348 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '999990243'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 11356 KB Output is correct
2 Correct 19 ms 11408 KB Output is correct
3 Correct 37 ms 14420 KB Output is correct
4 Correct 60 ms 13904 KB Output is correct
5 Correct 75 ms 19284 KB Output is correct
6 Correct 61 ms 18620 KB Output is correct
7 Correct 55 ms 19280 KB Output is correct
8 Correct 100 ms 19280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 11356 KB Output is correct
2 Correct 19 ms 11408 KB Output is correct
3 Correct 37 ms 14420 KB Output is correct
4 Correct 60 ms 13904 KB Output is correct
5 Correct 75 ms 19284 KB Output is correct
6 Correct 61 ms 18620 KB Output is correct
7 Correct 55 ms 19280 KB Output is correct
8 Correct 100 ms 19280 KB Output is correct
9 Correct 53 ms 19012 KB Output is correct
10 Incorrect 42 ms 15072 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '23310694292708'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 17348 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '999990243'
2 Halted 0 ms 0 KB -