結果

問題 No.2375 watasou and hibit's baseball
ユーザー HIcoderHIcoder
提出日時 2023-07-08 16:03:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 2,541 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 110,484 KB
実行使用メモリ 27,336 KB
最終ジャッジ日時 2023-09-29 17:25:58
合計ジャッジ時間 3,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 23 ms
12,568 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 115 ms
27,088 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 9 ms
7,744 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 40 ms
27,308 KB
testcase_13 AC 17 ms
12,564 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 8 ms
5,388 KB
testcase_16 AC 5 ms
4,460 KB
testcase_17 AC 37 ms
27,336 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,456 KB
testcase_21 AC 38 ms
27,044 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 36 ms
27,000 KB
testcase_24 AC 37 ms
27,152 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 49 ms
27,052 KB
testcase_27 AC 55 ms
27,052 KB
testcase_28 AC 58 ms
27,012 KB
testcase_29 AC 62 ms
27,000 KB
testcase_30 AC 66 ms
27,040 KB
testcase_31 AC 62 ms
27,004 KB
testcase_32 AC 71 ms
27,304 KB
testcase_33 AC 55 ms
27,092 KB
testcase_34 AC 50 ms
26,992 KB
testcase_35 AC 70 ms
27,084 KB
testcase_36 AC 63 ms
27,100 KB
testcase_37 AC 50 ms
27,040 KB
testcase_38 AC 35 ms
26,996 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,-inf)));
    /*
    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]=0;
        }
    

    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]==-inf) continue;

          
                //uから出発
                int cntbit=__builtin_popcount(S);
                if(cntbit==0){
                    dp[1<<u][u][N]=1;

                }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);
                            }

                        }
                    }

                }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);
                            }

                        }
                    }

                }



            }
        }

        
    }


    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;

}
0