結果

問題 No.740 幻の木
ユーザー sekiya9311sekiya9311
提出日時 2019-10-27 00:38:15
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 6,568 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 111,872 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-09-14 20:58:33
合計ジャッジ時間 2,895 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Numerics;
using System.Text;
namespace ProgrammingContestTemplateByDotNetCore
{
#region "Input and Output Classes"
class Scanner : IDisposable
{
private readonly Queue<string> _buffer;
private readonly char[] _sep;
private readonly TextReader _reader;
public Scanner(TextReader reader = null, char[] sep = null)
{
_buffer = new Queue<string>();
_sep = sep ?? new[] { ' ' };
_reader = reader ?? Console.In;
}
public Scanner(string path, char[] sep = null)
: this(new StreamReader(path), sep) { }
private void CheckBuffer()
{
if (_buffer.Any() || _reader.Peek() == -1)
return;
string str = string.Empty;
for (;
string.IsNullOrWhiteSpace(str);
str = _reader.ReadLine()) { }
var values = str.Split(_sep).Where(s => !string.IsNullOrWhiteSpace(s));
foreach (var item in values)
{
_buffer.Enqueue(item);
}
}
public string Next()
{
CheckBuffer();
return _buffer.Dequeue();
}
public string[] GetStringArray(int count)
=> Enumerable.Range(0, count)
.Select(e => Next())
.ToArray();
public int NextInt() => int.Parse(Next());
public int[] GetIntArray(int count)
=> Enumerable.Range(0, count)
.Select(e => NextInt())
.ToArray();
public long NextLong() => long.Parse(Next());
public long[] GetLongArray(int count)
=> Enumerable.Range(0, count)
.Select(e => NextLong())
.ToArray();
public double NextDouble() => double.Parse(Next());
public double[] GetDoubleArray(int count)
=> Enumerable.Range(0, count)
.Select(e => NextDouble())
.ToArray();
public decimal NextDecimal() => decimal.Parse(Next());
public decimal[] GetDecimalArray(int count)
=> Enumerable.Range(0, count)
.Select(e => NextDecimal())
.ToArray();
public BigInteger NextBigInt() => BigInteger.Parse(Next());
public BigInteger[] GetBigIntArray(int count)
=> Enumerable.Range(0, count)
.Select(e => NextBigInt())
.ToArray();
public bool IsEnd
{
get
{
CheckBuffer();
return !_buffer.Any();
}
}
public void Dispose()
{
if (!_reader.Equals(Console.In))
_reader.Dispose();
}
}
class Writer : IDisposable
{
private readonly TextWriter _writer;
private readonly StringBuilder _cache;
private readonly bool _isReactive;
public Writer(TextWriter writer = null, bool isReactive = false)
{
_writer = writer ?? Console.Out;
_isReactive = isReactive;
if (!_isReactive)
_cache = new StringBuilder();
}
public Writer(string path)
: this(new StreamWriter(path)) { }
public Writer(bool isReactive)
: this(null, isReactive) { }
public void Write(object value)
{
if (_isReactive)
{
_writer.Write(value);
_writer.Flush();
}
else
{
_cache.Append(value);
}
}
public void WriteFormat(string format, params object[] values)
{
var value = string.Format(format, values);
Write(value);
}
public void WriteLine(object value = null)
{
Write($"{value}{Environment.NewLine}");
}
public void WriteLine(string format, params object[] values)
{
WriteFormat($"{format}{Environment.NewLine}", values);
}
public void Dispose()
{
if (!_isReactive)
{
_writer.Write(_cache);
_writer.Flush();
}
if (!_writer.Equals(Console.Out))
{
_writer.Dispose();
}
}
}
public static class Extensions
{
public static void Set<TKey, TValue>(
this IDictionary<TKey, TValue> source,
TKey key, TValue value)
{
if (source.ContainsKey(key))
source[key] = value;
else
source.Add(key, value);
}
}
#endregion
class MainClass : IDisposable
{
#region "Template"
/// <summary> </summary>
private readonly Scanner sc;
/// <summary> </summary>
private readonly Writer wr;
private const string _inputFile = "input.txt";
private const string _outFile = "output.txt";
static void Main(string[] args)
{
using (new MainClass()) { }
}
public MainClass()
{
wr = new Writer(_isReactive);
// TODO: → wr = new Writer(_outFile);
#if DEBUG
//
sc = new Scanner(_inputFile);
#else
//
sc = new Scanner();
#endif
Solve();
}
public void Dispose()
{
sc?.Dispose();
wr?.Dispose();
}
#endregion
void Solve()
{
int N = sc.NextInt();
int M = sc.NextInt();
int P = sc.NextInt() - 1;
int Q = sc.NextInt();
int cnt = 0;
for (int month = 0; N > 0; cnt++, month = (month + 1) % 12)
{
if (0 <= month - P && month - P < Q)
{
N -= M * 2;
}
else
{
N -= M;
}
}
wr.WriteLine(cnt);
}
/// <summary>
/// TODO:
/// </summary>
private const bool _isReactive = false;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0