結果
問題 |
No.1742 Binary Indexed Train
|
ユーザー |
|
提出日時 | 2023-12-29 14:20:55 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 367 ms / 3,000 ms |
コード長 | 1,693 bytes |
コンパイル時間 | 6,821 ms |
コンパイル使用メモリ | 167,448 KB |
実行使用メモリ | 217,952 KB |
最終ジャッジ日時 | 2024-09-27 16:05:43 |
合計ジャッジ時間 | 16,575 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (90 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/
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); static long[][] 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) = ((int)c[0], (int)c[1]); var query = NArr(q); var ans = new List<int>(q); foreach (var que in query) { var s = Pop(que[0]); var t = Pop(que[1]); while (s.Count > 0 && t.Count > 0 && s[0] == t[0]) { s.RemoveAt(0); t.RemoveAt(0); } var ai = 0; while (true) { if (s.Count == 0 || (s.Count == 1 && s[0] == t[0])) break; ++ai; var cur = s[^1]; s.RemoveAt(s.Count - 1); while (s.Count > 0 && s[^1] == cur + 1) { ++cur; s.RemoveAt(s.Count - 1); } s.Add(cur + 1); } ans.Add(ai + t.Count - s.Count); } WriteLine(string.Join("\n", ans)); } static List<int> Pop(long a) { var ans = new List<int>(); var pos = 0; while (a > 0) { if (a % 2 == 1) ans.Add(pos); a >>= 1; ++pos; } ans.Reverse(); return ans; } }