Submission #807303

# Submission time Handle Problem Language Result Execution time Memory
807303 2023-08-04T15:37:32 Z TimDee Catfish Farm (IOI22_fish) C++17
100 / 100
366 ms 101576 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
#define pi pair<ll,ll>
#define f first
#define s second

const int N=100005;
vector<ll> pr[N];
vector<pi> f[N];

ll sum(int i, int j) {
  int l=0, r=f[i].size();
  while (l<r) {
    int m=(l+r+1)>>1;
    if (f[i][m-1].f>j) r=m-1;
    else l=m;
  }
  return pr[i][r];
}

vector<pi> dp[N], dp2[N], dp3[N];
vector<ll> prmx[N], prmx2[N], sfmx[N];


ll prmxquery(int i, int j) {
  return prmx[i].back();
}
ll prmx2query(int i, int j) {
  int l=0, r=dp3[i].size();
  while (l<r) {
    int m=(l+r+1)>>1;
    if (dp3[i][m-1].f >= j) r=m-1;
    else l=m;
  }
  return prmx2[i][r];
}
ll sfmxquery(int i, int j) {
  return sfmx[i][0];
}

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {

  forn(i,m) {
    f[x[i]+1].pb({y[i]+1,w[i]});
  }
  for(int i=1;i<=n;++i) {
    sort(all(f[i]));
    f[i].pb({n+1,0});
    pr[i]={0};
    forn(j,f[i].size()) pr[i].pb(pr[i].back()+f[i][j].s);
  }

  dp[0].pb({0,0});
  dp[0].pb({n,0});
  pr[0]={0,0,0};
  dp2[0]=dp3[0]=dp[0];
  prmx[0]={0,0};
  prmx2[0]=sfmx[0]=prmx[0];
  pr[n+1]={0,0,0};

  for(int i=1; i<=n; ++i) {
    if (f[i][0].f!=1) {
      int j=0;

      ll d=0;
      if (i>=2) {
        d=max(d,prmxquery(i-2,j)+sum(i-1,j));
        d=max(d,sfmxquery(i-2,j));
      }

      d=max(d,prmx2query(i-1,j)+sum(i-1,j));
      d=max(d,prmxquery(i-1,j));
      ll d3=d;
      d=max(d,sfmxquery(i-1,j)-sum(i,j));
      ll d2=d+sum(i+1,j);

      dp[i].pb({j,d});
      dp2[i].pb({j,d2});
      dp3[i].pb({j,d3});
    }
    for(auto&x:f[i]) {
      int j=x.f-1;

      ll d=0;
      if (i>=2) {
        d=max(d,prmxquery(i-2,j)+sum(i-1,j));
        d=max(d,sfmxquery(i-2,j));
      }

      d=max(d,prmx2query(i-1,j)+sum(i-1,j));
      d=max(d,prmxquery(i-1,j));
      ll d3=d;
      d=max(d,sfmxquery(i-1,j)-sum(i,j));
      ll d2=d+sum(i+1,j);

      dp[i].pb({j,d});
      dp2[i].pb({j,d2});
      dp3[i].pb({j,d3});
    }
    prmx[i]={0};
    prmx2[i]=sfmx[i]=prmx[i];

    for (int j=0; j<dp[i].size(); ++j) {
      prmx[i].pb(max(prmx[i].back(),dp[i][j].s));
      prmx2[i].pb(max(prmx2[i].back(),dp3[i][j].s-sum(i,dp3[i][j].f)));
    }
      
    reverse(all(dp2[i]));
    for (int j=0; j<dp2[i].size(); ++j) {
      sfmx[i].pb(max(sfmx[i].back(),dp2[i][j].s));
    }
    reverse(all(dp2[i]));
    reverse(all(sfmx[i]));

  }
  ll ans=0;
  for(auto&x:dp[n]) ans=max(ans,x.s);
  return ans;
  return prmx[n].back();

}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
......
   55 |     forn(j,f[i].size()) pr[i].pb(pr[i].back()+f[i][j].s);
      |          ~~~~~~~~~~~~~          
fish.cpp:55:5: note: in expansion of macro 'forn'
   55 |     forn(j,f[i].size()) pr[i].pb(pr[i].back()+f[i][j].s);
      |     ^~~~
