結果

問題 No.1779 Magical Swap
ユーザー laneguelanegue
提出日時 2021-12-25 19:53:14
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 3,727 ms
コンパイル使用メモリ 229,464 KB
実行使用メモリ 9,144 KB
最終ジャッジ日時 2023-09-04 15:34:38
合計ジャッジ時間 9,221 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
4,380 KB
testcase_01 AC 171 ms
4,376 KB
testcase_02 AC 177 ms
4,808 KB
testcase_03 AC 171 ms
4,380 KB
testcase_04 AC 192 ms
8,776 KB
testcase_05 AC 180 ms
6,584 KB
testcase_06 AC 182 ms
6,588 KB
testcase_07 AC 190 ms
8,896 KB
testcase_08 AC 170 ms
4,380 KB
testcase_09 AC 183 ms
5,024 KB
testcase_10 AC 225 ms
9,076 KB
testcase_11 AC 198 ms
6,992 KB
testcase_12 AC 179 ms
4,680 KB
testcase_13 AC 214 ms
8,368 KB
testcase_14 AC 227 ms
8,640 KB
testcase_15 AC 333 ms
4,804 KB
testcase_16 AC 195 ms
9,144 KB
testcase_17 AC 207 ms
4,820 KB
testcase_18 AC 171 ms
4,376 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[]);
	auto i = primes.countUntil!(a => (a * 2 > N));
	auto j = primes.countUntil!(a => (a > N));
	if(j < 0){
		j = primes.length;
	}
	foreach(p; primes[i .. j]){
		if(A[p - 1] != B[p - 1]) return false;
	}
	if(A[0] != B[0]) 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