結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-10 00:29:48
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 767 ms / 3,000 ms
コード長 2,954 bytes
コンパイル時間 6,894 ms
コンパイル使用メモリ 156,680 KB
実行使用メモリ 182,224 KB
最終ジャッジ日時 2023-12-10 00:30:07
合計ジャッジ時間 19,713 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
34,724 KB
testcase_01 AC 121 ms
34,724 KB
testcase_02 AC 142 ms
34,724 KB
testcase_03 AC 317 ms
34,852 KB
testcase_04 AC 234 ms
34,852 KB
testcase_05 AC 130 ms
34,724 KB
testcase_06 AC 315 ms
34,852 KB
testcase_07 AC 279 ms
34,852 KB
testcase_08 AC 153 ms
34,724 KB
testcase_09 AC 219 ms
34,852 KB
testcase_10 AC 281 ms
34,852 KB
testcase_11 AC 146 ms
34,724 KB
testcase_12 AC 329 ms
34,852 KB
testcase_13 AC 361 ms
34,852 KB
testcase_14 AC 329 ms
34,852 KB
testcase_15 AC 315 ms
34,852 KB
testcase_16 AC 319 ms
34,852 KB
testcase_17 AC 318 ms
34,852 KB
testcase_18 AC 375 ms
34,852 KB
testcase_19 AC 380 ms
34,852 KB
testcase_20 AC 366 ms
34,852 KB
testcase_21 AC 388 ms
34,852 KB
testcase_22 AC 767 ms
34,852 KB
testcase_23 AC 759 ms
34,852 KB
testcase_24 AC 758 ms
34,852 KB
testcase_25 AC 727 ms
34,852 KB
testcase_26 AC 767 ms
34,852 KB
testcase_27 AC 121 ms
34,724 KB
testcase_28 AC 123 ms
34,852 KB
testcase_29 AC 652 ms
34,852 KB
testcase_30 AC 217 ms
34,852 KB
testcase_31 AC 340 ms
182,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (117 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 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 m = NN;
        var g = NList;
        var h = NList;
        var q = NN;
        var query = NArr(q);
        var first = new List<long>[15];
        var second = new List<long>[15];
        for (var i = 0; i < 15; ++i)
        {
            first[i] = new List<long>();
            second[i] = new List<long>();
        }
        var bitmax = 1 << 14;
        for (var b = 0; b < bitmax; ++b)
        {
            var tmp = b;
            var gcnt = 0;
            var fsum = 0L;
            var ssum = 0L;
            for (var i = 0; i < 14; ++i)
            {
                if (tmp % 2 == 0)
                {
                    fsum += g[i];
                    ssum += g[i + 14];
                    ++gcnt;
                }
                else
                {
                    fsum += h[i];
                    ssum += h[i + 14];
                }
                tmp >>= 1;
            }
            first[gcnt].Add(fsum % m);
            second[gcnt].Add(ssum % m);
        }
        for (var i = 0; i < second.Length; ++i) second[i].Sort();
        var ans = new long[q];
        for (var i = 0; i < q; ++i)
        {
            var k = query[i][0];
            var x = query[i][1];
            for (var j = 0; j < first.Length; ++j)
            {
                var sg = k - j;
                if (sg < 0 || sg >= second.Length) continue;
                if (second[sg].Count == 0) continue;
                foreach (var fs in first[j])
                {
                    var add = 0;
                    if (fs <= x) add += LowerBound(0, m - fs, second[sg]) - LowerBound(0, x - fs, second[sg]);
                    else add += LowerBound(0, m - fs, second[sg]) + second[sg].Count - LowerBound(0, m + x - fs, second[sg]);
                    ans[i] += add;
                }
            }
        }
        WriteLine(string.Join("\n", ans));
    }
    // 昇順にソートされたリストの left 以降から、 min 以上の値のインデックスを取得する
    // min 以上の値がない場合 list.Length を返す(OutOfRangeに注意)
    static int LowerBound(int left, long min, List<long> list)
    {
        if (list[left] >= min) return left;
        var ng = left;
        var ok = list.Count;
        while (ok - ng > 1)
        {
            var center = (ng + ok) / 2;
            if (list[center] < min) ng = center;
            else ok = center;
        }
        return ok;
    }
}
0