Submission #852739

# Submission time Handle Problem Language Result Execution time Memory
852739 2023-09-22T15:41:19 Z abcvuitunggio Catfish Farm (IOI22_fish) C++17
18 / 100
467 ms 180928 KB
#include "fish.h"
#include <bits/stdc++.h>
#define MX mx[i][idx][b]
#define int long long
using namespace std;
const int INF=1e18;
vector <int> v[100001];
vector <pair <int, int>> s[100001],mx[100002][4][2];
int n,m,x,y,res;
void update(int pos, int val, int i, int idx){
    mx[pos][idx][0].push_back({i,val});
    mx[pos][idx][1].push_back({n-i-1,val});
}
int get(int pos, int i, int idx, int b){
    if (b)
        pos=n-pos-1;
    int p=upper_bound(MX.begin(),MX.end(),make_pair(pos,INF))-MX.begin()-1;
    return (p<0?-INF:MX[p].second);
}
int sum(int i, int j){
    if (i<0)
        return 0;
    return s[i][upper_bound(s[i].begin(),s[i].end(),make_pair(j,INF))-s[i].begin()-1].second;
}
int max_weights(int32_t N, int32_t M, vector <int32_t> X, vector <int32_t> Y, vector <int32_t> W){
    n=N;
    for (int i=0;i<M;i++){
        s[X[i]].push_back({Y[i],W[i]});
        if (X[i])
            v[X[i]-1].push_back(Y[i]);
        if (X[i]<N-1)
            v[X[i]+1].push_back(Y[i]);
    }
    for (int i=0;i<n;i++){
        v[i].push_back(-1);
        sort(v[i].begin(),v[i].end());
        v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
        s[i].push_back({-1,0});
        sort(s[i].begin(),s[i].end());
        for (int j=1;j<s[i].size();j++)
            s[i][j].second+=s[i][j-1].second;
    }
    for (int i:v[n-1]){
        update(n,0,i,0);
        update(n,0,i,1);
        update(n,-sum(n-1,i),i,2);
        update(n,sum(n-2,i),i,3);
    }
    for (int i=n-1;i;i--){
        for (int j:v[i-1]){
            x=max(max(get(j-1,i+1,2,0)+sum(i,j),get(j-1,i+1,1,0)),max(get(j,i+1,0,1),get(j,i+1,1,1)));
            y=max(max(get(j-1,i+1,2,0)+sum(i,j),get(j-1,i+1,1,0)),get(j,i+1,3,1)-sum(i-1,j));
            update(i,x,j,0);
            update(i,y,j,1);
            update(i,x-sum(i-1,j),j,2);
            update(i,max(x,y)+sum(i-2,j),j,3);
        }
        for (int j=0;j<4;j++){
            reverse(mx[i][j][1].begin(),mx[i][j][1].end());
            for (int k=0;k<2;k++)
                for (int l=1;l<mx[i][j][k].size();l++)
                    mx[i][j][k][l].second=max(mx[i][j][k][l].second,mx[i][j][k][l-1].second);
        }
    }
    return max(get(-1,1,0,1),get(-1,1,1,1));
}

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:40:23: 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]
   40 |         for (int j=1;j<s[i].size();j++)
      |                      ~^~~~~~~~~~~~
fish.cpp:61:31: 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]
   61 |                 for (int l=1;l<mx[i][j][k].size();l++)
      |                              ~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 116 ms 71104 KB Output is correct
