結果

問題 No.1779 Magical Swap
ユーザー laneguelanegue
提出日時 2021-12-25 19:31:33
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 229,264 KB
実行使用メモリ 10,656 KB
最終ジャッジ日時 2023-09-04 15:34:04
合計ジャッジ時間 7,810 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 161 ms
4,380 KB
testcase_04 AC 181 ms
8,828 KB
testcase_05 AC 170 ms
6,620 KB
testcase_06 AC 170 ms
7,396 KB
testcase_07 AC 178 ms
8,696 KB
testcase_08 AC 160 ms
4,380 KB
testcase_09 AC 173 ms
5,100 KB
testcase_10 AC 217 ms
9,024 KB
testcase_11 AC 190 ms
7,152 KB
testcase_12 AC 170 ms
4,712 KB
testcase_13 AC 205 ms
8,196 KB
testcase_14 RE -
testcase_15 AC 321 ms
4,808 KB
testcase_16 AC 185 ms
9,300 KB
testcase_17 WA -
testcase_18 AC 160 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

const int N_MAX = 10 ^^ 5;
int[] primes;

bool solve(){
	auto N = readln.chomp.to!int;
	auto A = readln.chomp.split(" ").to!(int[]);
	auto B = readln.chomp.split(" ").to!(int[]);
	if(A[0] != B[0]) return false;
	if(A.sort != B.sort) return false;
	auto i = primes.countUntil!(a => (a * 2 > N));
	auto j = primes.countUntil!(a => (a > N));
	foreach(p; primes[i .. j]){
		if(A[p - 1] != B[p - 1]) return false;
	}
	return true;
}

void main(){
	auto T = readln.chomp.to!int;
	primes ~= 2;
	for(auto n = 3; n <= N_MAX; n += 2){
		auto f = true;
		foreach(p; primes){
			if(n % p == 0){
				f = false;
				break;
			}
		}
		if(f){
			primes ~= n;
		}
	}
	for(auto t = 0; t < T; t++){
		if(solve){
			writeln("Yes");
		}else{
			writeln("No");
		}
	}
}
0