結果

問題 No.2687 所により大雨
ユーザー 👑 kakel-sankakel-san
提出日時 2024-04-02 23:51:21
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 811 ms / 2,000 ms
コード長 3,279 bytes
コンパイル時間 9,598 ms
コンパイル使用メモリ 158,508 KB
実行使用メモリ 181,176 KB
最終ジャッジ日時 2024-04-02 23:51:44
合計ジャッジ時間 20,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
71,712 KB
testcase_01 AC 281 ms
71,708 KB
testcase_02 AC 278 ms
71,708 KB
testcase_03 AC 282 ms
71,708 KB
testcase_04 AC 285 ms
71,712 KB
testcase_05 AC 88 ms
33,060 KB
testcase_06 AC 89 ms
33,060 KB
testcase_07 AC 90 ms
33,060 KB
testcase_08 AC 89 ms
33,060 KB
testcase_09 AC 89 ms
33,060 KB
testcase_10 AC 793 ms
71,468 KB
testcase_11 AC 796 ms
71,472 KB
testcase_12 AC 762 ms
71,468 KB
testcase_13 AC 807 ms
71,464 KB
testcase_14 AC 769 ms
71,472 KB
testcase_15 AC 796 ms
71,464 KB
testcase_16 AC 770 ms
71,472 KB
testcase_17 AC 786 ms
71,468 KB
testcase_18 AC 811 ms
71,468 KB
testcase_19 AC 745 ms
71,468 KB
testcase_20 AC 91 ms
33,060 KB
testcase_21 AC 89 ms
33,060 KB
testcase_22 AC 91 ms
33,060 KB
testcase_23 AC 89 ms
33,060 KB
testcase_24 AC 113 ms
33,700 KB
testcase_25 AC 115 ms
33,700 KB
testcase_26 AC 116 ms
33,700 KB
testcase_27 AC 122 ms
33,700 KB
testcase_28 AC 116 ms
181,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (105 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();
        // Test();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var nmap = NArr(n);
        var mmap = NArr(m);
        var k = NN;
        var p = NList;
        WriteLine(string.Join(" ", Rain(n, m, nmap, mmap, k, p)));
    }
    static int[] Rain(int n, int m, int[][] nmap, int[][] mmap, int k, int[] p)
    {
        var ans = Enumerable.Repeat(1, k).ToArray();
        var nlist = new List<(long pos, int flg)> { (-1_000_000_001, 0), (1_000_000_001, 0) };
        for (var i = 0; i < n; ++i)
        {
            nlist.Add((-nmap[i][0], 2));
            nlist.Add((-nmap[i][1], 1));
        }
        nlist.Sort((l, r) => {
            var d = l.pos.CompareTo(r.pos);
            if (d != 0) return d;
            return l.flg.CompareTo(r.flg);
        });
        for (var i = 0; i + 1 < nlist.Count; ++i)
        {
            if (nlist[i].flg == nlist[i + 1].flg)
            {
                return ans;
            }
        }
        var mlist = new List<(long pos, int flg)>();
        for (var i = 0; i < m; ++i)
        {
            mlist.Add((mmap[i][0], 1));
            mlist.Add((mmap[i][1], 2));
        }
        mlist.Sort((l, r) => {
            var d = l.pos.CompareTo(r.pos);
            if (d != 0) return d;
            return l.flg.CompareTo(r.flg);
        });
        for (var i = 0; i + 1 < mlist.Count; ++i)
        {
            if (mlist[i].flg == mlist[i + 1].flg)
            {
                return ans;
            }
        }
        for (var i = 0; i < k; ++i)
        {
            var flg = false;
            for (var j = 0; j < mlist.Count; j += 2)
            {
                var btime = mlist[j].pos - p[i] - p[i];
                var etime = mlist[j + 1].pos - p[i] - p[i];
                var bpos = LowerBound(0, btime, nlist);
                var epos = LowerBound(0, etime, nlist);
                if (bpos != epos)
                {
                    flg = true;
                    break;
                }
                if (nlist[bpos].flg == 2)
                {
                    flg = true;
                    break;
                }
                if (nlist[epos].flg == 1 && etime == nlist[epos].pos)
                {
                    flg = true;
                    break;
                }
            }
            if (!flg) ans[i] = 0;
        }
        return ans;
    }
    static int LowerBound(int left, long min, IList<(long pos, int flg)> list)
    {
        if (list[left].pos >= min) return left;
        var ng = left;
        var ok = list.Count;
        while (ok - ng > 1)
        {
            var center = (ng + ok) / 2;
            if (list[center].pos < min) ng = center;
            else ok = center;
        }
        return ok;
    }
}
0