답안 #625741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625741 2022-08-10T17:57:52 Z d4xn 메기 농장 (IOI22_fish) C++17
0 / 100
1000 ms 93052 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) {
        cnt += pre[curr+1][h] - pre[curr+1][h2];
      }

      // ver si pillo los de la izquierda      
      if (curr-1 >= 0) {
        cnt += pre[curr-1][h-1];
      }
      

      // ver si he eliminado alguno de los que he pillado
      cnt -= pre[curr][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) {
        cnt += pre[curr+1][h] - pre[curr+1][h2];
      }

      // ver si pillo los de la izquierda      
      if (curr-1 >= 0) {
        cnt += pre[curr-1][h-1];
      }
      

      // ver si he eliminado alguno de los que he pillado
      cnt -= pre[curr][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]);
  }

  for (int i = 0; i < n; i++) {
    sort(c[i].begin(), c[i].end());

    ll sum = 0;
    for (int &h : c[i]) {
      sum += w[i][h];
      pre[i][h] = sum;
    }
  }

  return mx(n-1, 0, 0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 57156 KB Output is correct
2 Correct 265 ms 64836 KB Output is correct
3 Correct 57 ms 38604 KB Output is correct
4 Correct 54 ms 38572 KB Output is correct
5 Execution timed out 1094 ms 93052 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Execution timed out 1088 ms 53112 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 38604 KB Output is correct
2 Incorrect 59 ms 38612 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Incorrect 6 ms 11988 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Incorrect 6 ms 11988 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 11988 KB Output is correct
3 Incorrect 6 ms 11988 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 38604 KB Output is correct
2 Incorrect 59 ms 38612 KB 1st lines differ - on the 1st token, expected: '882019', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 57156 KB Output is correct
2 Correct 265 ms 64836 KB Output is correct
3 Correct 57 ms 38604 KB Output is correct
4 Correct 54 ms 38572 KB Output is correct
5 Execution timed out 1094 ms 93052 KB Time limit exceeded
6 Halted 0 ms 0 KB -