結果

問題 No.1932 動く点 P / Moving Point P
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-03 00:05:40
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 817 ms / 6,000 ms
コード長 2,707 bytes
コンパイル時間 16,126 ms
コンパイル使用メモリ 157,528 KB
実行使用メモリ 242,716 KB
最終ジャッジ日時 2023-11-03 00:06:21
合計ジャッジ時間 36,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
33,568 KB
testcase_01 AC 350 ms
68,816 KB
testcase_02 AC 244 ms
62,144 KB
testcase_03 AC 403 ms
76,552 KB
testcase_04 AC 457 ms
77,228 KB
testcase_05 AC 498 ms
95,980 KB
testcase_06 AC 162 ms
56,224 KB
testcase_07 AC 817 ms
98,580 KB
testcase_08 AC 778 ms
102,360 KB
testcase_09 AC 674 ms
98,008 KB
testcase_10 AC 671 ms
98,120 KB
testcase_11 AC 690 ms
242,716 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (104 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static double[] NList => ReadLine().Split().Select(double.Parse).ToArray();
    static double[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var map = NArr(n);
        var q = NN;
        var query = NArr(q);
        var inlist = new List<(int i, int s, double x, double y)>();
        var outlist = new List<(int i, int t, double x, double y)>();
        for (var i = 0; i < q; ++i)
        {
            inlist.Add((i, (int)query[i][0] - 1, query[i][2], query[i][3]));
            outlist.Add((i, (int)query[i][1] - 1, query[i][2], query[i][3]));
        }
        inlist.Sort((l, r) => l.s.CompareTo(r.s));
        outlist.Sort((l, r) => l.t.CompareTo(r.t));
        var zero = new double[2];
        var vec = new double[] { 1, 0 };
        var pts = new double[q][];
        var ipos = 0;
        var opos = 0;
        var ans = new double[q][];
        for (var i = 0; i < n; ++i)
        {
            while (ipos < inlist.Count && inlist[ipos].s == i)
            {
                pts[inlist[ipos].i] = ToAbs(zero, vec, inlist[ipos].x, inlist[ipos].y);
                ++ipos;
            }
            var center = ToAbs(zero, vec, map[i][0], map[i][1]);
            zero = Rotate(new double[] { zero[0] - center[0], zero[1] - center[1] }, - map[i][2]);
            zero[0] += center[0];
            zero[1] += center[1];
            vec = Rotate(vec, - map[i][2]);
            while (opos < outlist.Count && outlist[opos].t == i)
            {
                ans[outlist[opos].i] = ToRel(zero, vec, pts[outlist[opos].i]);
                ++opos;
            }
        }
        WriteLine(string.Join("\n", ans.Select(ai => string.Join(" ", ai))));
    }
    static double[] ToAbs(double[] zero, double[] vec, double x, double y)
    {
        return new double[] { zero[0] + vec[0] * x - vec[1] * y, zero[1] + vec[1] * x + vec[0] * y };
    }
    static double[] ToRel(double[] zero, double[] vec, double[] a)
    {
        var rx = a[0] - zero[0];
        var ry = a[1] - zero[1];
        return new double[] { rx * vec[0] + ry * vec[1], - rx * vec[1] + ry * vec[0] };
    }
    static double[] Rotate(double[] a, double r)
    {
        var sin = Math.Sin(r * Math.PI / 180);
        var cos = Math.Cos(r * Math.PI / 180);
        return new double[] { a[0] * cos - a[1] * sin, a[0] * sin + a[1] * cos };
    }
}
0