結果
問題 | No.186 中華風 (Easy) |
ユーザー | mban |
提出日時 | 2017-04-16 17:04:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 3,228 bytes |
コンパイル時間 | 3,272 ms |
コンパイル使用メモリ | 105,144 KB |
実行使用メモリ | 22,848 KB |
最終ジャッジ日時 | 2023-09-27 00:51:35 |
合計ジャッジ時間 | 5,896 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
20,756 KB |
testcase_01 | AC | 61 ms
22,848 KB |
testcase_02 | AC | 61 ms
20,812 KB |
testcase_03 | AC | 57 ms
20,692 KB |
testcase_04 | AC | 68 ms
20,700 KB |
testcase_05 | AC | 67 ms
22,692 KB |
testcase_06 | AC | 72 ms
22,776 KB |
testcase_07 | AC | 69 ms
22,676 KB |
testcase_08 | AC | 76 ms
22,764 KB |
testcase_09 | AC | 75 ms
20,648 KB |
testcase_10 | AC | 73 ms
22,624 KB |
testcase_11 | AC | 81 ms
20,792 KB |
testcase_12 | AC | 63 ms
20,616 KB |
testcase_13 | AC | 65 ms
20,568 KB |
testcase_14 | AC | 66 ms
22,792 KB |
testcase_15 | AC | 58 ms
20,792 KB |
testcase_16 | AC | 62 ms
22,720 KB |
testcase_17 | AC | 58 ms
20,708 KB |
testcase_18 | AC | 60 ms
20,792 KB |
testcase_19 | AC | 70 ms
20,768 KB |
testcase_20 | AC | 60 ms
20,680 KB |
testcase_21 | AC | 67 ms
20,736 KB |
testcase_22 | AC | 69 ms
20,628 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using System.Collections; using System.IO; class Program { static void Main(string[] args) { new Magatro().Solve(); } } public class Scanner { private StreamReader Sr; private string[] S; private int Index; private const char Separator = ' '; public Scanner(Stream stream) { Index = 0; S = new string[0]; Sr = new StreamReader(stream); } private string[] Line() { return Sr.ReadLine().Split(Separator); } public string Next() { string result; if (Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public decimal NextDecimal() { return decimal.Parse(Next()); } public string[] StringArray(int index = 0) { Next(); Index = S.Length; return S.Skip(index).ToArray(); } public int[] IntArray(int index = 0) { return StringArray(index).Select(int.Parse).ToArray(); } public long[] LongArray(int index = 0) { return StringArray(index).Select(long.Parse).ToArray(); } public bool EndOfStream { get { return Sr.EndOfStream; } } } public class Magatro { private int X1, X2, X3, Y1, Y2, Y3; long ans; private void Scan() { Scanner scanner = new Scanner(Console.OpenStandardInput()); X1 = scanner.NextInt(); Y1 = scanner.NextInt(); X2 = scanner.NextInt(); Y2 = scanner.NextInt(); X3 = scanner.NextInt(); Y3 = scanner.NextInt(); } public void Solve() { Scan(); ans = X1; bool flag = false; for (long i = 0; i <= Y2; i++) { long j = ans + Y1 * i; if (j % Y2 == X2) { flag = true; ans = j; break; } } if (!flag) { Console.WriteLine(-1); return; } long lcm = LCM(Y1, Y2); flag = false; for (long i = 0; i <= Y3; i++) { long j = ans + lcm * i; if (j % Y3 == X3&&j!=0) { flag = true; ans = j; break; } } if (!flag) { Console.WriteLine(-1); return; } Console.WriteLine(ans); } private long LCM(long a, long b) { return (a * b) / GCD(a, b); } private long GCD(long a, long b) { if (a < b) { Swap(ref a, ref b); } long r = a % b; while (r > 0) { a = b; b = r; r = a % b; } return b; } private void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } }