結果

問題 No.187 中華風 (Hard)
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-09-24 01:53:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 126 ms / 3,000 ms
コード長 3,062 bytes
コンパイル時間 4,515 ms
コンパイル使用メモリ 107,520 KB
実行使用メモリ 27,280 KB
最終ジャッジ日時 2023-09-10 13:16:55
合計ジャッジ時間 8,414 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
23,120 KB
testcase_01 AC 68 ms
21,168 KB
testcase_02 AC 89 ms
27,072 KB
testcase_03 AC 89 ms
25,136 KB
testcase_04 AC 123 ms
27,088 KB
testcase_05 AC 121 ms
25,124 KB
testcase_06 AC 92 ms
27,080 KB
testcase_07 AC 94 ms
25,092 KB
testcase_08 AC 124 ms
25,160 KB
testcase_09 AC 126 ms
25,136 KB
testcase_10 AC 96 ms
27,060 KB
testcase_11 AC 125 ms
25,040 KB
testcase_12 AC 122 ms
27,216 KB
testcase_13 AC 69 ms
21,068 KB
testcase_14 AC 70 ms
18,832 KB
testcase_15 AC 88 ms
23,188 KB
testcase_16 AC 90 ms
25,224 KB
testcase_17 AC 65 ms
20,884 KB
testcase_18 AC 66 ms
19,012 KB
testcase_19 AC 65 ms
20,904 KB
testcase_20 AC 111 ms
25,240 KB
testcase_21 AC 67 ms
23,068 KB
testcase_22 AC 94 ms
27,280 KB
testcase_23 AC 64 ms
23,056 KB
testcase_24 AC 68 ms
20,916 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
using System.Runtime.CompilerServices;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		var b=new BigInteger[n];
		var m=new BigInteger[n];
		for(int i = 0;i<n;i++) {
			var e=sc.Ia;
			b[i]=e[0];
			m[i]=e[1];
		}
		var ans=Cr(b,m);
		Console.WriteLine((ans.Item1!=0?ans.Item1:ans.Item2)%mod);
	}
	static (BigInteger,BigInteger) Cr(BigInteger[] ba,BigInteger[] ma) {
		BigInteger b=0,m=1;
		for(int i = 0;i<ma.Length;i++) {
			BigInteger d=Extgcd(m,ma[i],out BigInteger x,out BigInteger y);
			if((b-ba[i])%d!=0){return (-1,-1);}
			b+=m*((ba[i]-b)/d*x%(d=ma[i]/d));
			m*=d;
		}
		return ((b%m+m)%m,m);
	}
	static BigInteger Extgcd(BigInteger a,BigInteger b,out BigInteger x,out BigInteger y) {
		if(b==0){x=1;y=0;return a;}
		BigInteger d=Extgcd(b,a%b,out y,out x);
		y-=a/b*x;
		return d;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0