답안 #852747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852747 2023-09-22T16:08:25 Z abcvuitunggio 메기 농장 (IOI22_fish) C++17
100 / 100
587 ms 187164 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>=0;i--){
        for (int j=0;j<4;j++){
            reverse(mx[i+1][j][1].begin(),mx[i+1][j][1].end());
            for (int k=0;k<2;k++)
                for (int l=1;l<mx[i+1][j][k].size();l++)
                    mx[i+1][j][k][l].second=max(mx[i+1][j][k][l].second,mx[i+1][j][k][l-1].second);
        }
        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)),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));
            res=max(res,max(x,y));
            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);
        }
    }
    return res;
}

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:53: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]
   53 |                 for (int l=1;l<mx[i+1][j][k].size();l++)
      |                              ~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 71240 KB Output is correct
2 Correct 153 ms 76348 KB Output is correct
3 Correct 60 ms 55120 KB Output is correct
4 Correct 61 ms 55120 KB Output is correct
5 Correct 353 ms 158200 KB Output is correct
6 Correct 453 ms 181020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 249 ms 101168 KB Output is correct
3 Correct 279 ms 111268 KB Output is correct
4 Correct 118 ms 71136 KB Output is correct
5 Correct 146 ms 76092 KB Output is correct
6 Correct 5 ms 23896 KB Output is correct
7 Correct 5 ms 23896 KB Output is correct
8 Correct 6 ms 23896 KB Output is correct
9 Correct 5 ms 23896 KB Output is correct
10 Correct 59 ms 55120 KB Output is correct
11 Correct 59 ms 55120 KB Output is correct
12 Correct 150 ms 84796 KB Output is correct
13 Correct 185 ms 91832 KB Output is correct
14 Correct 143 ms 76728 KB Output is correct
15 Correct 170 ms 81460 KB Output is correct
16 Correct 141 ms 76700 KB Output is correct
17 Correct 155 ms 81456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 55120 KB Output is correct
2 Correct 63 ms 55124 KB Output is correct
3 Correct 117 ms 62288 KB Output is correct
4 Correct 94 ms 62288 KB Output is correct
5 Correct 157 ms 74376 KB Output is correct
6 Correct 164 ms 74316 KB Output is correct
7 Correct 154 ms 74320 KB Output is correct
8 Correct 161 ms 74360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 5 ms 23896 KB Output is correct
5 Correct 6 ms 23896 KB Output is correct
6 Correct 5 ms 23896 KB Output is correct
7 Correct 5 ms 24152 KB Output is correct
8 Correct 5 ms 23896 KB Output is correct
9 Correct 6 ms 23896 KB Output is correct
10 Correct 9 ms 24592 KB Output is correct
11 Correct 7 ms 24156 KB Output is correct
12 Correct 7 ms 24156 KB Output is correct
13 Correct 6 ms 23996 KB Output is correct
14 Correct 8 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 5 ms 23896 KB Output is correct
5 Correct 6 ms 23896 KB Output is correct
6 Correct 5 ms 23896 KB Output is correct
7 Correct 5 ms 24152 KB Output is correct
8 Correct 5 ms 23896 KB Output is correct
9 Correct 6 ms 23896 KB Output is correct
10 Correct 9 ms 24592 KB Output is correct
11 Correct 7 ms 24156 KB Output is correct
12 Correct 7 ms 24156 KB Output is correct
13 Correct 6 ms 23996 KB Output is correct
14 Correct 8 ms 24192 KB Output is correct
15 Correct 7 ms 23900 KB Output is correct
16 Correct 8 ms 24668 KB Output is correct
17 Correct 54 ms 39616 KB Output is correct
18 Correct 55 ms 39484 KB Output is correct
19 Correct 51 ms 39848 KB Output is correct
20 Correct 44 ms 38132 KB Output is correct
21 Correct 45 ms 37972 KB Output is correct
22 Correct 87 ms 52104 KB Output is correct
23 Correct 18 ms 27516 KB Output is correct
24 Correct 45 ms 36080 KB Output is correct
25 Correct 8 ms 24480 KB Output is correct
26 Correct 19 ms 26972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 5 ms 23896 KB Output is correct
5 Correct 6 ms 23896 KB Output is correct
6 Correct 5 ms 23896 KB Output is correct
7 Correct 5 ms 24152 KB Output is correct
8 Correct 5 ms 23896 KB Output is correct
9 Correct 6 ms 23896 KB Output is correct
10 Correct 9 ms 24592 KB Output is correct
11 Correct 7 ms 24156 KB Output is correct
12 Correct 7 ms 24156 KB Output is correct
13 Correct 6 ms 23996 KB Output is correct
14 Correct 8 ms 24192 KB Output is correct
15 Correct 7 ms 23900 KB Output is correct
16 Correct 8 ms 24668 KB Output is correct
17 Correct 54 ms 39616 KB Output is correct
18 Correct 55 ms 39484 KB Output is correct
19 Correct 51 ms 39848 KB Output is correct
20 Correct 44 ms 38132 KB Output is correct
21 Correct 45 ms 37972 KB Output is correct
22 Correct 87 ms 52104 KB Output is correct
23 Correct 18 ms 27516 KB Output is correct
24 Correct 45 ms 36080 KB Output is correct
25 Correct 8 ms 24480 KB Output is correct
26 Correct 19 ms 26972 KB Output is correct
27 Correct 12 ms 26204 KB Output is correct
28 Correct 229 ms 89068 KB Output is correct
29 Correct 345 ms 113568 KB Output is correct
30 Correct 431 ms 146240 KB Output is correct
31 Correct 424 ms 146592 KB Output is correct
32 Correct 270 ms 108324 KB Output is correct
33 Correct 426 ms 146172 KB Output is correct
34 Correct 441 ms 146312 KB Output is correct
35 Correct 159 ms 72628 KB Output is correct
36 Correct 408 ms 129972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 55120 KB Output is correct
2 Correct 63 ms 55124 KB Output is correct
3 Correct 117 ms 62288 KB Output is correct
4 Correct 94 ms 62288 KB Output is correct
5 Correct 157 ms 74376 KB Output is correct
6 Correct 164 ms 74316 KB Output is correct
7 Correct 154 ms 74320 KB Output is correct
8 Correct 161 ms 74360 KB Output is correct
9 Correct 227 ms 99408 KB Output is correct
10 Correct 128 ms 66368 KB Output is correct
11 Correct 295 ms 108972 KB Output is correct
12 Correct 6 ms 23896 KB Output is correct
13 Correct 6 ms 23900 KB Output is correct
14 Correct 5 ms 23896 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
16 Correct 6 ms 23924 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 64 ms 55120 KB Output is correct
19 Correct 60 ms 55012 KB Output is correct
20 Correct 75 ms 55124 KB Output is correct
21 Correct 62 ms 55132 KB Output is correct
22 Correct 294 ms 96508 KB Output is correct
23 Correct 331 ms 140624 KB Output is correct
24 Correct 411 ms 150452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 71240 KB Output is correct
2 Correct 153 ms 76348 KB Output is correct
3 Correct 60 ms 55120 KB Output is correct
4 Correct 61 ms 55120 KB Output is correct
5 Correct 353 ms 158200 KB Output is correct
6 Correct 453 ms 181020 KB Output is correct
7 Correct 5 ms 23896 KB Output is correct
8 Correct 249 ms 101168 KB Output is correct
9 Correct 279 ms 111268 KB Output is correct
10 Correct 118 ms 71136 KB Output is correct
11 Correct 146 ms 76092 KB Output is correct
12 Correct 5 ms 23896 KB Output is correct
13 Correct 5 ms 23896 KB Output is correct
14 Correct 6 ms 23896 KB Output is correct
15 Correct 5 ms 23896 KB Output is correct
16 Correct 59 ms 55120 KB Output is correct
17 Correct 59 ms 55120 KB Output is correct
18 Correct 150 ms 84796 KB Output is correct
19 Correct 185 ms 91832 KB Output is correct
20 Correct 143 ms 76728 KB Output is correct
21 Correct 170 ms 81460 KB Output is correct
22 Correct 141 ms 76700 KB Output is correct
23 Correct 155 ms 81456 KB Output is correct
24 Correct 59 ms 55120 KB Output is correct
25 Correct 63 ms 55124 KB Output is correct
26 Correct 117 ms 62288 KB Output is correct
27 Correct 94 ms 62288 KB Output is correct
28 Correct 157 ms 74376 KB Output is correct
29 Correct 164 ms 74316 KB Output is correct
30 Correct 154 ms 74320 KB Output is correct
31 Correct 161 ms 74360 KB Output is correct
32 Correct 5 ms 23896 KB Output is correct
33 Correct 5 ms 23896 KB Output is correct
34 Correct 6 ms 23896 KB Output is correct
35 Correct 5 ms 23896 KB Output is correct
36 Correct 6 ms 23896 KB Output is correct
37 Correct 5 ms 23896 KB Output is correct
38 Correct 5 ms 24152 KB Output is correct
39 Correct 5 ms 23896 KB Output is correct
40 Correct 6 ms 23896 KB Output is correct
41 Correct 9 ms 24592 KB Output is correct
42 Correct 7 ms 24156 KB Output is correct
43 Correct 7 ms 24156 KB Output is correct
44 Correct 6 ms 23996 KB Output is correct
45 Correct 8 ms 24192 KB Output is correct
46 Correct 7 ms 23900 KB Output is correct
47 Correct 8 ms 24668 KB Output is correct
48 Correct 54 ms 39616 KB Output is correct
49 Correct 55 ms 39484 KB Output is correct
50 Correct 51 ms 39848 KB Output is correct
51 Correct 44 ms 38132 KB Output is correct
52 Correct 45 ms 37972 KB Output is correct
53 Correct 87 ms 52104 KB Output is correct
54 Correct 18 ms 27516 KB Output is correct
55 Correct 45 ms 36080 KB Output is correct
56 Correct 8 ms 24480 KB Output is correct
57 Correct 19 ms 26972 KB Output is correct
58 Correct 12 ms 26204 KB Output is correct
59 Correct 229 ms 89068 KB Output is correct
60 Correct 345 ms 113568 KB Output is correct
61 Correct 431 ms 146240 KB Output is correct
62 Correct 424 ms 146592 KB Output is correct
63 Correct 270 ms 108324 KB Output is correct
64 Correct 426 ms 146172 KB Output is correct
65 Correct 441 ms 146312 KB Output is correct
66 Correct 159 ms 72628 KB Output is correct
67 Correct 408 ms 129972 KB Output is correct
68 Correct 227 ms 99408 KB Output is correct
69 Correct 128 ms 66368 KB Output is correct
70 Correct 295 ms 108972 KB Output is correct
71 Correct 6 ms 23896 KB Output is correct
72 Correct 6 ms 23900 KB Output is correct
73 Correct 5 ms 23896 KB Output is correct
74 Correct 5 ms 23900 KB Output is correct
75 Correct 6 ms 23924 KB Output is correct
76 Correct 5 ms 23900 KB Output is correct
77 Correct 64 ms 55120 KB Output is correct
78 Correct 60 ms 55012 KB Output is correct
79 Correct 75 ms 55124 KB Output is correct
80 Correct 62 ms 55132 KB Output is correct
81 Correct 294 ms 96508 KB Output is correct
82 Correct 331 ms 140624 KB Output is correct
83 Correct 411 ms 150452 KB Output is correct
84 Correct 484 ms 157320 KB Output is correct
85 Correct 501 ms 165628 KB Output is correct
86 Correct 523 ms 183732 KB Output is correct
87 Correct 587 ms 187164 KB Output is correct
88 Correct 5 ms 23896 KB Output is correct
89 Correct 560 ms 186808 KB Output is correct
90 Correct 457 ms 173916 KB Output is correct
91 Correct 362 ms 151236 KB Output is correct