結果

問題 No.1955 Not Prime
ユーザー karinohitokarinohito
提出日時 2022-05-21 01:24:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,935 bytes
コンパイル時間 5,027 ms
コンパイル使用メモリ 268,312 KB
実行使用メモリ 67,360 KB
最終ジャッジ日時 2023-10-20 15:26:07
合計ジャッジ時間 8,070 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
18,764 KB
testcase_01 AC 44 ms
18,764 KB
testcase_02 AC 49 ms
18,764 KB
testcase_03 AC 50 ms
18,764 KB
testcase_04 AC 49 ms
18,764 KB
testcase_05 AC 51 ms
18,764 KB
testcase_06 AC 50 ms
19,248 KB
testcase_07 AC 72 ms
21,264 KB
testcase_08 AC 67 ms
21,016 KB
testcase_09 AC 74 ms
21,016 KB
testcase_10 AC 73 ms
18,764 KB
testcase_11 AC 138 ms
67,360 KB
testcase_12 AC 62 ms
19,704 KB
testcase_13 AC 87 ms
21,528 KB
testcase_14 AC 58 ms
19,964 KB
testcase_15 AC 56 ms
19,964 KB
testcase_16 AC 66 ms
21,016 KB
testcase_17 AC 80 ms
24,892 KB
testcase_18 AC 82 ms
21,528 KB
testcase_19 AC 79 ms
24,892 KB
testcase_20 AC 55 ms
18,764 KB
testcase_21 AC 62 ms
19,704 KB
testcase_22 AC 83 ms
18,764 KB
testcase_23 AC 52 ms
18,764 KB
testcase_24 AC 57 ms
18,764 KB
testcase_25 AC 56 ms
18,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)


bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll PM(ll P, ll Q) {
    if (Q == 0)return P * 10;
    ll k = 1;
    ll V = Q;
    while (V > 0) {
        V /= 10;
        k *= 10;
    }
    return P * k + Q;
}


int main() {
    ll M = 2e6;
    vll P(M);
    rep(i, M)P[i] = i;
    P[0] = P[1] = -1;
    rep(i, M) {
        if (P[i] == i)for (ll j = i; j < M; j += i)P[j] = i;
    }
    ll N;
    cin >> N;
    two_sat sa(N);
    vll A(N),B(N);
    rep(i, N)cin >> A[i]>>B[i];
    rep(i, N)rep(j, N) {
        //1:Ahidari 
        ll q = PM(A[i], A[j]);
        if (P[q]==q) {
            sa.add_clause(i, 0, j, 1);
        }
        q = PM(A[i], B[j]);
        if (P[q] == q) {
            sa.add_clause(i, 0, j, 0);
        }
        q = PM(B[i], A[j]);
        if (P[q] == q) {
            sa.add_clause(i, 1, j, 1);
        }
        q = PM(B[i], B[j]);
        if (P[q] == q) {
            sa.add_clause(i, 1, j, 0);
        }

        q = PM(A[j], A[i]);
        if (P[q] == q) {
            sa.add_clause(j, 0, i, 1);
        }
        q = PM(A[j], B[i]);
        if (P[q] == q) {
            sa.add_clause(j, 0, i, 0);
        }
        q = PM(B[j], A[i]);
        if (P[q] == q) {
            sa.add_clause(j, 1, i, 1);
        }
        q = PM(B[j], B[i]);
        if (P[q] == q) {
            sa.add_clause(j, 1, i, 0);
        }
    }

    if (sa.satisfiable()) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }


}
0