結果

問題 No.1226 I hate Robot Arms
ユーザー kakel-san
提出日時 2025-03-20 00:58:44
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 3,637 bytes
コンパイル時間 10,305 ms
コンパイル使用メモリ 173,772 KB
実行使用メモリ 51,232 KB
最終ジャッジ日時 2025-03-20 00:59:01
合計ジャッジ時間 15,102 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other TLE * 1 -- * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 ミリ秒)。
  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 static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, q) = (c[0], c[1]);
        var query = NArr(q);

        var len = Enumerable.Repeat(1, n + 1).ToArray();
        var dir = new int[n + 1];
        // var sq = (int)Math.Sqrt(q) + 1;
        var sq = q;
        var x = new double[n + 1];
        var y = new double[n + 1];
        var cdir = new int[n + 1];
        var ans = new List<string>();
        for (var i = 0; i < q; i += sq)
        {
            for (var j = 0; j < n; ++j)
            {
                cdir[j + 1] = cdir[j] + dir[j + 1];
                x[j + 1] = x[j] + len[j + 1] * Math.Cos(cdir[j + 1] * Math.PI / 180);
                y[j + 1] = y[j] + len[j + 1] * Math.Sin(cdir[j + 1] * Math.PI / 180);
            }
            // WriteLine($"x: {string.Join(" ", x)}");
            // WriteLine($"y: {string.Join(" ", y)}");
            // WriteLine($"cdir: {string.Join(" ", cdir)}");
            var set = new HashSet<int>();
            var rdic = new Dictionary<int, int>();
            for (var j = 0; j < sq; ++j)
            {
                if (query[i + j][0] == 1)
                {
                    rdic[query[i + j][1]] = cdir[query[i + j][1]];
                }
                else if (query[i + j][0] == 2)
                {
                    set.Add(query[i + j][1]);
                }
            }
            for (var j = 0; j < sq; ++j)
            {
                if (query[i + j][0] == 0)
                {
                    var pos = query[i + j][1];
                    var nr = query[i + j][2];
                    foreach (var li in set) if (li >= pos)
                    {
                        (x[li], y[li]) = Round(x[li], y[li], x[pos - 1], y[pos - 1], nr - dir[pos]);
                    }
                    foreach (var ri in rdic) if (ri.Key >= pos) rdic[ri.Key] += nr - dir[pos];
                    dir[pos] = nr;
                }
                else if (query[i + j][0] == 1)
                {
                    var pos = query[i + j][1];
                    var nl = query[i + j][2];
                    foreach (var li in set) if (li >= pos)
                    {
                        x[li] += (nl - len[pos]) * Math.Cos(rdic[pos] * Math.PI / 180);
                        y[li] += (nl - len[pos]) * Math.Sin(rdic[pos] * Math.PI / 180);
                    }
                    len[pos] = nl;
                }
                else
                {
                    ans.Add($"{x[query[i + j][1]]:0.00000000} {y[query[i + j][1]]:0.00000000}");
                }
            // WriteLine($"x: {string.Join(" ", x)}");
            // WriteLine($"y: {string.Join(" ", y)}");
            }
        }
        WriteLine(string.Join("\n", ans));
    }
    static (double x, double y) Round(double x, double y, double cx, double cy, int dr)
    {
        var len = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
        var nr = Math.Atan2(y - cy, x - cx) + dr * Math.PI / 180;
        // WriteLine($"Round  ({x}, {y}) from ({cx}, {cy}) r: {Math.Atan2(y - cy, x - cx)} + {dr}");
        return (cx + len * Math.Cos(nr), cy + len * Math.Sin(nr));
    }
}
0