結果
| 問題 |
No.538 N.G.S.
|
| コンテスト | |
| ユーザー |
くれちー
|
| 提出日時 | 2017-07-05 21:44:58 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 5,029 bytes |
| コンパイル時間 | 1,240 ms |
| コンパイル使用メモリ | 116,280 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-09-25 00:12:42 |
| 合計ジャッジ時間 | 4,848 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 51 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
#pragma warning disable IDE0011
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Convert;
using static System.Math;
using static Extentions;
class IO
{
int idx;
string[] line;
public void R(params char[] sep) { line = Console.ReadLine().Split(sep); idx = 0; }
public string S => line[idx++];
public string[] Ss => line.Skip(idx++).ToArray();
public char C => char.Parse(line[idx++]);
public char[] Cs => line.Skip(idx++).Select(char.Parse).ToArray();
public int I => int.Parse(line[idx++]);
public int[] Is => line.Skip(idx++).Select(int.Parse).ToArray();
public long L => long.Parse(line[idx++]);
public long[] Ls => line.Skip(idx++).Select(long.Parse).ToArray();
public double F => double.Parse(line[idx++]);
public double[] Fs => line.Skip(idx++).Select(double.Parse).ToArray();
public decimal D => decimal.Parse(line[idx++]);
public decimal[] Ds => line.Skip(idx++).Select(decimal.Parse).ToArray();
public BigInteger B => BigInteger.Parse(line[idx++]);
public BigInteger[] Bs => line.Skip(idx++).Select(BigInteger.Parse).ToArray();
public void Write<T>(params T[] xs)
{
Console.Write(xs.First());
foreach (var x in xs.Skip(1)) Console.Write(" " + x);
Console.WriteLine();
}
public void Write(params object[] xs)
{
Console.Write(xs.First());
foreach (var x in xs.Skip(1)) Console.Write(" " + x);
Console.WriteLine();
}
}
static class Extentions
{
public static long Gcd(long x, long y)
{
long r;
while ((r = x % y) != 0) { x = y; y = r; }
return y;
}
public static long Lcm(long x, long y) => x * y / Gcd(x, y);
}
public struct Rational : IComparable<Rational>, IEquatable<Rational>
{
long numer;
long denom;
public long Numer { get { this.Reduce(); return numer; } }
public long Denom { get { this.Reduce(); return denom; } }
public int Sign => numer.CompareTo(0) * denom.CompareTo(0);
public Rational(long numer, long denom)
{
this.numer = numer;
this.denom = denom;
}
void Reduce()
{
if (numer == 0) { denom = 1; return; }
var d = Gcd(numer, denom);
numer /= d; denom /= d;
if (denom < 0) { numer *= -1; denom *= -1; }
}
public Rational Invert() => new Rational(denom, numer);
public static Rational operator -(Rational r)
=> new Rational(-r.numer, r.denom);
public static Rational operator +(Rational left, Rational right)
{
left.Reduce(); right.Reduce();
var d = Lcm(left.denom, right.denom);
var n = checked(left.numer * d / left.denom + right.numer * d / right.denom);
return new Rational(n, d);
}
public static Rational operator *(Rational left, Rational right)
{
left.Reduce(); right.Reduce();
var n = checked(left.numer * right.numer);
var d = checked(left.denom * right.denom);
return new Rational(n, d);
}
public static Rational operator -(Rational left, Rational right)
=> left + -right;
public static Rational operator /(Rational left, Rational right)
=> left * right.Invert();
public static bool operator ==(Rational left, Rational right)
=> left.Equals(right);
public static bool operator !=(Rational left, Rational right)
=> !left.Equals(right);
public static bool operator <(Rational left, Rational right)
=> left.CompareTo(right) < 0;
public static bool operator >(Rational left, Rational right)
=> left.CompareTo(right) > 0;
public static bool operator <=(Rational left, Rational right)
=> left < right || left == right;
public static bool operator >=(Rational left, Rational right)
=> left > right || left == right;
public static implicit operator Rational(long x) => new Rational(x, 1);
public int CompareTo(Rational other) => (this - other).Sign;
public bool Equals(Rational other)
{
var r = this / other;
return r.numer == r.denom;
}
public override bool Equals(object obj)
{
if (!(obj is Rational)) return false;
var r = (Rational)obj / this;
return r.numer == r.denom;
}
public override int GetHashCode()
=> this.Numer.GetHashCode() ^ this.Denom.GetHashCode();
public override string ToString() => $"{this.Numer} / {this.Denom}";
}
static class Program
{
public static void Main()
{
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve(new IO());
Console.Out.Flush();
}
public static void Solve(IO io)
{
io.R();
var b = io.Ls;
var d = new Rational(b[0] * b[2] - b[1] * b[1], b[0] - b[1]);
var r = b[0] != 0 ? -(d - b[1]) / b[0] : -(d - b[2]) / b[1];
io.Write((r * b[2] + d).Numer);
}
}
くれちー