Submission #625750

# Submission time Handle Problem Language Result Execution time Memory
625750 2022-08-10T18:32:05 Z d4xn Catfish Farm (IOI22_fish) C++17
9 / 100
1000 ms 169692 KB
#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx2")
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define tuple3 tuple<int, int, int>
 
const int N = 1e5+1;
 
int n, m;
vi c[N];
map<int, int> w[N];
map<int, ll> pre[N];
map<tuple<int, int, int>, ll> dp; // dp[i][j][k] = maximos peces que puedo conseguir
              // con las k primeras columnas donde
              // en la columna k+1 he subido i-1
              // en la columna k+2 he subido j-1
 
ll mx(int curr, int h1, int h2) {
  if (curr == -1) return 0;
  
  tuple3 t = make_tuple(curr, h1, h2);
  auto it = dp.find(t);
  if (it != dp.end()) return it->second;
  
  dp[t] = mx(curr-1, 0, h1);
  it = dp.find(t);
 
  if (curr+1 < n) {
    for (int h : c[curr+1]) {
      h++;
      ll cnt = 0;
 
      // ver si pillo los de la derecha
      if (curr+1 < n && h > h2) {
        if (curr+1 == n) {
          // nada
        }
        else if (curr+2 == n) {
          cnt += pre[curr+1][h-1] - pre[curr+1][h1-1];
          assert(pre[curr+1].count(h-1) && pre[curr+1].count(h1-1));
        }
        else {
          cnt += pre[curr+1][h-1] - pre[curr+1][max(h1, h2)-1];
          assert(pre[curr+1].count(h-1) && pre[curr+1].count(max(h1, h2)-1));
        }
      }
 
      // ver si pillo los de la izquierda      
      if (curr-1 >= 0) {
        cnt += pre[curr-1][h-1];
        assert(pre[curr-1].count(h-1));
      }
      
 
      // ver si he eliminado alguno de los que he pillado
      cnt -= pre[curr][min(h, h1)-1];
      assert(pre[curr].count(min(h, h1)-1));
 
      it->second = max(it->second, cnt + mx(curr-1, h, h1));
    }
  }
 
  if (curr-1 >= 0) {
    for (int h : c[curr-1]) {
      h++;
      ll cnt = 0;
 
      // ver si pillo los de la derecha
      if (curr+1 < n && h > h2) {
        if (curr+1 == n) {
          // nada
        }
        else if (curr+2 == n) {
          cnt += pre[curr+1][h-1] - pre[curr+1][h1-1];
          assert(pre[curr+1].count(h-1) && pre[curr+1].count(h1-1));
        }
        else {
          cnt += pre[curr+1][h-1] - pre[curr+1][max(h1, h2)-1];
          assert(pre[curr+1].count(h-1) && pre[curr+1].count(max(h1, h2)-1));
        }
      }
 
      // ver si pillo los de la izquierda      
      if (curr-1 >= 0) {
        cnt += pre[curr-1][h-1];
        assert(pre[curr-1].count(h-1));
      }
      
 
      // ver si he eliminado alguno de los que he pillado
      cnt -= pre[curr][min(h, h1)-1];
      assert(pre[curr].count(min(h, h1)-1));
 
      it->second = max(it->second, cnt + mx(curr-1, h, h1));
    }
  }

  return it->second;
}
 
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  n = N;
  m = M;
 
  for (int i = 0; i < m; i++) {
    w[X[i]][Y[i]] = W[i];
    c[X[i]].push_back(Y[i]);
  }
 
  map<int, int> heights;
  for (int i = 0; i < n; i++) {
    pre[i][-1] = 0;

    sort(c[i].begin(), c[i].end());
    for (int &h : c[i]) heights[h]++;
 
    if (i >= 3) {
      for (int &h : c[i-3]) {
        heights[h]--;
        if (!heights[h]) heights.erase(h);
      }
    }
 
    ll sum1 = 0;
    ll sum2 = 0;
    ll sum3 = 0;
    for (auto &[h, cnt] : heights) {
      if (w[i].count(h)) sum3 += w[i][h];
      pre[i][h] = sum3;
 
      if (i-1 >= 0) {
        if (w[i-1].count(h)) sum2 += w[i-1][h];
        pre[i-1][h] = sum2;
      }
      if (i-2 >= 0) {
        if (w[i-2].count(h)) sum1 += w[i-2][h];
        pre[i-2][h] = sum1;
      }
    }
  }

  return mx(n-1, 0, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 339 ms 69368 KB Output is correct
2 Correct 396 ms 78876 KB Output is correct
3 Correct 56 ms 46452 KB Output is correct
4 Correct 58 ms 46464 KB Output is correct
5 Execution timed out 1099 ms 169692 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Execution timed out 1099 ms 71272 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 46352 KB Output is correct
2 Correct 56 ms 46456 KB Output is correct
3 Correct 189 ms 62992 KB Output is correct
4 Correct 166 ms 60352 KB Output is correct
5 Correct 459 ms 81632 KB Output is correct
6 Correct 449 ms 81704 KB Output is correct
7 Correct 444 ms 81568 KB Output is correct
8 Correct 443 ms 81584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 11968 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 6 ms 12044 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 11 ms 12268 KB Output is correct
10 Correct 66 ms 13896 KB Output is correct
11 Incorrect 25 ms 12756 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '278282583884'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 11968 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 6 ms 12044 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 11 ms 12268 KB Output is correct
10 Correct 66 ms 13896 KB Output is correct
11 Incorrect 25 ms 12756 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '278282583884'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 11968 KB Output is correct
5 Correct 7 ms 11988 KB Output is correct
6 Correct 6 ms 12044 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 11 ms 12268 KB Output is correct
10 Correct 66 ms 13896 KB Output is correct
11 Incorrect 25 ms 12756 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '278282583884'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 46352 KB Output is correct
2 Correct 56 ms 46456 KB Output is correct
3 Correct 189 ms 62992 KB Output is correct
4 Correct 166 ms 60352 KB Output is correct
5 Correct 459 ms 81632 KB Output is correct
6 Correct 449 ms 81704 KB Output is correct
7 Correct 444 ms 81568 KB Output is correct
8 Correct 443 ms 81584 KB Output is correct
9 Correct 967 ms 138040 KB Output is correct
10 Incorrect 480 ms 69392 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '36391635198497'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 339 ms 69368 KB Output is correct
2 Correct 396 ms 78876 KB Output is correct
3 Correct 56 ms 46452 KB Output is correct
4 Correct 58 ms 46464 KB Output is correct
5 Execution timed out 1099 ms 169692 KB Time limit exceeded
6 Halted 0 ms 0 KB -