結果
問題 |
No.1226 I hate Robot Arms
|
ユーザー |
|
提出日時 | 2025-03-20 01:19:56 |
言語 | C# (.NET 8.0.404) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,063 bytes |
コンパイル時間 | 20,269 ms |
コンパイル使用メモリ | 170,220 KB |
実行使用メモリ | 225,892 KB |
最終ジャッジ日時 | 2025-03-20 01:20:57 |
合計ジャッジ時間 | 48,422 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 TLE * 10 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (152 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
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 && i + j < q; ++j) { if (query[i + j][0] == 0) { set.Add(query[i + j][1] - 1); } else if (query[i + j][0] == 1) { rdic[query[i + j][1]] = cdir[query[i + j][1]]; } else { set.Add(query[i + j][1]); } } for (var j = 0; j < sq && i + j < q; ++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($"({x[705]}, {y[705]})"); } } 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; // return (cx + len * Math.Cos(nr), cy + len * Math.Sin(nr)); var rx = x - cx; var ry = y - cy; var cos = Math.Cos(dr * Math.PI / 180); var sin = Math.Sin(dr * Math.PI / 180); // WriteLine($"{x} {y} {cx} {cy} {dr} -> ({cx + rx * cos - ry * sin}, {cy + rx * sin + ry * cos})"); return (cx + rx * cos - ry * sin, cy + rx * sin + ry * cos); } }