fish.cpp:108:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for (int j=0; j<dp[i].size(); ++j) {
      |                   ~^~~~~~~~~~~~~
fish.cpp:114:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |     for (int j=0; j<dp2[i].size(); ++j) {
      |                   ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 121 ms 59568 KB Output is correct
2 Correct 141 ms 65264 KB Output is correct
3 Correct 80 ms 53488 KB Output is correct
4 Correct 77 ms 53448 KB Output is correct
5 Correct 244 ms 88940 KB Output is correct
6 Correct 298 ms 101576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19028 KB Output is correct
2 Correct 188 ms 69460 KB Output is correct
3 Correct 214 ms 77220 KB Output is correct
4 Correct 123 ms 59576 KB Output is correct
5 Correct 155 ms 65284 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 8 ms 19028 KB Output is correct
8 Correct 8 ms 19088 KB Output is correct
9 Correct 8 ms 19064 KB Output is correct
10 Correct 76 ms 53472 KB Output is correct
11 Correct 80 ms 53508 KB Output is correct
12 Correct 123 ms 59568 KB Output is correct
13 Correct 144 ms 65204 KB Output is correct
14 Correct 131 ms 59872 KB Output is correct
15 Correct 143 ms 64360 KB Output is correct
16 Correct 129 ms 59856 KB Output is correct
17 Correct 148 ms 64308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 53472 KB Output is correct
2 Correct 76 ms 53408 KB Output is correct
3 Correct 91 ms 52900 KB Output is correct
4 Correct 92 ms 55572 KB Output is correct
5 Correct 119 ms 59824 KB Output is correct
6 Correct 116 ms 59808 KB Output is correct
7 Correct 116 ms 59800 KB Output is correct
8 Correct 117 ms 59808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19080 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 8 ms 19028 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 8 ms 19072 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 11 ms 18988 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 10 ms 19540 KB Output is correct
11 Correct 9 ms 19156 KB Output is correct
12 Correct 9 ms 19360 KB Output is correct
13 Correct 9 ms 19136 KB Output is correct
14 Correct 9 ms 19236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19080 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 8 ms 19028 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 8 ms 19072 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 11 ms 18988 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 10 ms 19540 KB Output is correct
11 Correct 9 ms 19156 KB Output is correct
12 Correct 9 ms 19360 KB Output is correct
13 Correct 9 ms 19136 KB Output is correct
14 Correct 9 ms 19236 KB Output is correct
15 Correct 9 ms 19220 KB Output is correct
16 Correct 10 ms 19412 KB Output is correct
17 Correct 30 ms 24752 KB Output is correct
18 Correct 32 ms 28212 KB Output is correct
19 Correct 36 ms 27340 KB Output is correct
20 Correct 30 ms 27424 KB Output is correct
21 Correct 31 ms 27476 KB Output is correct
22 Correct 55 ms 35712 KB Output is correct
23 Correct 13 ms 20600 KB Output is correct
24 Correct 23 ms 23500 KB Output is correct
25 Correct 9 ms 19284 KB Output is correct
26 Correct 12 ms 20464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19080 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 8 ms 19028 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 8 ms 19072 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 11 ms 18988 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 10 ms 19540 KB Output is correct
11 Correct 9 ms 19156 KB Output is correct
12 Correct 9 ms 19360 KB Output is correct
13 Correct 9 ms 19136 KB Output is correct
14 Correct 9 ms 19236 KB Output is correct
15 Correct 9 ms 19220 KB Output is correct
16 Correct 10 ms 19412 KB Output is correct
17 Correct 30 ms 24752 KB Output is correct
18 Correct 32 ms 28212 KB Output is correct
19 Correct 36 ms 27340 KB Output is correct
20 Correct 30 ms 27424 KB Output is correct
21 Correct 31 ms 27476 KB Output is correct
22 Correct 55 ms 35712 KB Output is correct
23 Correct 13 ms 20600 KB Output is correct
24 Correct 23 ms 23500 KB Output is correct
25 Correct 9 ms 19284 KB Output is correct
26 Correct 12 ms 20464 KB Output is correct
27 Correct 12 ms 20520 KB Output is correct
28 Correct 139 ms 56692 KB Output is correct
29 Correct 177 ms 64788 KB Output is correct
30 Correct 153 ms 62792 KB Output is correct
31 Correct 154 ms 62792 KB Output is correct
32 Correct 168 ms 74284 KB Output is correct
33 Correct 151 ms 62804 KB Output is correct
34 Correct 184 ms 62792 KB Output is correct
35 Correct 68 ms 38884 KB Output is correct
36 Correct 161 ms 72408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 53472 KB Output is correct
2 Correct 76 ms 53408 KB Output is correct
3 Correct 91 ms 52900 KB Output is correct
4 Correct 92 ms 55572 KB Output is correct
5 Correct 119 ms 59824 KB Output is correct
6 Correct 116 ms 59808 KB Output is correct
7 Correct 116 ms 59800 KB Output is correct
8 Correct 117 ms 59808 KB Output is correct
9 Correct 132 ms 69220 KB Output is correct
10 Correct 83 ms 46540 KB Output is correct
11 Correct 169 ms 74176 KB Output is correct
12 Correct 9 ms 19028 KB Output is correct
13 Correct 10 ms 19028 KB Output is correct
14 Correct 8 ms 19028 KB Output is correct
15 Correct 8 ms 19028 KB Output is correct
16 Correct 8 ms 19096 KB Output is correct
17 Correct 8 ms 19028 KB Output is correct
18 Correct 76 ms 53436 KB Output is correct
19 Correct 76 ms 53492 KB Output is correct
20 Correct 80 ms 53472 KB Output is correct
21 Correct 76 ms 53456 KB Output is correct
22 Correct 162 ms 68304 KB Output is correct
23 Correct 194 ms 83012 KB Output is correct
24 Correct 183 ms 83532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 59568 KB Output is correct
2 Correct 141 ms 65264 KB Output is correct
3 Correct 80 ms 53488 KB Output is correct
4 Correct 77 ms 53448 KB Output is correct
5 Correct 244 ms 88940 KB Output is correct
6 Correct 298 ms 101576 KB Output is correct
7 Correct 8 ms 19028 KB Output is correct
8 Correct 188 ms 69460 KB Output is correct
9 Correct 214 ms 77220 KB Output is correct
10 Correct 123 ms 59576 KB Output is correct
11 Correct 155 ms 65284 KB Output is correct
12 Correct 9 ms 19028 KB Output is correct
13 Correct 8 ms 19028 KB Output is correct
14 Correct 8 ms 19088 KB Output is correct
15 Correct 8 ms 19064 KB Output is correct
16 Correct 76 ms 53472 KB Output is correct
17 Correct 80 ms 53508 KB Output is correct
18 Correct 123 ms 59568 KB Output is correct
19 Correct 144 ms 65204 KB Output is correct
20 Correct 131 ms 59872 KB Output is correct
21 Correct 143 ms 64360 KB Output is correct
22 Correct 129 ms 59856 KB Output is correct
23 Correct 148 ms 64308 KB Output is correct
24 Correct 80 ms 53472 KB Output is correct
25 Correct 76 ms 53408 KB Output is correct
26 Correct 91 ms 52900 KB Output is correct
27 Correct 92 ms 55572 KB Output is correct
28 Correct 119 ms 59824 KB Output is correct
29 Correct 116 ms 59808 KB Output is correct
30 Correct 116 ms 59800 KB Output is correct
31 Correct 117 ms 59808 KB Output is correct
32 Correct 11 ms 19080 KB Output is correct
33 Correct 9 ms 19028 KB Output is correct
34 Correct 8 ms 19028 KB Output is correct
35 Correct 9 ms 19028 KB Output is correct
36 Correct 9 ms 19028 KB Output is correct
37 Correct 8 ms 19072 KB Output is correct
38 Correct 10 ms 19028 KB Output is correct
39 Correct 11 ms 18988 KB Output is correct
40 Correct 9 ms 19156 KB Output is correct
41 Correct 10 ms 19540 KB Output is correct
42 Correct 9 ms 19156 KB Output is correct
43 Correct 9 ms 19360 KB Output is correct
44 Correct 9 ms 19136 KB Output is correct
45 Correct 9 ms 19236 KB Output is correct
46 Correct 9 ms 19220 KB Output is correct
47 Correct 10 ms 19412 KB Output is correct
48 Correct 30 ms 24752 KB Output is correct
49 Correct 32 ms 28212 KB Output is correct
50 Correct 36 ms 27340 KB Output is correct
51 Correct 30 ms 27424 KB Output is correct
52 Correct 31 ms 27476 KB Output is correct
53 Correct 55 ms 35712 KB Output is correct
54 Correct 13 ms 20600 KB Output is correct
55 Correct 23 ms 23500 KB Output is correct
56 Correct 9 ms 19284 KB Output is correct
57 Correct 12 ms 20464 KB Output is correct
58 Correct 12 ms 20520 KB Output is correct
59 Correct 139 ms 56692 KB Output is correct
60 Correct 177 ms 64788 KB Output is correct
61 Correct 153 ms 62792 KB Output is correct
62 Correct 154 ms 62792 KB Output is correct
63 Correct 168 ms 74284 KB Output is correct
64 Correct 151 ms 62804 KB Output is correct
65 Correct 184 ms 62792 KB Output is correct
66 Correct 68 ms 38884 KB Output is correct
67 Correct 161 ms 72408 KB Output is correct
68 Correct 132 ms 69220 KB Output is correct
69 Correct 83 ms 46540 KB Output is correct
70 Correct 169 ms 74176 KB Output is correct
71 Correct 9 ms 19028 KB Output is correct
72 Correct 10 ms 19028 KB Output is correct
73 Correct 8 ms 19028 KB Output is correct
74 Correct 8 ms 19028 KB Output is correct
75 Correct 8 ms 19096 KB Output is correct
76 Correct 8 ms 19028 KB Output is correct
77 Correct 76 ms 53436 KB Output is correct
78 Correct 76 ms 53492 KB Output is correct
79 Correct 80 ms 53472 KB Output is correct
80 Correct 76 ms 53456 KB Output is correct
81 Correct 162 ms 68304 KB Output is correct
82 Correct 194 ms 83012 KB Output is correct
83 Correct 183 ms 83532 KB Output is correct
84 Correct 267 ms 87608 KB Output is correct
85 Correct 275 ms 92408 KB Output is correct
86 Correct 366 ms 96692 KB Output is correct
87 Correct 323 ms 100796 KB Output is correct
88 Correct 9 ms 19028 KB Output is correct
89 Correct 323 ms 100808 KB Output is correct
90 Correct 259 ms 99160 KB Output is correct
91 Correct 247 ms 99692 KB Output is correct