結果

問題 No.3211 NAND Oracle
ユーザー D M
提出日時 2025-09-17 17:18:11
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 2,910 ms
コンパイル使用メモリ 276,268 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-17 17:18:19
合計ジャッジ時間 7,170 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long Q, K;
    if (!(cin >> Q >> K)) return 0;

    auto need = [&](){
        if (Q <= 1) return 2LL;
        if (Q <= 3) return 3LL;
        if (Q <= 5) return 4LL;
        return 5LL; // Q >= 6
    }();

    if (K < need) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    if (Q <= 5) {
        // 最適: (1,2) を ceil((Q+1)/2) 回 → 残りは (3,4)
        long long x = (Q + 2) / 2;      // ceil((Q+1)/2)
        long long y = Q - x;
        for (long long t = 0; t < x; ++t) cout << 1 << ' ' << 2 << '\n';
        for (long long t = 0; t < y; ++t) cout << 3 << ' ' << 4 << '\n';
    } else {
        // あなたの構成: Q>=6 で上限5に固定
        cout << 1 << ' ' << 2 << '\n';  // A3 = A1 NAND A2
        cout << 2 << ' ' << 3 << '\n';  // A4 = A2 NAND A3
        cout << 1 << ' ' << 4 << '\n';  // A5 = A1 NAND A4 → ここで必ず A1 != A5
        cout << 1 << ' ' << 5 << '\n';  // A6 = 1
        cout << 1 << ' ' << 5 << '\n';  // A7 = 1
        for (long long t = 6; t <= Q; ++t) cout << 6 << ' ' << 7 << '\n'; // 以降ずっと 0
    }
    return 0;
}
0