結果
問題 | No.2375 watasou and hibit's baseball |
ユーザー |
|
提出日時 | 2023-07-08 16:02:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 125 ms / 2,000 ms |
コード長 | 2,804 bytes |
コンパイル時間 | 1,043 ms |
コンパイル使用メモリ | 108,228 KB |
最終ジャッジ日時 | 2025-02-15 09:05:26 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include<iostream>#include<set>#include<algorithm>#include<vector>#include<string>#include<set>#include<map>#include<numeric>#include<queue>#include<cmath>using namespace std;typedef long long ll;const ll INF=1LL<<60;typedef pair<ll,ll> P;typedef pair<int,P> PP;const ll MOD=998244353;const double PI=acos(-1);int main(){int N,A,B;cin>>N>>A>>B;vector<ll> X(N),Y(N),K(N);for(int i=0;i<N;i++){cin>>X[i]>>Y[i]>>K[i];}const int inf=(1<<30);/*dp[S][v][u]=今vにいる.訪れた頂点集合がS vにいる前はuにいた*/vector dp(1<<N,vector<vector<int>>(N,vector<int>(N+1,false)));/*for(int c=0;c<N;c++){for(int u=0;u<N;u++){//スタート地点を決めるdp[0][u][c]=0;}}*/for(int u=0;u<N;u++){//スタート地点を決めるdp[0][u][N]=true;}auto dist=[&](int i,int j){int res=abs(X[i]-X[j])+abs(Y[i]-Y[j]);return res;};for(int S=0;S<(1<<N);S++){//for(int c=0;c<N;c++){for(int c=N;c>=0;c--){for(int u=0;u<N;u++){if(!dp[S][u][c]) continue;//uから出発int cntbit=__builtin_popcount(S);if(cntbit==0){dp[1<<u][u][N]=true;}else if(cntbit==1){//ルール2for(int v=0;v<N;v++){if(u!=v && ((S>>v)&1)==0){if(A<=dist(u,v) || B<=abs(K[u]-K[v])){//dp[S|(1<<v)][v][u]=max(dp[S|(1<<v)][v][u],dp[S][u][N]+1);dp[S|(1<<v)][v][u]=true;}}}}else if(cntbit>=2){//cntbit>=2for(int v=0;v<N;v++){if(u!=v && ((S>>v)&1)==0 ){//今からvにいくif(c<N && (A<=(dist(v,u)+dist(v,c)) || B<=abs(K[v]-K[u])) ){//dp[S|(1<<v)][v][u]=max(dp[S|(1<<v)][v][u],dp[S][u][c]+1);dp[S|(1<<v)][v][u]=true;}}}}}}}int ans=0;for(int S=0;S<(1<<N);S++){for(int c=0;c<=N;c++){for(int u=0;u<N;u++){if(dp[S][u][c]){ans=max(ans,(int)__builtin_popcount(S));}//ans=max(ans,dp[S][u][c]);}}}cout<<ans<<endl;}