結果

問題 No.3437 [Cherry 8th Tune C] Silhouette
コンテスト
ユーザー tobisatis
提出日時 2026-01-23 23:53:41
言語 C#
(.NET 10.0.101)
結果
TLE  
実行時間 -
コード長 5,123 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,036 ms
コンパイル使用メモリ 170,596 KB
実行使用メモリ 81,736 KB
最終ジャッジ日時 2026-01-24 00:00:17
合計ジャッジ時間 24,989 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other TLE * 1 -- * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (132 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

#nullable enable

using System.Numerics;

#region
var (_input, _iter) = (Array.Empty<string>(), 0);
T I<T>() where T : IParsable<T>
{
    while (_iter >= _input.Length) (_input, _iter) = (Console.ReadLine()!.Split(' '), 0);
    return T.Parse(_input[_iter++], null);
}
#endregion

static T[] Range<T>(int n, Func<T> F) => Enumerable.Range(0, n).Select(_ => F()).ToArray();

ModInt Solve()
{
    var ps = Range(3, () => Range(3, () => new Rational<Int128>(I<int>(), 1)));
    var l = Range(3, () => new Rational<Int128>(I<int>(), 1));
    foreach (var p in ps)
    {
        var pz = p[2];
        var lz = l[2];
        var dz = lz - pz;
        var k = lz / dz;
        for (var i = 0; i < 3; i++)
        {
            var pi = p[i];
            var li = l[i];
            var di = li - pi;
            p[i] = li + di * k;
        }
    }
    for (var i = 1; i < 3; i++) for (var j = 0; j < 3; j++)
    {
        ps[i][j] -= ps[0][j];
    }
    var area = (ps[1][0] * ps[2][1] - ps[1][1] * ps[2][0]) / (Int128)2;
    if (area < (Int128)0) area = -area; 
    var a = (ModInt)(long)(area.P % (Int128)ModInt.Mod);
    var b = (ModInt)(long)(area.Q % (Int128)ModInt.Mod);
    return a / b;
}

var ans = Range(I<int>(), Solve);
Console.WriteLine(string.Join(Environment.NewLine, ans));

readonly record struct ModInt
{
    public const int Mod = 998244353;
    int V { get; init; }
    public ModInt(long value)
    {
        var v = value % Mod;
        if (v < 0) v += Mod;
        V = (int)v;
    }
    static ModInt New(int value) => new(){ V = value };

    public static implicit operator ModInt(long v) => new(v);
    public static implicit operator int(ModInt modInt) => modInt.V;

    public static ModInt AdditiveIdentity => New(0);
    public static ModInt operator +(ModInt a, ModInt b)
    {
        var v = a.V + b.V;
        if (v >= Mod) v -= Mod;
        return New(v);
    }
    public ModInt AdditiveInverse()
    {
        if (V == 0) return AdditiveIdentity;
        return New(Mod - V);
    }
    public static ModInt operator -(ModInt a, ModInt b)
    {
        var v = a.V - b.V;
        if (v < 0) v += Mod;
        return New(v);
    }

    public static ModInt MultiplicativeIdentity => New(1);
    public static ModInt operator *(ModInt a, ModInt b) => New((int)((long)a.V * b.V % Mod));
    public ModInt MultiplicativeInverse() => V == 0 ? throw new DivideByZeroException() : Power(V, Mod - 2, Mod);
    public static ModInt operator /(ModInt a, ModInt b) => a * b.MultiplicativeInverse();

    static long Power(long v, ulong p, long mod)
    {
        var (res, k) = (1L, v);
        while (p > 0)
        {
            if ((p & 1) > 0) res = res * k % mod;
            k = k * k % mod;
            p >>= 1;
        }
        return res;
    }
    public ModInt Power(long p) => p < 0 ? MultiplicativeInverse().Power(-p) : Power(V, (ulong)p, Mod);

    public override string ToString() => V.ToString();
}

readonly record struct Rational<T> :
    IAdditiveIdentity<Rational<T>, Rational<T>>,
    IAdditionOperators<Rational<T>, Rational<T>, Rational<T>>,
    ISubtractionOperators<Rational<T>, Rational<T>, Rational<T>>,
    IUnaryNegationOperators<Rational<T>, Rational<T>>,
    IMultiplicativeIdentity<Rational<T>, Rational<T>>,
    IMultiplyOperators<Rational<T>, Rational<T>, Rational<T>>,
    IDivisionOperators<Rational<T>, Rational<T>, Rational<T>>,
    IComparable<Rational<T>>,
    IEqualityOperators<Rational<T>, Rational<T>, bool>,
    IComparisonOperators<Rational<T>, Rational<T>, bool>
    where T : IBinaryInteger<T>
{
    public T P { get; private init; }
    public T Q { get; private init; }
    public Rational(T p, T q)
    {
        if (q == T.Zero) throw new DivideByZeroException();
        if (q < T.Zero) (p, q) = (-p, -q);
        var (x, y) = (T.Abs(p), q);
        while (y > T.Zero) (x, y) = (y, x % y);
        (P, Q) = (p / x, q / x);
    }
    public Rational(T p) { (P, Q) = (p, T.One); }
    public static Rational<T> AdditiveIdentity => new(T.Zero); 
    public static Rational<T> MultiplicativeIdentity => new(T.One);

    public static implicit operator Rational<T>(T i) => new(i);
    public static Rational<T> operator -(Rational<T> r) => new(-r.P, r.Q);
    public static Rational<T> operator +(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.Q + r1.Q * r2.P, r1.Q * r2.Q);
    public static Rational<T> operator -(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.Q - r1.Q * r2.P, r1.Q * r2.Q);
    public static Rational<T> operator *(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.P, r1.Q * r2.Q);
    public static Rational<T> operator /(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.Q, r1.Q * r2.P);
    public static bool operator <(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) < 0;
    public static bool operator <=(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) <= 0;
    public static bool operator >(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) > 0;
    public static bool operator >=(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) >= 0;
    public int CompareTo(Rational<T> r) => (P * r.Q).CompareTo(Q * r.P);
}
0