Submission #1037443

# Submission time Handle Problem Language Result Execution time Memory
1037443 2024-07-28T22:03:46 Z HappyCapybara Catfish Farm (IOI22_fish) C++17
0 / 100
1000 ms 34684 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int n;
vector<vector<int>> v;
unordered_map<ll,ll> m, dp;

ll solve(int c, int prev){
  if (c == n) return 0;
  if (dp.find((ll)c*100001+prev) !=dp.end()) return dp[(ll)c*100001+prev];
  ll cur = 0, res = 0;
  int l = 0, r = 0;
  while (r != v[c].size()){
    res = max(res, cur+solve(c+1, r));
    while (c != 0 && l < prev && v[c-1][l+1] <= v[c][r+1]){
      l++;
      res -= m[(ll) c*100001 + (ll) v[c-1][l]];
    }
    r++;
    if (c < n-1) res += m[(ll) (c+1)*100001 + (ll) v[c][r]];
    if (c > 0 && v[c-1][prev] < v[c][r]) res += m[(ll) (c-1)*100001 + (ll) v[c][r]];
  }
  //cout << c << " " << prev << " " << res << "\n";
  return res;
}

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
  n = N;
  v.resize(N, {-1});
  for (int i=0; i<M; i++){
    m[(ll)X[i]*100001+(ll)Y[i]] = W[i];
    if (X[i] > 0) v[X[i]-1].push_back(Y[i]);
    if (X[i] < N-1) v[X[i]+1].push_back(Y[i]);
  }
  for (int i=0; i<N; i++) sort(v[i].begin(), v[i].end());

  return solve(0, 0)/2;
}

Compilation message

fish.cpp: In function 'long long int solve(int, int)':
fish.cpp:16:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   while (r != v[c].size()){
      |          ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 28352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1096 ms 34684 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 26216 KB Output is correct
2 Correct 21 ms 26216 KB Output is correct
3 Execution timed out 1101 ms 23104 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '5050', found: '6565'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '5050', found: '6565'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '5050', found: '6565'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 26216 KB Output is correct
2 Correct 21 ms 26216 KB Output is correct
3 Execution timed out 1101 ms 23104 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 28352 KB Time limit exceeded
2 Halted 0 ms 0 KB -