結果
| 問題 | No.2375 watasou and hibit's baseball | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-07-08 16:05:25 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 106 ms / 2,000 ms | 
| コード長 | 2,385 bytes | 
| コンパイル時間 | 994 ms | 
| コンパイル使用メモリ | 108,284 KB | 
| 最終ジャッジ日時 | 2025-02-15 09:05:39 | 
| ジャッジサーバーID (参考情報) | judge3 / 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,-inf)));
     
    for(int c=0;c<N;c++){
        for(int u=0;u<N;u++){
            //ルール1
            //スタート地点を決める
            dp[1<<u][u][c]=1;
            
        }
    }
    auto dist=[&](int i,int j){
        ll 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 u=0;u<N;u++){
            
            if(dp[S][u][c]==-inf) continue;
            if((S>>u)&1){//Sにuのビットが立っている
                //uから出発
                int cntbit=__builtin_popcount(S);
                if(cntbit==1){
                    //ルール2
                    for(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][c]+1);
                            }
                        }
                    }
                }else if(cntbit>=2){
                    //cntbit>=2
                    for(int v=0;v<N;v++){
                        if(u!=v && ((S>>v)&1)==0 ){
                            //今からvにいく
                            if(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);
                            }
                        }
                    }
                }
            }
        }
        }
    }
    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++){
                ans=max(ans,dp[S][u][c]);
            }
        }
    }
    cout<<ans<<endl;
}
            
            
            
        