結果

問題 No.2375 watasou and hibit's baseball
ユーザー HIcoderHIcoder
提出日時 2023-07-08 16:02:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 2,804 bytes
コンパイル時間 1,132 ms
コンパイル使用メモリ 109,724 KB
実行使用メモリ 27,352 KB
最終ジャッジ日時 2023-09-29 17:24:39
合計ジャッジ時間 4,080 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 25 ms
12,640 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 126 ms
26,972 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 9 ms
7,700 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 43 ms
26,980 KB
testcase_13 AC 18 ms
12,660 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 9 ms
5,392 KB
testcase_16 AC 6 ms
4,580 KB
testcase_17 AC 40 ms
27,072 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 3 ms
4,464 KB
testcase_21 AC 40 ms
27,068 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 39 ms
27,000 KB
testcase_24 AC 39 ms
27,088 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 54 ms
27,352 KB
testcase_27 AC 60 ms
26,980 KB
testcase_28 AC 64 ms
27,088 KB
testcase_29 AC 69 ms
27,016 KB
testcase_30 AC 73 ms
27,004 KB
testcase_31 AC 69 ms
26,972 KB
testcase_32 AC 77 ms
27,112 KB
testcase_33 AC 63 ms
27,112 KB
testcase_34 AC 57 ms
27,148 KB
testcase_35 AC 76 ms
27,064 KB
testcase_36 AC 70 ms
27,008 KB
testcase_37 AC 57 ms
27,016 KB
testcase_38 AC 40 ms
27,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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){
                    //ルール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][N]+1);
                                dp[S|(1<<v)][v][u]=true;
                            }

                        }
                    }

                }else if(cntbit>=2){
                    //cntbit>=2

                    for(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;

}
0