結果

問題 No.1955 Not Prime
ユーザー 👑 platinumplatinum
提出日時 2022-04-12 21:23:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 960 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 2,739 ms
コンパイル使用メモリ 228,300 KB
実行使用メモリ 56,048 KB
最終ジャッジ日時 2023-08-23 07:00:57
合計ジャッジ時間 11,019 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,924 KB
testcase_01 AC 32 ms
11,704 KB
testcase_02 AC 31 ms
11,624 KB
testcase_03 AC 31 ms
11,564 KB
testcase_04 AC 31 ms
11,648 KB
testcase_05 AC 31 ms
11,640 KB
testcase_06 AC 59 ms
12,616 KB
testcase_07 AC 571 ms
25,588 KB
testcase_08 AC 494 ms
24,792 KB
testcase_09 AC 960 ms
28,232 KB
testcase_10 AC 467 ms
11,940 KB
testcase_11 AC 193 ms
34,560 KB
testcase_12 AC 252 ms
18,056 KB
testcase_13 AC 949 ms
29,468 KB
testcase_14 AC 100 ms
12,500 KB
testcase_15 AC 97 ms
12,028 KB
testcase_16 AC 234 ms
15,064 KB
testcase_17 AC 397 ms
18,140 KB
testcase_18 AC 951 ms
29,244 KB
testcase_19 AC 848 ms
56,048 KB
testcase_20 AC 32 ms
11,584 KB
testcase_21 AC 287 ms
19,468 KB
testcase_22 AC 31 ms
11,560 KB
testcase_23 AC 31 ms
11,528 KB
testcase_24 AC 31 ms
11,652 KB
testcase_25 AC 31 ms
11,624 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);
	map<int,int> primes;
	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