結果

問題 No.1624 三角形の反射
ユーザー fairy_lettucefairy_lettuce
提出日時 2021-12-01 15:49:34
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 9,669 bytes
コンパイル時間 10,501 ms
コンパイル使用メモリ 166,844 KB
実行使用メモリ 192,660 KB
最終ジャッジ日時 2024-07-04 15:36:20
合計ジャッジ時間 13,024 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
29,696 KB
testcase_01 AC 54 ms
30,336 KB
testcase_02 AC 56 ms
30,336 KB
testcase_03 AC 57 ms
30,208 KB
testcase_04 AC 56 ms
30,208 KB
testcase_05 AC 57 ms
30,336 KB
testcase_06 AC 54 ms
30,040 KB
testcase_07 AC 56 ms
30,208 KB
testcase_08 AC 57 ms
30,208 KB
testcase_09 AC 55 ms
30,204 KB
testcase_10 AC 56 ms
29,952 KB
testcase_11 AC 56 ms
30,464 KB
testcase_12 AC 55 ms
30,204 KB
testcase_13 AC 54 ms
30,336 KB
testcase_14 AC 56 ms
30,040 KB
testcase_15 AC 57 ms
29,568 KB
testcase_16 AC 57 ms
30,336 KB
testcase_17 AC 55 ms
30,208 KB
testcase_18 AC 56 ms
30,208 KB
testcase_19 AC 54 ms
29,824 KB
testcase_20 AC 54 ms
30,208 KB
testcase_21 AC 54 ms
30,336 KB
testcase_22 AC 58 ms
30,204 KB
testcase_23 AC 56 ms
29,824 KB
testcase_24 AC 57 ms
192,660 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (92 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Threading;
using static System.Math;
namespace CpLibrary.Contest
{
	public class SolverB : SolverBase
	{
		Scanner sr;
		bool HasMultipleTestcases { get; }

		public override void Solve()
		{
			var s = sr.ReadString().Split('.').Select(p => int.Parse(p)).ToArray();
			var a = new Rational(s[0] * 1000 + s[1], 1000);
			var x = a.denominator;
			var y = a.numerator;
			var ans = x + y - 2;
			ans += Abs(x + y) / 2;
			ans += Abs(x - y) / 2;
			if (x % 2 == y % 2)
			{
				Console.WriteLine($"A {ans}");
			}
			else if (x % 2 == 1)
			{
				Console.WriteLine($"B {ans}");
			}
			else
			{
				Console.WriteLine($"C {ans}");
			}
		}

		public SolverB(Scanner sr) => this.sr = sr;

		public override void Run()
		{
			var _t = 1;
			if (HasMultipleTestcases) _t = sr.ReadInt();
			while (_t-- > 0) Solve();
		}
	}

	public struct Rational : IComparable<Rational>, IEquatable<Rational>
	{
		public long numerator { get; set; }
		public long denominator { get; set; }

		public Rational(long numerator, long denominator)
		{
			if (denominator < 0)
			{
				numerator *= -1;
				denominator *= -1;
			}

			static long GCD(long a, long b)
			{
				a = Math.Abs(a);
				b = Math.Abs(b);
				while (a > 0)
				{
					b %= a;
					var x = a;
					a = b;
					b = x;
				}
				return b;
			}

			var gcd = GCD(numerator, denominator);
			numerator /= gcd;
			denominator /= gcd;

			this.numerator = numerator;
			this.denominator = denominator;
		}

		public Rational(long integer)
		{
			numerator = integer;
			denominator = 1;
		}

		public static Rational Parse(string s)
		{
			var sarray = s.Split('/');
			if (sarray.Length == 1) return new Rational(long.Parse(sarray[0]));
			if (sarray.Length == 2) return new Rational(long.Parse(sarray[0]), long.Parse(sarray[1]));
			throw new ArgumentException("Invalid argument input.");
		}

		public static Rational operator +(Rational l, Rational r) => new Rational(l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator);
		public static Rational operator -(Rational l, Rational r) => new Rational(l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator);
		public static Rational operator *(Rational l, Rational r) => new Rational(l.numerator * r.numerator, l.denominator * r.denominator);
		public static Rational operator /(Rational l, Rational r) => new Rational(l.numerator * r.denominator, l.denominator * r.numerator);

		public static Rational operator ++(Rational x)
		{
			var tmp = x + new Rational(1);
			return tmp;
		}
		public static Rational operator --(Rational x)
		{
			var tmp = x - new Rational(1);
			return tmp;
		}

		public static bool operator >(Rational l, Rational r) => l.CompareTo(r) > 0;
		public static bool operator <(Rational l, Rational r) => l.CompareTo(r) < 0;
		public static bool operator >=(Rational l, Rational r) => l.CompareTo(r) >= 0;
		public static bool operator <=(Rational l, Rational r) => l.CompareTo(r) <= 0;
		public static bool operator ==(Rational l, Rational r) => l.Equals(r);
		public static bool operator !=(Rational l, Rational r) => !l.Equals(r);

		public override string ToString() => $"{numerator}/{denominator}";

		public int CompareTo(Rational x)
		{
			var diff = this - x;
			if (diff.numerator > 0) return 1;
			if (diff.numerator < 0) return -1;
			return 0;
		}

		public bool Equals(Rational item) => denominator == item.denominator && numerator == item.numerator;

		public override bool Equals(object obj) => obj is Rational r && numerator == r.numerator && denominator == r.denominator;

		public override int GetHashCode()
		{
			return HashCode.Combine(numerator, denominator);
		}
	}

	public static class ProgramB
	{
		private static bool StartsOnThread = true;

		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);
			var sr = new Scanner(new StreamReader(Console.OpenStandardInput()));
			var solver = new SolverB(sr);
			if (StartsOnThread)
			{
				var thread = new Thread(new ThreadStart(() => solver.Run()), 1 << 27);
				thread.Start();
				thread.Join();
			}
			else solver.Run();
			Console.Out.Flush();
		}

		public static void Expand() => SourceExpander.Expander.Expand();
	}
}
#region Expanded by https://github.com/naminodarie/SourceExpander
namespace CpLibrary { public class Scanner { public StreamReader sr { get; private set; }  string[] str; int index; char[] separators; public Scanner(StreamReader sr, char[] separators) { this.sr = sr; this.separators = separators; str = new string[0]; index = 0; }  public Scanner(StreamReader sr): this(sr, new char[]{' '}) { }  public Scanner(): this(new StreamReader(Console.OpenStandardInput()), new char[]{' '}) { }  public string Read() { if (index < str.Length) return str[index++]; string s; do s = sr.ReadLine(); while (s == ""); str = s.Split(separators, StringSplitOptions.RemoveEmptyEntries); index = 0; return str[index++]; }  public string ReadString() => Read(); public string[] ReadStringArray(int n) { var arr = new string[n]; for (int i = 0; i < n; i++) { arr[i] = ReadString(); }  return arr; }  public int ReadInt() => int.Parse(ReadString()); public int[] ReadIntArray(int n) => ReadValueArray<int>(n); public long ReadLong() => long.Parse(ReadString()); public long[] ReadLongArray(int n) => ReadValueArray<long>(n); public double ReadDouble() => double.Parse(ReadString()); public double[] ReadDoubleArray(int n) => ReadValueArray<double>(n); public BigInteger ReadBigInteger() => BigInteger.Parse(ReadString()); public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public T1[] ReadValueArray<T1>(int n) { var arr = new T1[n]; for (int i = 0; i < n; i++) { arr[i] = ReadValue<T1>(); }  return arr; }  public (T1, T2) ReadValue<T1, T2>() => (ReadValue<T1>(), ReadValue<T2>()); public (T1, T2, T3) ReadValue<T1, T2, T3>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>()); public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>()); public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>()); public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>(), ReadValue<T6>()); public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>(), ReadValue<T6>(), ReadValue<T7>()); public (T1[], T2[]) ReadValueArray<T1, T2>(int n) { var(v1, v2) = (new T1[n], new T2[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i]) = ReadValue<T1, T2>(); }  return (v1, v2); }  public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int n) { var(v1, v2, v3) = (new T1[n], new T2[n], new T3[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i]) = ReadValue<T1, T2, T3>(); }  return (v1, v2, v3); }  public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int n) { var(v1, v2, v3, v4) = (new T1[n], new T2[n], new T3[n], new T4[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i]) = ReadValue<T1, T2, T3, T4>(); }  return (v1, v2, v3, v4); }  public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int n) { var(v1, v2, v3, v4, v5) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i]) = ReadValue<T1, T2, T3, T4, T5>(); }  return (v1, v2, v3, v4, v5); }  public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int n) { var(v1, v2, v3, v4, v5, v6) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i]) = ReadValue<T1, T2, T3, T4, T5, T6>(); }  return (v1, v2, v3, v4, v5, v6); }  public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int n) { var(v1, v2, v3, v4, v5, v6, v7) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n], new T7[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i], v7[i]) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); }  return (v1, v2, v3, v4, v5, v6, v7); } } }
namespace CpLibrary { public interface ISolver { public void Solve(); public void Run(); }  public abstract class SolverBase : ISolver { public abstract void Solve(); public abstract void Run(); public bool YesNo(bool condition) { Console.WriteLine(condition ? "Yes" : "No"); return condition; }  public bool YESNO(bool condition) { Console.WriteLine(condition ? "YES" : "NO"); return condition; }  public bool yesno(bool condition) { Console.WriteLine(condition ? "yes" : "no"); return condition; }  public static T SignOutput<T>(int x, T pos, T zero, T neg) => x == 0 ? zero : (x > 0 ? pos : neg); public static T[] CreateArray<T>(int n, Func<int, T> func) => Enumerable.Range(0, n).Select(p => func(p)).ToArray(); public static T[][] CreateArray<T>(int h, int w, Func<int, int, T> func) => Enumerable.Range(0, h).Select(i => Enumerable.Range(0, w).Select(j => func(i, j)).ToArray()).ToArray(); } }
namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}}
#endregion Expanded by https://github.com/naminodarie/SourceExpander
0