Submission #1068554

# Submission time Handle Problem Language Result Execution time Memory
1068554 2024-08-21T10:36:15 Z Unforgettablepl Catfish Farm (IOI22_fish) C++17
52 / 100
1000 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

long long max_weights(int N, int M,vector<int> X,vector<int> Y,
                      vector<int> W){
    vector DP(N+1,vector(2,0ll));
    vector<vector<pair<int,long long>>> pref(N+2);
    for(int i=0;i<=N+1;i++)pref[i].emplace_back(0,0);
    vector<vector<int>> special_points(N+2);
    for(int i=1;i<=N+1;i++)special_points[i].emplace_back(0);
    for(int i=1;i<=N+1;i++)special_points[i].emplace_back(N);
    vector transition1(N+1,vector(N+1,0ll));
    vector transition2(N+1,vector(N+1,0ll));
    vector transition3(N+1,vector(N+1,0ll));
    vector transition4(N+1,vector(N+1,0ll));
    for(int i=0;i<M;i++) {
        pref[X[i]+1].emplace_back(Y[i]+1,W[i]);
        special_points[X[i]+1].emplace_back(Y[i]);
    }
    for(int i=1;i<=N+1;i++) {
        sort(special_points[i].begin(),special_points[i].end());
        special_points[i].erase(unique(special_points[i].begin(),special_points[i].end()),special_points[i].end());
        sort(pref[i].begin(), pref[i].end());
        for(int j=1;j<pref[i].size();j++)pref[i][j].second+=pref[i][j-1].second;
    }
    auto getpref = [&](int i,int j) {
        auto iter = lower_bound(pref[i].begin(),pref[i].end(),make_pair(j+1,-1ll));
        iter--;
        return iter->second;
    };
    for(int i=2;i<=N;i++) {
        for(int j=0;j<=N;j++) {
            if(i!=2)DP[j][1]=max(DP[j][1],-getpref(i,j)+transition1[i-1][j]);
            else DP[j][1]=max(DP[j][1],getpref(i,N)-getpref(i,j));
            if(i>2) {
                if(i!=3) {
                    DP[j][0]=max(DP[j][0],getpref(i-1,j)+transition2[i-2][j]);
                    DP[j][0]=max(DP[j][0],transition3[i-2][j]);
                }
                else DP[j][0]=max(DP[j][0],getpref(i-1,N));
            }
            if(i!=2)DP[j][0]=max(DP[j][0],getpref(i-1,j)+transition4[i-1][j]);
            else DP[j][0]=max(DP[j][0],getpref(i-1,j));
            transition1[i][j]=getpref(i+1,j)+max(DP[j][0],DP[j][1]);
            transition2[i][j]=max(DP[j][0],DP[j][1]);
            transition3[i][j]=getpref(i+1,j)+max(DP[j][0],DP[j][1]);
            transition4[i][j]=-getpref(i,j)+DP[j][0];
        }
        for(int j=N-1;j>=0;j--)transition1[i][j]=max(transition1[i][j],transition1[i][j+1]);
        for(int j=1;j<=N;j++)transition2[i][j]=max(transition2[i][j],transition2[i][j-1]);
        for(int j=N-1;j>=0;j--)transition3[i][j]=max(transition3[i][j],transition3[i][j+1]);
        for(int j=1;j<=N;j++)transition4[i][j]=max(transition4[i][j],transition4[i][j-1]);
    }
    long long ans = 0;
    for(int j=0;j<=N;j++)ans=max(ans,DP[j][0]);
    for(int j=0;j<=N;j++)ans=max(ans,DP[j][1]);
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int j=1;j<pref[i].size();j++)pref[i][j].second+=pref[i][j-1].second;
      |                     ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1107 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 937 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 886 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 4 ms 3416 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 4 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 4 ms 3416 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 4 ms 3164 KB Output is correct
15 Correct 4 ms 3160 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 26 ms 5600 KB Output is correct
18 Correct 24 ms 6236 KB Output is correct
19 Correct 20 ms 6236 KB Output is correct
20 Correct 19 ms 6060 KB Output is correct
21 Correct 19 ms 5976 KB Output is correct
22 Correct 32 ms 9048 KB Output is correct
23 Correct 16 ms 3676 KB Output is correct
24 Correct 22 ms 4696 KB Output is correct
25 Correct 5 ms 3416 KB Output is correct
26 Correct 10 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 4 ms 3416 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 4 ms 3164 KB Output is correct
15 Correct 4 ms 3160 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 26 ms 5600 KB Output is correct
18 Correct 24 ms 6236 KB Output is correct
19 Correct 20 ms 6236 KB Output is correct
20 Correct 19 ms 6060 KB Output is correct
21 Correct 19 ms 5976 KB Output is correct
22 Correct 32 ms 9048 KB Output is correct
23 Correct 16 ms 3676 KB Output is correct
24 Correct 22 ms 4696 KB Output is correct
25 Correct 5 ms 3416 KB Output is correct
26 Correct 10 ms 3832 KB Output is correct
27 Correct 332 ms 283324 KB Output is correct
28 Correct 153 ms 30800 KB Output is correct
29 Correct 485 ms 300116 KB Output is correct
30 Correct 869 ms 299116 KB Output is correct
31 Correct 774 ms 298980 KB Output is correct
32 Correct 151 ms 28812 KB Output is correct
33 Correct 801 ms 299052 KB Output is correct
34 Correct 801 ms 299104 KB Output is correct
35 Correct 545 ms 289912 KB Output is correct
36 Correct 670 ms 301176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 886 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1107 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -