Submission #172899


Source Code Expand

Copy
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math

NUM_MOD =1000000007

N = int(sys.stdin.readline().rstrip())
As = map(int, sys.stdin.readline().rstrip().split())

def get_sigma_fast(start, end, num):
    # calcurate (end-start+num C end-start)
    # = prod(xrange(num, end-start+num)) / prod(xrange(num)) / prod(xrange(end-start))
    ans = 1    
    for i in xrange(num, end-start+num+1):
        ans = (ans * i) % NUM_MOD

    # according to Fermat,
    # ( ans / prod(xrange(num)) ) % NUM_MOD
    # = ( ans * prod(xrange(num)) ** (NUM_MOD-2) ) % NUM_MOD
    num_permutaion = 1
    for i in xrange(1, num+1):
        num_permutaion = (num_permutaion*i) % NUM_MOD
    ans = ans * pow(num_permutaion, NUM_MOD-2, NUM_MOD)

    # according to Fermat, ...
    range_permutation = 1
    for i in xrange(1, end-start+1):
        range_permutation = (range_permutation*i) % NUM_MOD
    ans = ans * pow(range_permutation, NUM_MOD-2, NUM_MOD)
    return ans


def get_sigma(start, end, num):
    n_range = end-start+1
    memo = [1 for i in xrange(n_range)]

    for i in xrange(num-1):
        memo = [sum(memo[:i+1])%NUM_MOD for i in xrange(n_range)]
        continue
        nexmemo = [memo[0]]
        for item in memo[1:]:
            nexmemo.append((nexmemo[-1] + item)%NUM_MOD)
        memo = nexmemo
        #print memo
    return sum(memo)
    

#print gamemap
#print ([(y, lim-y) for lim in xrange(D%2, D+1, 2) for y in xrange(lim+1)])
# print ([gamemap[y][lim-y]
#            for lim in xrange(D%2, D+1, 2) 
#            for y in xrange(lim+1)])

# print max([gamemap[y][lim-y]
#            for lim in xrange(D%2, D+1, 2) 
#            for y in xrange(lim+1)
#            if y < len(gamemap) and lim-y < len(gamemap[y])])

#print get_sigma(1, 3, 1)
#print get_sigma(1, 3, 2)
#print get_sigma(1, 3, 3)

last, now = 0, 0
is_counting = False
count = 0
ans = 1
for A in As:
    if A == -1:
        is_counting = True
        count += 1
    else:
        now, last = A, now
        if is_counting:
            #print last, now, count
            ans *= get_sigma_fast(last, now, count)
            ans = ans % NUM_MOD
            count = 0
            is_counting = False
print ans
exit(0)

Submission Info

Submission Time
Task C - タコヤ木
User hiking
Language Python (2.7.3)
Score 0
Code Size 2288 Byte
Status WA
Exec Time 2031 ms
Memory 3576 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 0 / 50 0 / 30 0 / 20
Status
AC × 2
TLE × 1
AC × 6
WA × 8
AC × 10
WA × 16
AC × 10
WA × 17
TLE × 9
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 48 ms 3376 KB
sample_02.txt AC 48 ms 3380 KB
sample_03.txt TLE 2030 ms 3500 KB
subtask1_01.txt AC 48 ms 3324 KB
subtask1_02.txt AC 47 ms 3328 KB
subtask1_03.txt AC 48 ms 3328 KB
subtask1_04.txt WA 49 ms 3376 KB
subtask1_05.txt WA 50 ms 3380 KB
subtask1_06.txt WA 50 ms 3376 KB
subtask1_07.txt WA 48 ms 3328 KB
subtask1_08.txt AC 48 ms 3312 KB
subtask1_09.txt WA 47 ms 3376 KB
subtask1_10.txt WA 48 ms 3360 KB
subtask1_11.txt WA 50 ms 3328 KB
subtask1_12.txt WA 51 ms 3368 KB
subtask2_01.txt AC 48 ms 3384 KB
subtask2_02.txt AC 48 ms 3324 KB
subtask2_03.txt AC 48 ms 3328 KB
subtask2_04.txt WA 50 ms 3428 KB
subtask2_05.txt WA 50 ms 3448 KB
subtask2_06.txt WA 49 ms 3372 KB
subtask2_07.txt WA 50 ms 3380 KB
subtask2_08.txt AC 49 ms 3368 KB
subtask2_09.txt WA 50 ms 3452 KB
subtask2_10.txt WA 51 ms 3372 KB
subtask2_11.txt WA 52 ms 3372 KB
subtask2_12.txt WA 52 ms 3384 KB
subtask3_01.txt AC 48 ms 3328 KB
subtask3_02.txt TLE 2031 ms 3508 KB
subtask3_03.txt TLE 2030 ms 3492 KB
subtask3_04.txt TLE 2030 ms 3552 KB
subtask3_05.txt TLE 2029 ms 3432 KB
subtask3_06.txt TLE 2029 ms 3500 KB
subtask3_07.txt TLE 2029 ms 3500 KB
subtask3_08.txt AC 49 ms 3384 KB
subtask3_09.txt WA 52 ms 3372 KB
subtask3_10.txt TLE 2029 ms 3576 KB
subtask3_11.txt TLE 2030 ms 3500 KB
subtask3_12.txt TLE 2029 ms 3500 KB