2 Correct 133 ms 76096 KB Output is correct
3 Correct 59 ms 55336 KB Output is correct
4 Correct 58 ms 54968 KB Output is correct
5 Correct 363 ms 158124 KB Output is correct
6 Correct 467 ms 180928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 262 ms 101044 KB Output is correct
3 Correct 303 ms 114928 KB Output is correct
4 Correct 126 ms 72580 KB Output is correct
5 Correct 132 ms 77668 KB Output is correct
6 Correct 5 ms 23896 KB Output is correct
7 Correct 6 ms 23900 KB Output is correct
8 Correct 6 ms 23900 KB Output is correct
9 Correct 6 ms 24152 KB Output is correct
10 Correct 58 ms 55132 KB Output is correct
11 Correct 59 ms 55128 KB Output is correct
12 Correct 163 ms 86336 KB Output is correct
13 Correct 182 ms 93112 KB Output is correct
14 Correct 137 ms 78088 KB Output is correct
15 Correct 174 ms 82996 KB Output is correct
16 Correct 141 ms 78024 KB Output is correct
17 Correct 162 ms 82936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 55056 KB Output is correct
2 Correct 61 ms 55120 KB Output is correct
3 Correct 112 ms 62284 KB Output is correct
4 Correct 97 ms 62804 KB Output is correct
5 Correct 166 ms 75860 KB Output is correct
6 Correct 153 ms 75236 KB Output is correct
7 Correct 169 ms 75860 KB Output is correct
8 Correct 195 ms 75964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23920 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Incorrect 7 ms 24152 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23920 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Incorrect 7 ms 24152 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23920 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Incorrect 7 ms 24152 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 55056 KB Output is correct
2 Correct 61 ms 55120 KB Output is correct
3 Correct 112 ms 62284 KB Output is correct
4 Correct 97 ms 62804 KB Output is correct
5 Correct 166 ms 75860 KB Output is correct
6 Correct 153 ms 75236 KB Output is correct
7 Correct 169 ms 75860 KB Output is correct
8 Correct 195 ms 75964 KB Output is correct
9 Correct 212 ms 100920 KB Output is correct
10 Correct 150 ms 67956 KB Output is correct
11 Incorrect 311 ms 112268 KB 1st lines differ - on the 1st token, expected: '72889508713304', found: '72889208890328'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 116 ms 71104 KB Output is correct
2 Correct 133 ms 76096 KB Output is correct
3 Correct 59 ms 55336 KB Output is correct
4 Correct 58 ms 54968 KB Output is correct
5 Correct 363 ms 158124 KB Output is correct
6 Correct 467 ms 180928 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 262 ms 101044 KB Output is correct
9 Correct 303 ms 114928 KB Output is correct
10 Correct 126 ms 72580 KB Output is correct
11 Correct 132 ms 77668 KB Output is correct
12 Correct 5 ms 23896 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
14 Correct 6 ms 23900 KB Output is correct
15 Correct 6 ms 24152 KB Output is correct
16 Correct 58 ms 55132 KB Output is correct
17 Correct 59 ms 55128 KB Output is correct
18 Correct 163 ms 86336 KB Output is correct
19 Correct 182 ms 93112 KB Output is correct
20 Correct 137 ms 78088 KB Output is correct
21 Correct 174 ms 82996 KB Output is correct
22 Correct 141 ms 78024 KB Output is correct
23 Correct 162 ms 82936 KB Output is correct
24 Correct 75 ms 55056 KB Output is correct
25 Correct 61 ms 55120 KB Output is correct
26 Correct 112 ms 62284 KB Output is correct
27 Correct 97 ms 62804 KB Output is correct
28 Correct 166 ms 75860 KB Output is correct
29 Correct 153 ms 75236 KB Output is correct
30 Correct 169 ms 75860 KB Output is correct
31 Correct 195 ms 75964 KB Output is correct
32 Correct 5 ms 23900 KB Output is correct
33 Correct 5 ms 23900 KB Output is correct
34 Correct 5 ms 23900 KB Output is correct
35 Correct 5 ms 23900 KB Output is correct
36 Correct 5 ms 23900 KB Output is correct
37 Correct 5 ms 23920 KB Output is correct
38 Correct 5 ms 23900 KB Output is correct
39 Correct 5 ms 23900 KB Output is correct
40 Incorrect 7 ms 24152 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048'
41 Halted 0 ms 0 KB -