結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-14 17:35:56 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,902 bytes |
| コンパイル時間 | 883 ms |
| コンパイル使用メモリ | 109,404 KB |
| 実行使用メモリ | 25,948 KB |
| 最終ジャッジ日時 | 2024-11-06 19:51:42 |
| 合計ジャッジ時間 | 3,598 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 48 RE * 9 |
コンパイルメッセージ
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(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;
}
}
// 真ん中が出る場合
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 = @"
1000000000
1000000000
1000000000
1000000000
";
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();
}
}
14番