結果
問題 |
No.3257 +|+
|
ユーザー |
|
提出日時 | 2025-09-06 00:04:15 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 2,366 ms / 3,000 ms |
コード長 | 1,450 bytes |
コンパイル時間 | 10,285 ms |
コンパイル使用メモリ | 170,708 KB |
実行使用メモリ | 480,812 KB |
最終ジャッジ日時 | 2025-09-06 00:05:51 |
合計ジャッジ時間 | 61,761 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (114 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
#nullable enable #region var _input = Array.Empty<string>(); var _iter = 0; string String() { while (_iter >= _input.Length) (_input, _iter) = (Console.ReadLine()!.Split(' '), 0); return _input[_iter++]; } T I<T>() where T : IParsable<T> => T.Parse(String(), null); #endregion T[] Range<T>(int n, Func<T> F) => Enumerable.Range(0, n).Select(_ => F()).ToArray(); var n = I<int>(); var az = Range(n, I<int>); var l = az.Max() * 2; var ans = 0L; var bag = new Bag<long>(); for (var i = 1; i <= n; i++) { var a = az[i - 1]; var d = 0; var k = 0; while (true) { d += i; k++; if (d > l) break; long v = d - a; v <<= 20; ans += bag[v + k]; bag.Add(-v + k); } } Console.WriteLine(ans); class Bag<K> where K : notnull { readonly Dictionary<K, int> _dictionary = new(); public void Add(K key) { var dictionary = _dictionary; if (dictionary.TryGetValue(key, out var count)) dictionary[key] = count + 1; else dictionary[key] = 1; } public bool Remove(K key) { var dictionary = _dictionary; if (!dictionary.TryGetValue(key, out var count)) return false; if (count == 1) dictionary.Remove(key); else dictionary[key] = count - 1; return true; } public int this[K key] => _dictionary.TryGetValue(key, out var count) ? count : 0; public int CountKeys => _dictionary.Count; }