結果

問題 No.1955 Not Prime
ユーザー hir355hir355
提出日時 2022-05-20 23:40:50
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 3,623 bytes
コンパイル時間 3,766 ms
コンパイル使用メモリ 261,368 KB
実行使用メモリ 27,300 KB
最終ジャッジ日時 2023-10-20 14:36:52
合計ジャッジ時間 5,206 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,348 KB
testcase_01 AC 10 ms
4,348 KB
testcase_02 AC 10 ms
4,348 KB
testcase_03 AC 11 ms
4,348 KB
testcase_04 AC 11 ms
4,348 KB
testcase_05 AC 11 ms
4,348 KB
testcase_06 AC 12 ms
4,348 KB
testcase_07 AC 29 ms
4,684 KB
testcase_08 AC 26 ms
4,424 KB
testcase_09 AC 36 ms
4,428 KB
testcase_10 AC 32 ms
4,348 KB
testcase_11 AC 63 ms
27,300 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 37 ms
4,684 KB
testcase_14 AC 15 ms
4,348 KB
testcase_15 AC 15 ms
4,348 KB
testcase_16 AC 23 ms
4,424 KB
testcase_17 AC 37 ms
5,988 KB
testcase_18 AC 37 ms
4,684 KB
testcase_19 AC 39 ms
5,476 KB
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 19 ms
4,348 KB
testcase_22 AC 11 ms
4,348 KB
testcase_23 AC 11 ms
4,348 KB
testcase_24 AC 11 ms
4,348 KB
testcase_25 AC 11 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <atcoder/modint>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/segtree>
// #include <atcoder/maxflow>
// #include <atcoder/scc>
// #include <atcoder/mincostflow>
#include <atcoder/twosat>
using namespace atcoder;

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

constexpr long long INF_LL = 2000000000000000000LL;
constexpr int INF = 2000000000;
constexpr long long MOD = 998244353;
// constexpr long long MOD = 1000000007;

const double PI = acos(-1);

#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;

int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};

template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

template <class T>
T gcd(T m, T n) {
    if(n == 0) return m;
    return gcd(n, m % n);
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

typedef vector<vector<edge>> graph;

// using mint = modint998244353;
// // using mint = modint1000000007;
// constexpr int MAX_COM = 1000001;
// mint fac[MAX_COM], ifac[MAX_COM];
// void initfac() {
//     fac[0] = ifac[0] = 1;
//     REP(i, 1, MAX_COM) fac[i] = i * fac[i - 1];
//     REP(i, 1, MAX_COM) ifac[i] = 1 / fac[i];
// }
// mint nCr(int n, int r){
//     if(r < 0 || n < r) return 0;
//     return fac[n] * ifac[n - r] * ifac[r];
// }


// typedef Matrix<double> S;
// S op(S x, S y){ return y * x; }
// S e(){ return Matrix<double>::I(3); }
// typedef int F;
// S mapping(F f, S x){ 
//     return f + x;
// }
// F composition(F f, F g){ 
//     return f + g;
// }
// F id(){ return 0; }

std::vector<bool> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
        }
    }
    return is_prime;
}

void solve(){
    int n;
    cin >> n;
    vi a(n), b(n), c(n * 2);
    auto is_prime = Eratosthenes(1000000);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n) {
        c[i] = a[i];
        c[i + n] = b[i];
    }
    two_sat ts(n * 2);
    rep(i, n){
        ts.add_clause(i, 1, i + n, 1);
        ts.add_clause(i, 0, i + n, 0);
    }
    rep(i, n * 2){
        rep(j, n * 2){
            int t = 100000, x = c[i], y = c[j];
            while(t > c[j]){
                t /= 10;
            }
            while(t > 0){
                x *= 10;
                x += y / t;
                y %= t;
                t /= 10;
            }
            if(is_prime[x]){
                ts.add_clause(i, 1, j, 0);
            }
        }
    }
    if(ts.satisfiable()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

int main(){
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);
    // initfac();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
0