結果
問題 | No.1884 Sequence |
ユーザー |
![]() |
提出日時 | 2022-03-26 07:52:18 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 207 ms / 2,000 ms |
コード長 | 1,537 bytes |
コンパイル時間 | 868 ms |
コンパイル使用メモリ | 111,948 KB |
実行使用メモリ | 55,512 KB |
最終ジャッジ日時 | 2024-10-14 17:21:04 |
合計ジャッジ時間 | 8,860 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Collections.Generic; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = new List<long>(); var z = 0; for (int i = 0; i < n; i++) { var t = long.Parse(line[i]); if (t == 0) z++; else a.Add(t); } getAns(n, z, a); } static bool checkD0(List<long> a) { var pre = a[0]; foreach (var x in a) if (x != pre) return false; return true; } static void getAns(int n, int z, List<long> a) { var acount = a.Count; if (acount <=2) { Console.WriteLine("Yes");return; } a.Sort(); var dlist = new List<long>(); var g = a[1] - a[0]; if (g == 0) { Console.WriteLine(checkD0(a) ? "Yes" : "No"); return; } dlist.Add(g); for (int i = 2; i < acount; i++) { var tt = a[i] - a[i - 1]; if (tt == 0) { Console.WriteLine(checkD0(a) ? "Yes" : "No"); return; } g = Gcd(g, tt); dlist.Add(tt); } var ans = 0L; foreach (var x in dlist) ans += x / g - 1; Console.WriteLine(z >= ans ? "Yes" : "No"); } public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var w = a % b; a = b; b = w; } return a; } }