結果
問題 | No.801 エレベーター |
ユーザー | ひばち |
提出日時 | 2019-11-17 22:42:38 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 11,668 bytes |
コンパイル時間 | 1,200 ms |
コンパイル使用メモリ | 120,616 KB |
実行使用メモリ | 55,740 KB |
最終ジャッジ日時 | 2024-09-25 06:11:36 |
合計ジャッジ時間 | 6,169 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
32,296 KB |
testcase_01 | AC | 32 ms
27,372 KB |
testcase_02 | AC | 33 ms
25,196 KB |
testcase_03 | AC | 122 ms
30,420 KB |
testcase_04 | AC | 123 ms
28,160 KB |
testcase_05 | AC | 120 ms
28,032 KB |
testcase_06 | AC | 122 ms
30,196 KB |
testcase_07 | AC | 125 ms
30,088 KB |
testcase_08 | AC | 125 ms
28,420 KB |
testcase_09 | AC | 122 ms
28,160 KB |
testcase_10 | AC | 124 ms
26,164 KB |
testcase_11 | AC | 121 ms
28,040 KB |
testcase_12 | AC | 124 ms
28,288 KB |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; using Number = System.Int64; class Solver { Scanner sc = new Scanner(); // public void Solve() { int N, M, K; sc.Make(out N, out M, out K); var lrs = sc.ArrInt2D(M); var dp = new SegmentTree<ModInt>(N, 0, (a, b) => a + b); dp.Update(0, 1); while (K-- > 0) { var newdp = new SegmentTree<ModInt>(N, 0, (a, b) => a + b, (a, b) => a + b); foreach (var lr in lrs) { int l = lr[0]-1, r = lr[1]; newdp.Update(l, r, dp.Query(l, r)); } for (var i = 0; i < N; i++) dp[i] = newdp.Query(i); dp.All_Update(); } WriteLine(dp.Query(N - 1, N)); } } public class SegmentTree<T> { protected readonly T[] item; protected readonly int num; protected readonly Func<T, T, T> func; protected readonly Func<T, T, T> updateFunc; protected readonly T minT; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Parent(int index) => (index - 1) >> 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Left(int index) => (index << 1) + 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + num - 1]; } set { item[i + num - 1] = value; } } public SegmentTree(int num, T minT, Func<T, T, T> func, Func<T, T, T> updateFunc = null) { this.func = func; this.num = 1; this.minT = minT; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (this.num <= num) this.num <<= 1; item = new T[2 * this.num - 1]; for (var i = 0; i < 2 * this.num - 1; i++) item[i] = minT; } public void Update(int index, T value) { index += num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = func(item[Left(index)], item[Right(index)]); } } public virtual void Update(int left, int right, T value) => Update(left, right, 0, 0, num, value); protected virtual void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = num - 2; i >= 0; i--) item[i] = func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += num - 1; var value = func(minT, item[index]); while (index > 0) { index = Parent(index); value = func(value, item[index]); } return value; } public virtual T Query(int left, int right) => Query(left, right, 0, 0, num); protected virtual T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return minT; if (left <= l && r <= right) return item[k]; else return func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } /// <summary> /// check(func(item[st]...item[i]))がtrueとなる最小のi /// </summary> public int Find(int st, Func<T, bool> check) { var x = minT; return Find(st, check, ref x, 0, 0, num); } private int Find(int st, Func<T, bool> check, ref T x, int k, int l, int r) { if (l + 1 == r) { x = func(x, item[k]); return check(x) ? k - num + 1 : -1; } var m = (l + r) >> 1; if (m <= st) return Find(st, check, ref x, Right(k), m, r); if (st <= l && !check(func(x, item[k]))) { x = func(x, item[k]); return -1; } var xl = Find(st, check, ref x, Left(k), l, m); if (xl >= 0) return xl; return Find(st, check, ref x, Right(k), m, r); } } public struct ModInt { public const long MOD = (int)1e9 + 7; //public const long MOD = 998244353; public long num { get; set; } public ModInt(long n = 0) { num = n; } private static ModInt[] _fac;//階乗 private static ModInt[] _inv;//逆数 private static ModInt[] _facrev;//1/(i!) public override string ToString() => num.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= MOD) l.num -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.num * r.num % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.num; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void CombBuild(int n) { _fac = new ModInt[n + 1]; _facrev = new ModInt[n + 1]; _inv = new ModInt[n + 1]; _inv[1] = 1; _fac[0] = _fac[1] = 1; _facrev[0] = _facrev[1] = 1; for (var i = 2; i <= n; i++) { _fac[i] = _fac[i - 1] * i; _inv[i] = MOD - _inv[MOD % i] * (MOD / i); _facrev[i] = _facrev[i - 1] * _inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => _fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Div(ModInt n) => _inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacRev(ModInt n) => _facrev[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = _fac[n]; calc = calc * _facrev[r]; calc = calc * _facrev[n - r]; return calc; } } #region Template public class Template { static void Main(string[] args) { Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() { } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() { } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion