結果
問題 | No.1955 Not Prime |
ユーザー | hiro71687k |
提出日時 | 2023-04-12 13:10:39 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 296 ms / 2,000 ms |
コード長 | 4,358 bytes |
コンパイル時間 | 6,566 ms |
コンパイル使用メモリ | 272,748 KB |
実行使用メモリ | 42,712 KB |
最終ジャッジ日時 | 2024-04-17 02:17:27 |
合計ジャッジ時間 | 14,233 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 163 ms
18,944 KB |
testcase_01 | AC | 176 ms
19,072 KB |
testcase_02 | AC | 176 ms
19,072 KB |
testcase_03 | AC | 169 ms
19,200 KB |
testcase_04 | AC | 167 ms
19,072 KB |
testcase_05 | AC | 161 ms
19,200 KB |
testcase_06 | AC | 177 ms
19,200 KB |
testcase_07 | AC | 225 ms
20,192 KB |
testcase_08 | AC | 215 ms
20,320 KB |
testcase_09 | AC | 258 ms
20,316 KB |
testcase_10 | AC | 263 ms
19,200 KB |
testcase_11 | AC | 296 ms
42,712 KB |
testcase_12 | AC | 198 ms
19,456 KB |
testcase_13 | AC | 255 ms
20,444 KB |
testcase_14 | AC | 187 ms
19,840 KB |
testcase_15 | AC | 187 ms
19,712 KB |
testcase_16 | AC | 217 ms
20,312 KB |
testcase_17 | AC | 256 ms
21,852 KB |
testcase_18 | AC | 257 ms
20,448 KB |
testcase_19 | AC | 252 ms
21,340 KB |
testcase_20 | AC | 182 ms
19,072 KB |
testcase_21 | AC | 194 ms
19,584 KB |
testcase_22 | AC | 166 ms
19,072 KB |
testcase_23 | AC | 171 ms
19,072 KB |
testcase_24 | AC | 175 ms
19,072 KB |
testcase_25 | AC | 168 ms
19,072 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=1444999999999999; ll mod=998244353; struct Eratosthenes { // テーブル vector<bool> isprime; // 整数 i を割り切る最小の素数 vector<ll> minfactor; vector<ll>mobius; // コンストラクタで篩を回す Eratosthenes(ll N) : isprime(N+1, true), minfactor(N+1, -1), mobius(N+1,1) { // 1 は予めふるい落としておく isprime[1] = false; minfactor[1] = 1; // 篩 for (ll p = 2; p <= N; ++p) { // すでに合成数であるものはスキップする if (!isprime[p]) continue; // p についての情報更新 minfactor[p] = p; mobius[p]=-1; // p 以外の p の倍数から素数ラベルを剥奪 for (ll q = p * 2; q <= N; q += p) { // q は合成数なのでふるい落とす isprime[q] = false; // q は p で割り切れる旨を更新 if (minfactor[q] == -1) minfactor[q] = p; if ((q / p) % p == 0) mobius[q] = 0; else mobius[q] = -mobius[q]; } } } // 高速素因数分解 // pair (素因子, 指数) の vector を返す vector<pair<ll,ll>> factorize(ll n) { vector<pair<ll,ll>> res; while (n > 1) { ll p = minfactor[n]; ll exp = 0; // n で割り切れる限り割る while (minfactor[n] == p) { n /= p; ++exp; } res.emplace_back(p, exp); } return res; } vector<ll>divisors(ll n){ vector<ll>res({1}); auto pf=factorize(n); for (auto p : pf) { ll s=(ll)res.size(); for (ll i = 0; i < s; i++) { ll v=1; for (ll j = 0; j < p.second; j++) { v*=p.first; res.push_back(res[i]*v); } } } return res; } }; int main(){ ll n; cin >> n; vector<ll>a(n),b(n); for (ll i = 0; i < n; i++) { cin >> a[i] >> b[i]; } scc_graph g(n*2); Eratosthenes er(1000000); for (ll i = 0; i < n; i++) { string s=to_string(a[i]),t=to_string(b[i]); s+=t; ll x=stoll(s); if (er.isprime[x]) { g.add_edge(i*2,i*2+1); } s=to_string(b[i]),t=to_string(a[i]); s+=t; x=stoll(s); if (er.isprime[x]) { g.add_edge(i*2+1,i*2); } } for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { if (i==j) { continue; } string s=to_string(a[i]),t=to_string(b[j]); s+=t; ll x=stoll(s); if (er.isprime[x]) { g.add_edge(i*2,j*2+1); g.add_edge(j*2,i*2+1); } s=to_string(a[i]),t=to_string(a[j]); s+=t; x=stoll(s); if (er.isprime[x]) { g.add_edge(i*2,j*2); g.add_edge(j*2+1,i*2+1); } s=to_string(b[i]),t=to_string(b[j]); s+=t; x=stoll(s); if (er.isprime[x]) { g.add_edge(i*2+1,j*2+1); g.add_edge(j*2,i*2); } s=to_string(b[i]),t=to_string(a[j]); s+=t; x=stoll(s); if (er.isprime[x]) { g.add_edge(i*2+1,j*2); g.add_edge(j*2+1,i*2); } } } vector<vector<int>>x=g.scc(); for (ll i = 0; i < x.size(); i++) { sort(x[i].begin(),x[i].end()); for (ll j = 1; j <x[i].size(); j++) { if (x[i][j]-x[i][j-1]==1&&x[i][j-1]%2==0) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; }