結果

問題 No.2375 watasou and hibit's baseball
ユーザー t98slidert98slider
提出日時 2023-07-07 22:12:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,918 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 180,376 KB
実行使用メモリ 20,140 KB
最終ジャッジ日時 2023-09-28 23:33:29
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 23 ms
10,916 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 94 ms
19,884 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 9 ms
6,676 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 40 ms
19,888 KB
testcase_13 AC 17 ms
10,940 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 8 ms
5,016 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 37 ms
19,932 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 38 ms
20,140 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 37 ms
19,952 KB
testcase_24 AC 37 ms
19,912 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 48 ms
19,888 KB
testcase_27 AC 52 ms
20,008 KB
testcase_28 AC 54 ms
19,880 KB
testcase_29 AC 58 ms
20,136 KB
testcase_30 AC 64 ms
19,884 KB
testcase_31 AC 58 ms
19,948 KB
testcase_32 AC 65 ms
19,916 KB
testcase_33 AC 54 ms
19,984 KB
testcase_34 AC 49 ms
19,940 KB
testcase_35 AC 63 ms
19,928 KB
testcase_36 AC 60 ms
19,884 KB
testcase_37 AC 49 ms
19,932 KB
testcase_38 AC 37 ms
19,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, A, B;
    cin >> n >> A >> B;
    vector<tuple<int,int,int>> a(n);
    for(int i = 0; i < n; i++){
        int x, y, k;
        cin >> x >> y >> k;
        a[i] = make_tuple(x, y, k);
    }

    vector<vector<vector<bool>>> dp(1 << n, vector<vector<bool>>(n, vector<bool>(n)));
    for(int i = 0; i < n; i++) dp[1 << i][i][0] = true;
    
    auto f = [&](int i, int j, int k){
        int x1, y1, k1;
        int x2, y2, k2;
        int x3, y3, k3;
        tie(x1, y1, k1) = a[i];
        tie(x2, y2, k2) = a[j];
        tie(x3, y3, k3) = a[k];
        if(abs(k1 - k2) >= B) return true;
        if(abs(x1 - x2) + abs(y1 - y2) + abs(x1 - x3) + abs(y1 - y3) >= A) return true;
        return false;
    };

    int ans = 1;
    for(int i = 1; i < (1 << n); i++){
        int b = __builtin_popcount(i);
        if(b == 1){
            for(int j = 0; j < n; j++){
                if(!dp[i][j][0]) continue;
                int x1, y1, k1;
                tie(x1, y1, k1) = a[j];
                for(int k = 0; k < n; k++){
                    int x2, y2, k2;
                    tie(x2, y2, k2) = a[k];
                    if(i == j) continue;
                    if((A <= abs(x1 - x2) + abs(y1 - y2)) || (B <= abs(k1 - k2))) dp[i | (1 << k)][k][j] = true;
                }
            }
        }else{
            for(int j = 0; j < n; j++){
                if(~i >> j & 1) continue;
                for(int k = 0; k < n; k++){
                    if(!dp[i][j][k]) continue;
                    ans = max(ans, b);
                    for(int l = 0; l < n; l++){
                        if(i >> l & 1) continue;
                        if(f(l, j, k)) dp[i | (1 << l)][l][j] = true;
                    }
                }
            }
        }
    }
    cout << ans << '\n';
}
0