Submission #172889


Source Code Expand

Copy
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static readonly int Mod = (int)1e9 + 7;

    void Solve()
    {
        int N = reader.Int();
        int[] A = reader.IntLine();
        int[] index = Enumerable.Range(0, N).Where(i => A[i] != -1).ToArray();
        long ans = 1;

        for (int i = 0; i < index.Length - 1; i++)
        {
            long r = index[i + 1] - index[i] - 1;
            long n = (A[index[i + 1]] - A[index[i]]) + r;
            ans = ans * C(n, r, Mod) % Mod;
        }

        Console.WriteLine(ans);
        Console.ReadLine();
    }

    static long C(long n, long r, long mod)
    {
        long y = 1, x = 1;
        r = Math.Min(r, n - r);

        for (int i = 0; i < r; i++)
        {
            y = (y * (n - i)) % mod;
            x = (x * (i + 1)) % mod;
        }
        x = ModPower(x, mod - 2, mod);

        return y * x % mod;
    }

    static long ModPower(long x, long n, long mod) // x ^ n
    {
        long res = 1;
        while (n > 0)
        {
            if ((n & 1) == 1) { res = (res * x) % mod; }
            x = (x * x) % mod;
            n >>= 1;
        }
        return res;
    }



    static void Main() { new Program().Solve(); }
    static Reader reader = new Reader(Console.In);

    class Reader
    {
        private readonly TextReader reader;
        private readonly char[] separator = new char[] { ' ' };
        private string[] s = new string[0];
        private int i;
        public Reader(TextReader r) { reader = r; }
        public bool HasNext() { return Enqueue(); }
        public string String() { return Dequeue(); }
        public int Int() { return int.Parse(Dequeue()); }
        public long Long() { return long.Parse(Dequeue()); }
        public double Double() { return double.Parse(Dequeue()); }
        public int[] IntLine() { return Array.ConvertAll(Line().Split(), int.Parse); }
        public int[] IntArray(int N) { return Enumerable.Range(0, N).Select(i => Int()).ToArray(); }
        public int[][] IntGrid(int H) { return Enumerable.Range(0, H).Select(i => IntLine()).ToArray(); }
        public string[] StringArray(int N) { return Enumerable.Range(0, N).Select(i => Line()).ToArray(); }
        public string Line() { return reader.ReadLine().Trim(); }
        private bool Enqueue()
        {
            if (i < s.Length) return true;
            string line = reader.ReadLine();
            if (string.IsNullOrEmpty(line)) return false;
            s = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return true;
        }
        private string Dequeue() { Enqueue(); return s[i++]; }
    }
}

Submission Info

Submission Time
Task C - タコヤ木
User eitaho
Language C# (Mono 2.10.8.1)
Score 100
Code Size 2818 Byte
Status AC
Exec Time 178 ms
Memory 8964 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 50 / 50 30 / 30 20 / 20
Status
AC × 3
AC × 14
AC × 26
AC × 36
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt
Subtask2 sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt
Subtask3 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask3_04.txt, subtask3_05.txt, subtask3_06.txt, subtask3_07.txt, subtask3_08.txt, subtask3_09.txt, subtask3_10.txt, subtask3_11.txt, subtask3_12.txt
Case Name Status Exec Time Memory
sample_01.txt AC 162 ms 8712 KB
sample_02.txt AC 163 ms 8588 KB
sample_03.txt AC 156 ms 8584 KB
subtask1_01.txt AC 159 ms 8724 KB
subtask1_02.txt AC 155 ms 8652 KB
subtask1_03.txt AC 159 ms 8704 KB
subtask1_04.txt AC 165 ms 8648 KB
subtask1_05.txt AC 169 ms 8636 KB
subtask1_06.txt AC 158 ms 8708 KB
subtask1_07.txt AC 166 ms 8696 KB
subtask1_08.txt AC 167 ms 8652 KB
subtask1_09.txt AC 163 ms 8580 KB
subtask1_10.txt AC 167 ms 8720 KB
subtask1_11.txt AC 167 ms 8720 KB
subtask1_12.txt AC 169 ms 8712 KB
subtask2_01.txt AC 159 ms 8588 KB
subtask2_02.txt AC 162 ms 8716 KB
subtask2_03.txt AC 161 ms 8580 KB
subtask2_04.txt AC 178 ms 8708 KB
subtask2_05.txt AC 166 ms 8832 KB
subtask2_06.txt AC 165 ms 8708 KB
subtask2_07.txt AC 164 ms 8848 KB
subtask2_08.txt AC 163 ms 8828 KB
subtask2_09.txt AC 169 ms 8716 KB
subtask2_10.txt AC 166 ms 8792 KB
subtask2_11.txt AC 169 ms 8844 KB
subtask2_12.txt AC 175 ms 8732 KB
subtask3_01.txt AC 159 ms 8580 KB
subtask3_02.txt AC 156 ms 8620 KB
subtask3_03.txt AC 164 ms 8584 KB
subtask3_04.txt AC 166 ms 8844 KB
subtask3_05.txt AC 162 ms 8708 KB
subtask3_06.txt AC 164 ms 8704 KB
subtask3_07.txt AC 164 ms 8688 KB
subtask3_08.txt AC 162 ms 8948 KB
subtask3_09.txt AC 164 ms 8840 KB
subtask3_10.txt AC 163 ms 8964 KB
subtask3_11.txt AC 159 ms 8840 KB
subtask3_12.txt AC 164 ms 8920 KB