結果
問題 | No.2518 Adjacent Larger |
ユーザー |
|
提出日時 | 2023-10-27 22:54:02 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 1,349 bytes |
コンパイル時間 | 3,533 ms |
コンパイル使用メモリ | 178,184 KB |
実行使用メモリ | 8,788 KB |
最終ジャッジ日時 | 2024-09-25 14:56:42 |
合計ジャッジ時間 | 5,027 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
import std;void main () {int T = readln.chomp.to!int;foreach (_; 0..T) {int N = readln.split[0].to!int;int[] A = readln.split.to!(int[]);auto ans = solve(N, A);writeln(ans);}}auto solve (int N, int[] A) {/*** 必要条件* - 0と2が少なくとも1つ* - 0と2は同じものが連続することがない* - 0と2は同じ数だけ存在* かなー未証明だけど提出チャレンジする** WAした。まだなんか抜けてるみたい*/int zero = 0, two = 0;foreach (a; A) {if (a == 0) zero++;if (a == 2) two++;}if (zero != two || zero == 0 || two == 0) return "No";foreach (i; 0..A.length) {if (A[i] == 0 || A[i] == 2) {if (A[i] == A[(i+1)%A.length]) return "No";}}bool isNextZero = false;bool first = true;foreach (a; chain(A, A)) {if (first && a == 0) { isNextZero = false; first = false; continue; }if (first && a == 2) { isNextZero = true; first = false; continue; }if (first) continue;if (a == 0 && isNextZero) { isNextZero = false; continue; }if (a == 2 && !isNextZero) { isNextZero = true; continue; }if (a == 0 || a == 2) return "No";}return "Yes";}