Submission #721332

# Submission time Handle Problem Language Result Execution time Memory
721332 2023-04-10T17:20:12 Z Yell0 Catfish Farm (IOI22_fish) C++17
100 / 100
273 ms 35716 KB
#include <bits/stdc++.h>
#define r first
#define w second
 
using namespace std;
typedef long long ll;
typedef pair<int,ll> pii;
const int MN=1e5+2;

ll max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W) {
  vector<vector<pii>> fish(N+2);
  for(int i=0;i<M;++i) fish[X[i]+1].push_back({Y[i]+1,(ll)W[i]});

  fish[0].push_back({0,0LL});
  fish[N+1].push_back({0,0LL});
  for(int i=1;i<=N;++i) {
    fish[i].push_back({0,0LL});
    sort(fish[i].begin(),fish[i].end());
    for(int j=1;j<(int)fish[i].size();++j) fish[i][j].w+=fish[i][j-1].w;
  }

  auto pfx=[&](int c,int r) {
    return (--upper_bound(fish[c].begin(),fish[c].end(),pii(r,LLONG_MAX)))->w;
  };

  vector<vector<int>> stops(N+2);
  stops[0].push_back(0);
  stops[N+1].push_back(0);
  for(int i=1;i<=N;++i) {
    for(pii f:fish[i-1]) stops[i].push_back(f.r);
    for(pii f:fish[i+1]) stops[i].push_back(f.r);
    sort(stops[i].begin(),stops[i].end());
    stops[i].erase(unique(stops[i].begin(),stops[i].end()),stops[i].end());
  }

  vector<ll> dp[2];
  dp[0]={0LL};
  dp[1]={0LL};
  for(int i=1;i<=N+1;++i) {
    vector<ll> ndp[2];
    ll pf=0,sf=0;
    int pfi=0,sfi=(int)stops[i-1].size()-1;
    for(int s=0;s<(int)stops[i].size();++s) {
      while(pfi<(int)stops[i-1].size()&&stops[i-1][pfi]<=stops[i][s]) {
        pf=max(pf,dp[0][pfi]-pfx(i-1,stops[i-1][pfi]));
        ++pfi;
      }
      ndp[0].push_back(max(dp[1][0],pf+pfx(i-1,stops[i][s])));
    }
    for(int s=(int)stops[i].size()-1;s>=0;--s) {
      while(sfi>=0&&stops[i-1][sfi]>=stops[i][s]) {
        sf=max(sf,max(dp[0][sfi],dp[1][sfi])+pfx(i,stops[i-1][sfi]));
        --sfi;
      }
      ndp[1].push_back(sf-pfx(i,stops[i][s]));
    }
    reverse(ndp[1].begin(),ndp[1].end());
    dp[0].clear();
    dp[1].clear();
    for(ll x:ndp[0]) dp[0].push_back(x);
    for(ll x:ndp[1]) dp[1].push_back(x);
  }

  return max(dp[0][0],dp[1][0]);
}
# Verdict Execution time Memory Grader output
1 Correct 66 ms 17212 KB Output is correct
2 Correct 76 ms 21400 KB Output is correct
3 Correct 28 ms 11340 KB Output is correct
4 Correct 27 ms 11220 KB Output is correct
5 Correct 211 ms 35716 KB Output is correct
6 Correct 210 ms 34644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 136 ms 21056 KB Output is correct
3 Correct 156 ms 27812 KB Output is correct
4 Correct 70 ms 18504 KB Output is correct
5 Correct 78 ms 21400 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 32 ms 11212 KB Output is correct
11 Correct 28 ms 11172 KB Output is correct
12 Correct 73 ms 18876 KB Output is correct
13 Correct 95 ms 21804 KB Output is correct
14 Correct 75 ms 16964 KB Output is correct
15 Correct 97 ms 18800 KB Output is correct
16 Correct 71 ms 17048 KB Output is correct
17 Correct 81 ms 18744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11268 KB Output is correct
2 Correct 25 ms 11156 KB Output is correct
3 Correct 52 ms 12244 KB Output is correct
4 Correct 47 ms 12648 KB Output is correct
5 Correct 86 ms 15672 KB Output is correct
6 Correct 78 ms 15564 KB Output is correct
7 Correct 88 ms 15680 KB Output is correct
8 Correct 88 ms 15692 KB Output is correct
# Verdict Execution time Memory 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 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 24 ms 3308 KB Output is correct
18 Correct 24 ms 4192 KB Output is correct
19 Correct 20 ms 4052 KB Output is correct
20 Correct 21 ms 4028 KB Output is correct
21 Correct 20 ms 3880 KB Output is correct
22 Correct 43 ms 7612 KB Output is correct
23 Correct 6 ms 980 KB Output is correct
24 Correct 19 ms 2388 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 6 ms 892 KB Output is correct
# Verdict Execution time Memory 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 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 24 ms 3308 KB Output is correct
18 Correct 24 ms 4192 KB Output is correct
19 Correct 20 ms 4052 KB Output is correct
20 Correct 21 ms 4028 KB Output is correct
21 Correct 20 ms 3880 KB Output is correct
22 Correct 43 ms 7612 KB Output is correct
23 Correct 6 ms 980 KB Output is correct
24 Correct 19 ms 2388 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 6 ms 892 KB Output is correct
27 Correct 3 ms 688 KB Output is correct
28 Correct 127 ms 17304 KB Output is correct
29 Correct 199 ms 23504 KB Output is correct
30 Correct 208 ms 22356 KB Output is correct
31 Correct 197 ms 22480 KB Output is correct
32 Correct 149 ms 24956 KB Output is correct
33 Correct 202 ms 22372 KB Output is correct
34 Correct 200 ms 22404 KB Output is correct
35 Correct 69 ms 9352 KB Output is correct
36 Correct 207 ms 24652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11268 KB Output is correct
2 Correct 25 ms 11156 KB Output is correct
3 Correct 52 ms 12244 KB Output is correct
4 Correct 47 ms 12648 KB Output is correct
5 Correct 86 ms 15672 KB Output is correct
6 Correct 78 ms 15564 KB Output is correct
7 Correct 88 ms 15680 KB Output is correct
8 Correct 88 ms 15692 KB Output is correct
9 Correct 90 ms 15664 KB Output is correct
10 Correct 65 ms 11468 KB Output is correct
11 Correct 151 ms 22740 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 26 ms 11268 KB Output is correct
19 Correct 25 ms 11140 KB Output is correct
20 Correct 26 ms 11220 KB Output is correct
21 Correct 24 ms 11244 KB Output is correct
22 Correct 99 ms 16188 KB Output is correct
23 Correct 150 ms 22720 KB Output is correct
24 Correct 162 ms 22804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 17212 KB Output is correct
2 Correct 76 ms 21400 KB Output is correct
3 Correct 28 ms 11340 KB Output is correct
4 Correct 27 ms 11220 KB Output is correct
5 Correct 211 ms 35716 KB Output is correct
6 Correct 210 ms 34644 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 136 ms 21056 KB Output is correct
9 Correct 156 ms 27812 KB Output is correct
10 Correct 70 ms 18504 KB Output is correct
11 Correct 78 ms 21400 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 32 ms 11212 KB Output is correct
17 Correct 28 ms 11172 KB Output is correct
18 Correct 73 ms 18876 KB Output is correct
19 Correct 95 ms 21804 KB Output is correct
20 Correct 75 ms 16964 KB Output is correct
21 Correct 97 ms 18800 KB Output is correct
22 Correct 71 ms 17048 KB Output is correct
23 Correct 81 ms 18744 KB Output is correct
24 Correct 26 ms 11268 KB Output is correct
25 Correct 25 ms 11156 KB Output is correct
26 Correct 52 ms 12244 KB Output is correct
27 Correct 47 ms 12648 KB Output is correct
28 Correct 86 ms 15672 KB Output is correct
29 Correct 78 ms 15564 KB Output is correct
30 Correct 88 ms 15680 KB Output is correct
31 Correct 88 ms 15692 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 292 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 24 ms 3308 KB Output is correct
49 Correct 24 ms 4192 KB Output is correct
50 Correct 20 ms 4052 KB Output is correct
51 Correct 21 ms 4028 KB Output is correct
52 Correct 20 ms 3880 KB Output is correct
53 Correct 43 ms 7612 KB Output is correct
54 Correct 6 ms 980 KB Output is correct
55 Correct 19 ms 2388 KB Output is correct
56 Correct 2 ms 328 KB Output is correct
57 Correct 6 ms 892 KB Output is correct
58 Correct 3 ms 688 KB Output is correct
59 Correct 127 ms 17304 KB Output is correct
60 Correct 199 ms 23504 KB Output is correct
61 Correct 208 ms 22356 KB Output is correct
62 Correct 197 ms 22480 KB Output is correct
63 Correct 149 ms 24956 KB Output is correct
64 Correct 202 ms 22372 KB Output is correct
65 Correct 200 ms 22404 KB Output is correct
66 Correct 69 ms 9352 KB Output is correct
67 Correct 207 ms 24652 KB Output is correct
68 Correct 90 ms 15664 KB Output is correct
69 Correct 65 ms 11468 KB Output is correct
70 Correct 151 ms 22740 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 26 ms 11268 KB Output is correct
78 Correct 25 ms 11140 KB Output is correct
79 Correct 26 ms 11220 KB Output is correct
80 Correct 24 ms 11244 KB Output is correct
81 Correct 99 ms 16188 KB Output is correct
82 Correct 150 ms 22720 KB Output is correct
83 Correct 162 ms 22804 KB Output is correct
84 Correct 258 ms 31956 KB Output is correct
85 Correct 272 ms 33144 KB Output is correct
86 Correct 231 ms 32584 KB Output is correct
87 Correct 247 ms 33872 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 273 ms 33776 KB Output is correct
90 Correct 224 ms 33268 KB Output is correct
91 Correct 188 ms 33664 KB Output is correct