結果

問題 No.2375 watasou and hibit's baseball
ユーザー as277575
提出日時 2023-07-07 23:29:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,449 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 136,588 KB
最終ジャッジ日時 2025-02-15 08:38:29
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 TLE * 1 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bit>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <set>
#include <string>

using namespace::std;

template<typename T, typename U>
ostream& operator<< (ostream& o, const pair<T, U>& p) {
  o << "<" << p.first << ", " << p.second << ">";
  return o;
}

template <typename T>
ostream& operator<< (ostream& o, const vector<T>& v) {
 for (const auto& x : v) o << x << " ";
 return o;
}

template <typename T>
ostream& operator<< (ostream& o, const set<T>& v) {
 for (const auto& x : v) o << x << " ";
 return o;
}

template <typename T>
ostream& operator<< (ostream& o, const deque<T>& v) {
 for (const auto& x : v) o << x << " ";
 return o;
}

template <typename K, typename V>
ostream& operator<<(ostream& o, const unordered_map<K, V>& m) {
  o << "{";
  for (const auto& [k, v] : m)
    o << " " << k << ": " << v << ",";
  o << "}";
  return o;
}

template <typename T>
istream& operator>> (istream& i, vector<T>& v) {
  for (auto& x : v) i >> x;
  return i;
}

int main() {
  ios::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> x(n), y(n), k(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> k[i];
  
  using State = pair<set<int>, deque<int>>;
  set<State> vis {};
  vector<State> q {{{}, {}}};
  while (q.size()) {
    State u = q.back();
    q.pop_back();
    if (vis.count(u)) continue;
    vis.insert(u);
    //cerr << "New State " << u << endl;
    for (int i = 0; i < n; ++i) {
      //cerr << "i " << i << endl;
      if (!u.first.count(i) && (
        u.first.size() == 0 ||
        (u.first.size() == 1 && a <= abs(x[i] - x[u.second.back()]) + abs(y[i] - y[u.second.back()]))
        || (u.first.size() >= 1 && b <= abs(k[i] - k[u.second.back()]))
        || (u.first.size() >= 2
          && a <= abs(x[i] - x[u.second.back()]) + abs(y[i] - y[u.second.back()]) +
            abs(x[i] - x[u.second[0]]) + abs(y[i] - y[u.second[0]])))) {
        
          State v = u;
          v.first.insert(i);
          if (v.second.size() > 2)
          v.second.pop_front();
          v.second.push_back(i);
          q.push_back(v);
            
        }
        
      }
        
  }
  unsigned long r = 0;
  for (const State& s : vis)
    r = max(r, s.first.size());
  cout << r << endl;
  return 0;
}

0