結果
問題 | No.2375 watasou and hibit's baseball |
ユーザー |
|
提出日時 | 2023-07-07 23:30:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 3,991 bytes |
コンパイル時間 | 3,691 ms |
コンパイル使用メモリ | 254,868 KB |
最終ジャッジ日時 | 2025-02-15 08:38:46 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;// inputtemplate<class T>istream &operator>>(istream &is, vector<T> &v){for(T &in : v) is >> in;return is;}template<class T, class S>istream &operator>>(istream &is, pair<T, S> &p){is >> p.first >> p.second;return is;}template<class... T> void input(T&... a) {(cin >> ... >> a);}//outputtemplate<class T>ostream & operator<<(ostream &os, const vector<T> &v){for(int i = 0; i < (int)v.size(); i++) os << (i == 0 ? "" : " ") << v[i];return os;}template<class T, class S>ostream &operator<<(ostream &os, const pair<T, S> &p){os << p.first << " " << p.second;return os;}template<class T, class S>ostream &operator<<(ostream &os, const map<T, S> &mp){for(auto &[key, val] : mp) os << key << ":" << val << " ";return os;}template<class T>ostream &operator<<(ostream &os, const set<T> &st){for(auto itr = st.begin(); itr != st.end(); itr++) os << (itr == st.begin() ? "" : " ") << *itr;return os;}template<class T>ostream &operator<<(ostream &os, const multiset<T> &st){for(auto itr = st.begin(); itr != st.end(); itr++) os << (itr == st.begin() ? "" : " ") << *itr;return os;}template<class T>ostream &operator<<(ostream &os, queue<T> que){while(!que.empty()) {os << que.front(); que.pop();if(!que.empty()) os << " ";}return os;}template<class T>ostream &operator<<(ostream &os, stack<T> st){while(!st.empty()) {os << st.top(); st.pop();if(!st.empty()) os << " ";}return os;}template <class T, class Container, class Compare>ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq){while (!pq.empty()){os << pq.top(); pq.pop();if(!pq.empty()) os << " ";}return os;}void print() {cout << "\n";}template<class T> void print(const T& a) {cout << a << '\n';}template<class T, class... Ts> void print(const T& a, const Ts&... b) {cout << a; (..., (cout << ' ' << b)); cout << '\n';}#define debug(var) cout << #var << " = ";print(var);typedef long long lint;#define _overload3(_1,_2,_3,name,...) name#define _rep(i,n) repi(i,0,n)#define repi(i,a,b) for(int i=int(a);i<int(b);++i)#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)#define _overload3(_1,_2,_3,name,...) name#define _rrep(i,n) rrepi(i,n,0)#define rrepi(i,a,b) for(int i=int(a-1);i>=int(b);--i)#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep)(__VA_ARGS__)#define all(x) (x).begin(),(x).end()template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }int dist(int x, int y, int u, int v){return abs(x - u) + abs(y - v);}int main() {int N, A, B; input(N, A, B);vector<int> X(N), Y(N), K(N);rep(i, N) input(X[i], Y[i], K[i]);vector<vector<vector<int>>> dp(1<<N, vector<vector<int>>(N+1, vector<int>(N+1, -1)));dp[(1<<N)-1][N][N] = 1;rrep(S, (1<<N)){rep(i, N+1){rep(j, N+1){if(dp[S][i][j] == -1) continue;rep(k, N){if(((S >> k) & 1) == 0) continue;int pcnt = __builtin_popcount(S);if(S == (1<<N)-1) dp[S & ~(1<<k)][k][i] = 1;else if(pcnt == N-1 && A <= dist(X[k], Y[k], X[i], Y[i])) dp[S & ~(1<<k)][k][i] = 1;else if(pcnt <= N-1 && B <= abs(K[k] - K[i])) dp[S & ~(1<<k)][k][i] = 1;else if(pcnt <= N-2 && A <= dist(X[k], Y[k], X[i], Y[i]) + dist(X[k], Y[k], X[j], Y[j])) dp[S & ~(1<<k)][k][i] = 1;}}}}int ans = 1;rep(i, 1<<N) {rep(j, N+1){rep(k, N+1){if(dp[i][j][k] == 1) chmax(ans, N - __builtin_popcount(i));}}}print(ans);}