結果
| 問題 |
No.1884 Sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-01 21:06:27 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 2,000 ms |
| コード長 | 5,708 bytes |
| コンパイル時間 | 9,656 ms |
| コンパイル使用メモリ | 167,940 KB |
| 実行使用メモリ | 230,812 KB |
| 最終ジャッジ日時 | 2024-11-26 03:14:48 |
| 合計ジャッジ時間 | 17,077 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (96 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
//using static CompLib.CompLib;
//using DataStructure;
namespace atcoder
{
class Program
{
const int intMax = 1000000000;
const long longMax = 2000000000000000000;
static void Main(string[] args)
{
int N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
var list = new List<long>();
int cnt = 0;
for (int i = 0; i < N; i++)
{
if (A[i] > 0)
{
list.Add(A[i]);
}
else
{
cnt++;
}
}
list = list.OrderBy(a => a).ToList();
var diff = new List<long>();
for (int i = 0; i < list.Count - 1; i++)
{
diff.Add(list[i + 1] - list[i]);
}
if (diff.Contains(0))
{
if (list[0] == list[list.Count - 1])
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
return;
}
else if (diff.Count == 0)
{
Console.WriteLine("Yes");
return;
}
long gcd = diff[0];
for (int i = 1; i < diff.Count; i++)
{
gcd = MyMath.gcd(gcd, diff[i]);
}
long need = 0;
foreach (var d in diff)
{
need += (d / gcd) - 1;
}
if (need <= cnt)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
}
public static class MyMath
{
public static bool IsPrime(long n)
{
for (int i = 2; i <= Math.Sqrt(n); i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
public static List<int> GetPrimes(int n)
{
var primeList = new List<int>();
var prime = new int[n + 1];
for (int i = 2; i <= n; i++)
{
int temp = i;
int id = 2;
while (temp <= n)
{
prime[temp]++;
temp = i * id;
id++;
}
}
for (int i = 1; i <= n; i++)
{
if (prime[i] == 1)
{
primeList.Add(i);
}
}
return primeList;
}
public static long gcd(long C, long D)
{
long tempC = C;
long tempD = D;
long r = tempD % tempC;
while (r != 0)
{
tempD = tempC;
tempC = r;
r = tempD % tempC;
}
return tempC;
}
public static long lcm(long C, long D)
{
long tempC = C;
long tempD = D;
long r = tempD % tempC;
while (r != 0)
{
tempD = tempC;
tempC = r;
r = tempD % tempC;
}
long lcm = (long)Math.Floor(((decimal)C * D) / tempC);
return lcm;
}
public static long pow(long x, long n, long mod = 100000007)
{
long ret = 1;
while (n > 0)
{
if ((n & 1) > 0) ret *= x;
ret %= mod;
x *= x;
x %= mod;
n = n >> 1;
}
return ret;
}
public static long[,] Transpose(long[,] A)
{
long[,] AT = new long[A.GetLength(1), A.GetLength(0)];
for (int i = 0; i < A.GetLength(1); i++)
{
for (int j = 0; j < A.GetLength(0); j++)
{
AT[i, j] = A[j, i];
}
}
return AT;
}
public static long[,] MatrixMultiplication(long[,] A, long[,] B, long mod = 1000000007)
{
long[,] C = new long[A.GetLength(0), B.GetLength(1)];
for (int i = 0; i < A.GetLength(0); i++)
{
for (int j = 0; j < B.GetLength(1); j++)
{
for (int k = 0; k < A.GetLength(1); k++)
{
C[i, j] += A[i, k] * B[k, j];
C[i, j] %= mod;
}
}
}
return C;
}
public static long[,] MathrixPow(long[,] A, long n, long mod = 1000000007)
{
long[,] P = A;
long[,] Q = new long[A.GetLength(0), A.GetLength(1)];
bool flag = false;
for (int i = 0; i < 60; i++)
{
if ((n & ((long)1 << i)) > 0)
{
if (!flag)
{
Q = P;
flag = true;
}
else
{
Q = MatrixMultiplication(Q, P, mod);
}
}
P = MatrixMultiplication(P, P, mod);
}
return Q;
}
}
}