結果

問題 No.1955 Not Prime
コンテスト
ユーザー 👑 tttmmmyyyy
提出日時 2026-10-31 00:16:13
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 54 ms / 2,000 ms
+ 235µs
コード長 1,845 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,208 ms
コンパイル使用メモリ 128,664 KB
実行使用メモリ 27,176 KB
最終ジャッジ日時 2026-10-31 00:16:18
合計ジャッジ時間 4,409 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <string>
#include <vector>
#include <atcoder/twosat>

using namespace std;
using namespace atcoder;
using ll = long long;

static vector<bool> pt;

static bool hate(ll a, ll b) {
    ll x = stoll(to_string(a) + to_string(b));
    return pt[x];
}

int main() {
    const int m = 1000000;
    pt.assign(m, true);
    pt[0] = pt[1] = false;
    for (ll p = 2; p * p < m; p++) {
        if (pt[p]) {
            for (ll q = p * p; q < m; q += p) {
                pt[q] = false;
            }
        }
    }

    int n;
    scanf("%d", &n);
    vector<ll> as(n), bs(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld", &as[i], &bs[i]);
    }
    two_sat ts(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (!hate(as[i], bs[j])) {
                continue;
            }
            if (i == j) {
                ts.add_clause(i, false, i, false);
                continue;
            }
            ts.add_clause(i, false, j, false);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (!hate(bs[j], as[i])) {
                continue;
            }
            if (i == j) {
                ts.add_clause(i, true, i, true);
                continue;
            }
            ts.add_clause(i, true, j, true);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j || !hate(as[i], as[j])) {
                continue;
            }
            ts.add_clause(i, false, j, true);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j || !hate(bs[i], bs[j])) {
                continue;
            }
            ts.add_clause(i, true, j, false);
        }
    }
    puts(ts.satisfiable() ? "Yes" : "No");
}
0