Submission #630091

# Submission time Handle Problem Language Result Execution time Memory
630091 2022-08-15T16:36:36 Z CyanForces Catfish Farm (IOI22_fish) C++17
37 / 100
1000 ms 40204 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define debug(...) //ignore
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef long double ld;


bool smin(auto &a, auto&& b) { return (b < a) ? (a = b, 1) : 0; } 
bool smax(auto &a, auto&& b) { return (a < b) ? (a = b, 1) : 0; } 

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
    std::vector<int> W) {

  int n = N, m = M;
  vi x(all(X)), y(all(Y));
  vi w(all(W));

  vector<vi> at_x(n);
  vector<vi> at_dp(n);
  rep(i,0,n) at_dp[i].emplace_back(-1);
  rep(i,0,m) {
    at_x[x[i]].emplace_back(i);
    if(x[i]) at_dp[x[i]-1].emplace_back(y[i]);
    if(x[i]+1 < n) at_dp[x[i]+1].emplace_back(y[i]);
  }
  rep(i,0,n) sort(all(at_dp[i]));
  rep(i,0,n) sort(all(at_x[i]), [&](int a, int b) { return y[a] < y[b]; });

  auto fish = [&](int x, int h0, int h1) -> ll {
    ll res = 0;
    for(int i : at_x[x]) if(h0 <= y[i] && y[i] <= h1) res += w[i];
    return res;
  };

  vector<vi> dp_inc(n), dp_dec(n);
  rep(i,0,n) {
    vi& cur_inc = dp_inc[i];
    vi& cur_dec = dp_dec[i];
    cur_inc.assign(sz(at_dp[i]),0);
    cur_dec.assign(sz(at_dp[i]),0);

    if(i == 0) continue;

    vi& prev_inc = dp_inc[i-1];
    vi& prev_dec = dp_dec[i-1];

    rep(j,0,sz(cur_inc)) {
      rep(jp,0,sz(prev_inc)) {
        int h_cur = at_dp[i][j];
        int h_prev = at_dp[i-1][jp];
        if(h_prev > h_cur) continue;
        smax(cur_inc[j], prev_inc[jp] + fish(i-1,h_prev+1,h_cur));
      }
    }

    rep(j,0,sz(cur_dec)) {
      rep(jp,0,sz(prev_dec)) {
        int h_cur = at_dp[i][j];
        int h_prev = at_dp[i-1][jp];
        if(h_prev < h_cur) continue;
        smax(cur_dec[j], prev_dec[jp] + fish(i,h_cur+1,h_prev));
      }
    }

    rep(j,0,sz(cur_dec)) {
      rep(jp,0,sz(prev_inc)) {
        int h_cur = at_dp[i][j];
        int h_prev = at_dp[i-1][jp];
        if(h_prev < h_cur) continue;
        smax(cur_dec[j], prev_inc[jp] + fish(i,h_cur+1,h_prev));
      }
    }

    if(i == 1) continue;

    for(auto prev : {dp_inc[i-2], dp_dec[i-2]}) {
      rep(j,0,sz(at_dp[i])) {
        rep(jp,0,sz(prev)) {
          int h_cur = at_dp[i][j];
          int h_prev = at_dp[i-2][jp];
          ll q = prev[jp] + fish(i-1,0,max(h_prev, h_cur));
          smax(cur_inc[j], q);
          smax(cur_dec[j], q);
        }
      }
    }
  }

  ll ans = 0;
  ans = max(ans, *max_element(all(dp_inc[n-1])));
  ans = max(ans, *max_element(all(dp_dec[n-1])));
  if(n >= 2) {
    rep(jp,0,sz(at_dp[n-2])) {
      int h_prev = at_dp[n-2][jp];
      smax(ans, dp_inc[n-2][jp] + fish(n-1,0,h_prev));
      smax(ans, dp_dec[n-2][jp] + fish(n-1,0,h_prev));
    }
  }

  return ans;
}

Compilation message

fish.cpp:16:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   16 | bool smin(auto &a, auto&& b) { return (b < a) ? (a = b, 1) : 0; }
      |           ^~~~
fish.cpp:16:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   16 | bool smin(auto &a, auto&& b) { return (b < a) ? (a = b, 1) : 0; }
      |                    ^~~~
fish.cpp:17:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   17 | bool smax(auto &a, auto&& b) { return (a < b) ? (a = b, 1) : 0; }
      |           ^~~~
fish.cpp:17:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   17 | bool smax(auto &a, auto&& b) { return (a < b) ? (a = b, 1) : 0; }
      |                    ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 17912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1087 ms 25000 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 19020 KB Output is correct
2 Correct 31 ms 19080 KB Output is correct
3 Correct 85 ms 22120 KB Output is correct
4 Correct 71 ms 22388 KB Output is correct
5 Correct 134 ms 28492 KB Output is correct
6 Correct 139 ms 28464 KB Output is correct
7 Correct 133 ms 28484 KB Output is correct
8 Correct 138 ms 28460 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 0 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 6 ms 584 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 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 0 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 6 ms 584 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 134 ms 532 KB Output is correct
17 Execution timed out 1095 ms 3748 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 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 0 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 6 ms 584 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 134 ms 532 KB Output is correct
17 Execution timed out 1095 ms 3748 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 19020 KB Output is correct
2 Correct 31 ms 19080 KB Output is correct
3 Correct 85 ms 22120 KB Output is correct
4 Correct 71 ms 22388 KB Output is correct
5 Correct 134 ms 28492 KB Output is correct
6 Correct 139 ms 28464 KB Output is correct
7 Correct 133 ms 28484 KB Output is correct
8 Correct 138 ms 28460 KB Output is correct
9 Correct 138 ms 28456 KB Output is correct
10 Correct 111 ms 20224 KB Output is correct
11 Correct 330 ms 40200 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 33 ms 19020 KB Output is correct
19 Correct 32 ms 19084 KB Output is correct
20 Correct 33 ms 18996 KB Output is correct
21 Correct 31 ms 19028 KB Output is correct
22 Correct 162 ms 28204 KB Output is correct
23 Correct 280 ms 40156 KB Output is correct
24 Correct 277 ms 40204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 17912 KB Time limit exceeded
2 Halted 0 ms 0 KB -