結果

問題 No.1955 Not Prime
コンテスト
ユーザー 👑 tttmmmyyyy
提出日時 2026-10-31 08:18:01
言語 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  
実行時間 29 ms / 2,000 ms
+ 843µs
コード長 2,468 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,004 ms
コンパイル使用メモリ 126,364 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2026-10-31 08:18:08
合計ジャッジ時間 2,643 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

static inline ll fast_read() {
    int c = getchar_unlocked();
    while (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\v' || c == '\f') {
        c = getchar_unlocked();
    }
    bool negative = false;
    if (c == '-' || c == '+') {
        negative = c == '-';
        c = getchar_unlocked();
    }
    ull value = 0;
    while ('0' <= c && c <= '9') {
        value = value * 10 + (ull)(c - '0');
        c = getchar_unlocked();
    }
    if (c != EOF) {
        ungetc(c, stdin);
    }
    return negative ? -(ll)value : (ll)value;
}

static bitset<1000000> pt;

static bool hate(ll a, ll b) {
    ll p = b < 10 ? 10 : b < 100 ? 100 : 1000;
    return pt[a * p + b];
}

int main() {
    const int m = 1000000;
    pt.set();
    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;
    n = (int)fast_read();
    vector<ll> as(n), bs(n);
    for (int i = 0; i < n; i++) {
        as[i] = fast_read();
        bs[i] = fast_read();
    }
    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