結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
4,380 KB
testcase_01 AC 161 ms
4,376 KB
testcase_02 AC 167 ms
4,808 KB
testcase_03 AC 161 ms
4,380 KB
testcase_04 AC 181 ms
8,904 KB
testcase_05 AC 169 ms
6,828 KB
testcase_06 AC 171 ms
7,116 KB
testcase_07 AC 179 ms
8,864 KB
testcase_08 AC 161 ms
4,380 KB
testcase_09 AC 175 ms
6,368 KB
testcase_10 AC 218 ms
8,976 KB
testcase_11 AC 191 ms
7,028 KB
testcase_12 AC 170 ms
6,216 KB
testcase_13 AC 205 ms
8,416 KB
testcase_14 RE -
testcase_15 AC 326 ms
4,808 KB
testcase_16 AC 184 ms
9,248 KB
testcase_17 AC 200 ms
4,860 KB
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;
	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;
	}
	if(A.sort != B.sort) 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