結果

問題 No.1955 Not Prime
ユーザー 👑 platinumplatinum
提出日時 2022-04-12 21:25:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 3,332 ms
コンパイル使用メモリ 222,508 KB
実行使用メモリ 34,820 KB
最終ジャッジ日時 2023-08-23 07:00:25
合計ジャッジ時間 6,370 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
11,556 KB
testcase_01 AC 15 ms
11,544 KB
testcase_02 AC 16 ms
11,752 KB
testcase_03 AC 15 ms
11,600 KB
testcase_04 AC 16 ms
11,748 KB
testcase_05 AC 15 ms
11,548 KB
testcase_06 AC 21 ms
11,556 KB
testcase_07 AC 117 ms
15,128 KB
testcase_08 AC 106 ms
14,632 KB
testcase_09 AC 191 ms
14,324 KB
testcase_10 AC 170 ms
11,704 KB
testcase_11 AC 150 ms
34,820 KB
testcase_12 AC 57 ms
12,332 KB
testcase_13 AC 186 ms
14,960 KB
testcase_14 AC 42 ms
12,720 KB
testcase_15 AC 41 ms
12,200 KB
testcase_16 AC 80 ms
14,664 KB
testcase_17 AC 146 ms
18,308 KB
testcase_18 AC 190 ms
15,000 KB
testcase_19 AC 176 ms
17,784 KB
testcase_20 AC 16 ms
11,624 KB
testcase_21 AC 64 ms
12,288 KB
testcase_22 AC 15 ms
11,552 KB
testcase_23 AC 16 ms
11,752 KB
testcase_24 AC 17 ms
11,920 KB
testcase_25 AC 16 ms
11,548 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){
			if(i == j){
				rep(u,2){
					string s = to_string(A[i][u]) + to_string(A[j][u^1]);
					int a = stoi(s);
					if(primes[a]) ts.add_clause(i, u, j, u);
				}
			}
			else{
				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