提出 #51308848


ソースコード 拡げる

#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, h, w;
    cin >> n >> h >> w;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    vector<int> order(n);
    iota(order.begin(), order.end(), 0);

    int good = 0;
    vector<vector<int>> blocked(h, vector<int>(w, 0));
    do {
        for(int flipped_mask = 0; flipped_mask < (1ll << n); flipped_mask++) {
            for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                    blocked[i][j] = 0;
                }
            }
            int cur_good = 1, at = 0;
            for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                    if(!blocked[i][j]) {
                        if(at >= n) {
                            cur_good = 0;
                            continue;
                        }
                        int height = a[order[at]], width = b[order[at]];
                        if(flipped_mask & (1ll << at)) {
                            swap(height, width);
                        }
                        if(i + height > h || j + width > w) {
                            cur_good = 0;
                            continue;
                        }
                        for(int x = 0; x < height; x++) {
                            for(int y = 0; y < width; y++) {
                                if(blocked[i + x][j + y]) {
                                    cur_good = 0;
                                }
                                blocked[i + x][j + y] = 1;
                            }
                        }
                        at++;
                    }
                }
            }
            if(cur_good) {
                good = 1;
            }
        }
    } while(next_permutation(order.begin(), order.end()));

    if(good) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

提出情報

提出日時
問題 D - Tiling
ユーザ ExplodingFreeze
言語 C++ 20 (gcc 12.2)
得点 450
コード長 2149 Byte
結果 AC
実行時間 190 ms
メモリ 3608 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 4
AC × 82
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt, example_03.txt
All example_00.txt, example_01.txt, example_02.txt, example_03.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, hand_24.txt, hand_25.txt, hand_26.txt, hand_27.txt, hand_28.txt, hand_29.txt, hand_30.txt, hand_31.txt, hand_32.txt, hand_33.txt, hand_34.txt, hand_35.txt, random2_00.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 2 ms 3520 KiB
example_01.txt AC 1 ms 3416 KiB
example_02.txt AC 1 ms 3324 KiB
example_03.txt AC 1 ms 3396 KiB
hand_00.txt AC 4 ms 3332 KiB
hand_01.txt AC 149 ms 3464 KiB
hand_02.txt AC 4 ms 3600 KiB
hand_03.txt AC 1 ms 3468 KiB
hand_04.txt AC 1 ms 3528 KiB
hand_05.txt AC 159 ms 3380 KiB
hand_06.txt AC 63 ms 3600 KiB
hand_07.txt AC 182 ms 3416 KiB
hand_08.txt AC 66 ms 3440 KiB
hand_09.txt AC 162 ms 3440 KiB
hand_10.txt AC 114 ms 3464 KiB
hand_11.txt AC 36 ms 3472 KiB
hand_12.txt AC 38 ms 3520 KiB
hand_13.txt AC 46 ms 3480 KiB
hand_14.txt AC 67 ms 3416 KiB
hand_15.txt AC 155 ms 3396 KiB
hand_16.txt AC 168 ms 3380 KiB
hand_17.txt AC 167 ms 3456 KiB
hand_18.txt AC 114 ms 3456 KiB
hand_19.txt AC 114 ms 3604 KiB
hand_20.txt AC 127 ms 3480 KiB
hand_21.txt AC 127 ms 3320 KiB
hand_22.txt AC 66 ms 3444 KiB
hand_23.txt AC 64 ms 3524 KiB
hand_24.txt AC 114 ms 3440 KiB
hand_25.txt AC 114 ms 3448 KiB
hand_26.txt AC 150 ms 3468 KiB
hand_27.txt AC 149 ms 3388 KiB
hand_28.txt AC 149 ms 3464 KiB
hand_29.txt AC 81 ms 3400 KiB
hand_30.txt AC 116 ms 3476 KiB
hand_31.txt AC 115 ms 3484 KiB
hand_32.txt AC 111 ms 3396 KiB
hand_33.txt AC 112 ms 3532 KiB
hand_34.txt AC 125 ms 3516 KiB
hand_35.txt AC 163 ms 3368 KiB
random2_00.txt AC 1 ms 3416 KiB
random2_01.txt AC 1 ms 3320 KiB
random2_02.txt AC 12 ms 3468 KiB
random2_03.txt AC 4 ms 3396 KiB
random2_04.txt AC 1 ms 3448 KiB
random2_05.txt AC 62 ms 3608 KiB
random_00.txt AC 1 ms 3416 KiB
random_01.txt AC 1 ms 3520 KiB
random_02.txt AC 8 ms 3532 KiB
random_03.txt AC 1 ms 3456 KiB
random_04.txt AC 1 ms 3380 KiB
random_05.txt AC 1 ms 3460 KiB
random_06.txt AC 2 ms 3428 KiB
random_07.txt AC 5 ms 3416 KiB
random_08.txt AC 23 ms 3456 KiB
random_09.txt AC 48 ms 3472 KiB
random_10.txt AC 1 ms 3452 KiB
random_11.txt AC 7 ms 3388 KiB
random_12.txt AC 1 ms 3388 KiB
random_13.txt AC 33 ms 3396 KiB
random_14.txt AC 85 ms 3464 KiB
random_15.txt AC 20 ms 3384 KiB
random_16.txt AC 1 ms 3480 KiB
random_17.txt AC 1 ms 3524 KiB
random_18.txt AC 1 ms 3488 KiB
random_19.txt AC 23 ms 3484 KiB
random_20.txt AC 82 ms 3476 KiB
random_21.txt AC 124 ms 3396 KiB
random_22.txt AC 7 ms 3520 KiB
random_23.txt AC 51 ms 3428 KiB
random_24.txt AC 190 ms 3472 KiB
random_25.txt AC 2 ms 3452 KiB
random_26.txt AC 10 ms 3460 KiB
random_27.txt AC 145 ms 3464 KiB
random_28.txt AC 105 ms 3416 KiB
random_29.txt AC 151 ms 3488 KiB
random_30.txt AC 154 ms 3328 KiB
random_31.txt AC 133 ms 3472 KiB
random_32.txt AC 147 ms 3444 KiB
random_33.txt AC 13 ms 3524 KiB
random_34.txt AC 150 ms 3428 KiB
random_35.txt AC 119 ms 3428 KiB