結果

問題 No.1955 Not Prime
ユーザー 👑 platinumplatinum
提出日時 2022-04-12 22:34:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 219,900 KB
実行使用メモリ 35,132 KB
最終ジャッジ日時 2023-08-23 07:53:01
合計ジャッジ時間 5,958 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
11,736 KB
testcase_01 AC 16 ms
11,752 KB
testcase_02 AC 17 ms
11,764 KB
testcase_03 AC 17 ms
11,532 KB
testcase_04 AC 16 ms
11,748 KB
testcase_05 AC 16 ms
11,700 KB
testcase_06 AC 23 ms
11,920 KB
testcase_07 AC 129 ms
14,980 KB
testcase_08 AC 110 ms
14,648 KB
testcase_09 AC 196 ms
14,476 KB
testcase_10 AC 171 ms
11,792 KB
testcase_11 AC 154 ms
35,132 KB
testcase_12 AC 65 ms
12,348 KB
testcase_13 AC 200 ms
15,180 KB
testcase_14 AC 43 ms
12,716 KB
testcase_15 AC 41 ms
12,384 KB
testcase_16 AC 82 ms
14,564 KB
testcase_17 AC 149 ms
18,220 KB
testcase_18 AC 204 ms
14,924 KB
testcase_19 AC 182 ms
18,308 KB
testcase_20 AC 17 ms
11,944 KB
testcase_21 AC 68 ms
12,216 KB
testcase_22 AC 17 ms
11,540 KB
testcase_23 AC 17 ms
11,772 KB
testcase_24 AC 16 ms
11,700 KB
testcase_25 AC 16 ms
11,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/twosat>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

using namespace std;
using namespace atcoder;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;

pair<vector<int>, vector<int>> Eratosthenes(const int N){
   vector<int> divisor(N + 1);
   vector<int> res;
   for(int i = 2; i <= N; i++){
	   if(divisor[i] == 0){
		   divisor[i] = 1;
		   res.emplace_back(i);
		   for(int j = 2 * i; j <= N; j += i) divisor[j] = i;
	   }
   }
   return pair<vector<int>, vector<int>>(res, divisor);
}

int main(){
	int N;
	cin >> N;
	vv A(N, vector<int>(2));
	rep(i,N) cin >> A[i][0] >> A[i][1];
	pair<vector<int>,vector<int>> E = Eratosthenes(1000005);
	vector<int> primes(1000010);
	for(auto p : E.first) primes[p]++;
	two_sat ts(N);
	rep(i,N){
		rep(j,N){
			rep(u,2){
				rep(v,2){
					string s1 = to_string(A[i][u]) + to_string(A[j][v^1]);
					string s2 = to_string(A[j][v]) + to_string(A[i][u^1]);
					int a = stoi(s1), b = stoi(s2);
					if(primes[a] or primes[b]) ts.add_clause(i, u, j, v);
				}
			}
		}
	}
	bool ans = ts.satisfiable();
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}
0