結果
問題 | No.281 門松と魔法(1) |
ユーザー | 14番 |
提出日時 | 2016-05-14 17:37:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 26 ms / 1,000 ms |
コード長 | 3,991 bytes |
コンパイル時間 | 2,308 ms |
コンパイル使用メモリ | 111,684 KB |
実行使用メモリ | 25,960 KB |
最終ジャッジ日時 | 2024-11-06 20:45:44 |
合計ジャッジ時間 | 3,874 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
23,544 KB |
testcase_01 | AC | 25 ms
23,648 KB |
testcase_02 | AC | 24 ms
23,544 KB |
testcase_03 | AC | 25 ms
23,796 KB |
testcase_04 | AC | 24 ms
21,692 KB |
testcase_05 | AC | 25 ms
23,668 KB |
testcase_06 | AC | 25 ms
23,852 KB |
testcase_07 | AC | 24 ms
24,056 KB |
testcase_08 | AC | 24 ms
21,680 KB |
testcase_09 | AC | 25 ms
25,960 KB |
testcase_10 | AC | 25 ms
25,960 KB |
testcase_11 | AC | 24 ms
21,684 KB |
testcase_12 | AC | 24 ms
23,596 KB |
testcase_13 | AC | 25 ms
25,704 KB |
testcase_14 | AC | 25 ms
23,924 KB |
testcase_15 | AC | 24 ms
23,660 KB |
testcase_16 | AC | 24 ms
23,912 KB |
testcase_17 | AC | 26 ms
25,712 KB |
testcase_18 | AC | 25 ms
23,980 KB |
testcase_19 | AC | 24 ms
23,796 KB |
testcase_20 | AC | 24 ms
23,800 KB |
testcase_21 | AC | 25 ms
25,724 KB |
testcase_22 | AC | 25 ms
23,788 KB |
testcase_23 | AC | 25 ms
23,924 KB |
testcase_24 | AC | 24 ms
23,796 KB |
testcase_25 | AC | 25 ms
23,672 KB |
testcase_26 | AC | 25 ms
25,956 KB |
testcase_27 | AC | 25 ms
25,832 KB |
testcase_28 | AC | 24 ms
25,948 KB |
testcase_29 | AC | 25 ms
23,672 KB |
testcase_30 | AC | 25 ms
24,048 KB |
testcase_31 | AC | 25 ms
23,796 KB |
testcase_32 | AC | 25 ms
25,708 KB |
testcase_33 | AC | 25 ms
25,824 KB |
testcase_34 | AC | 24 ms
23,856 KB |
testcase_35 | AC | 25 ms
23,672 KB |
testcase_36 | AC | 26 ms
25,704 KB |
testcase_37 | AC | 26 ms
25,836 KB |
testcase_38 | AC | 25 ms
23,644 KB |
testcase_39 | AC | 25 ms
23,468 KB |
testcase_40 | AC | 24 ms
23,796 KB |
testcase_41 | AC | 24 ms
23,672 KB |
testcase_42 | AC | 24 ms
23,724 KB |
testcase_43 | AC | 24 ms
23,544 KB |
testcase_44 | AC | 24 ms
23,724 KB |
testcase_45 | AC | 25 ms
25,584 KB |
testcase_46 | AC | 24 ms
23,724 KB |
testcase_47 | AC | 25 ms
23,796 KB |
testcase_48 | AC | 26 ms
23,788 KB |
testcase_49 | AC | 25 ms
24,056 KB |
testcase_50 | AC | 25 ms
24,176 KB |
testcase_51 | AC | 25 ms
23,924 KB |
testcase_52 | AC | 24 ms
25,828 KB |
testcase_53 | AC | 25 ms
25,840 KB |
testcase_54 | AC | 26 ms
23,656 KB |
testcase_55 | AC | 25 ms
25,704 KB |
testcase_56 | AC | 25 ms
25,840 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.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long minus = long.Parse(Reader.ReadLine()); long take1 = long.Parse(Reader.ReadLine()); long take2 = long.Parse(Reader.ReadLine()); long take3 = long.Parse(Reader.ReadLine()); long ans = -1; // 真ん中を減らす場合 long ret = this.GetAns1(take1, take2, take3, minus); if(ret >= 0) { ans = ret; } ret = this.GetAns2(take1, take2, take3, minus); if(ret >= 0) { if(ans == -1) { ans = ret; } else { ans = Math.Min(ans, ret); } } Console.WriteLine(ans); } private long GetAns2(long take1, long take2, long take3, long minus) { // 真ん中が引っ込む場合 long tmp1 = take1; long tmp2 = take2; long tmp3 = take3; long ret = 0; if(minus == 0) { return -1; } if(tmp1 == tmp3) { if(tmp1 == 0) { return -1; } tmp1 = Math.Max(0, tmp1 - minus); ret++; } long times = (tmp2 - Math.Min(tmp1,tmp3)) / minus + 1; tmp2 = Math.Max(0, tmp2 - times * minus); ret += times; if(tmp2 == tmp1 || tmp2 == tmp3) { if(tmp2 == 0) { return -1; } else { tmp2 = Math.Max(0, tmp2 - minus); ret++; } } return ret; } private long GetAns1(long take1, long take2, long take3, long minus) { // 最初から揃っている場合 if(take1 != take2 && take2 != take3 && take3 != take1) { if(take2 > Math.Max(take1, take3)) { return 0; } if(take2 < Math.Min(take1, take3)) { return 0; } } if(minus == 0) { return -1; } // 真ん中が出る場合 long tmp1 = take1; long tmp2 = take2; long tmp3 = take3; long ret = 0; if(tmp1 >= tmp2) { long times = (take1 - take2) / minus + 1; ret += times; tmp1 = Math.Max(0, tmp1 - (times * minus)); } if(tmp3 >= tmp2) { long times = (take3 - take2) / minus + 1; ret += times; tmp3 = Math.Max(0, tmp3 - (times * minus)); } if(tmp1 == tmp3) { if(tmp1 == 0) { return -1; } else { ret += 1; } } return ret; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 0 0 1 2 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }