Submission #172592


Source Code Expand

Copy
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int,int> pii;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
template <class F, class T> void convert(const F &f, T &t){	stringstream ss; ss << f; ss >> t;}


const int mod = 1000000007;

ll f(ll a, ll b){
	ll res = 1;
	for(ll i=a;i<=b;i++){
		res = res * i % mod;
	}
	return res;
}

ll modpow(ll x, ll n){	//冪乗法
	ll res = 1;
	while(n){
		if(n & 1) res = res * x % mod;
		n >>= 1;
		x = x * x % mod;
	}
	return res;
}

bool solve(){
	int n;
	cin>> n;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin>> a[i];
	
	ll ans = 1;
	int pre = 0, nex = 0;
	for(int i=0;i<n;i++){
		if(a[i] == -1){
			for(int j=i+1;j<n;j++){
				if(a[j] != -1){
					nex = j;
					break;
				}
			}
			ll x = a[nex] - a[pre];
			ll y = nex - pre - 1;
			ans = ans * f(x+1, x+y) % mod;
			ans = ans * modpow(f(1, y), mod - 2) % mod;			// X/Y ≡ X*(Y^(p-2))
			i = nex;
		}
		pre = i;
	}
	
	cout<< ans<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	solve();
	return 0;
}

 

Submission Info

Submission Time
Task C - タコヤ木
User yokabb
Language C++ (G++ 4.6.4)
Score 100
Code Size 1551 Byte
Status AC
Exec Time 23 ms
Memory 924 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 22 ms 792 KB
sample_02.txt AC 22 ms 720 KB
sample_03.txt AC 22 ms 920 KB
subtask1_01.txt AC 21 ms 920 KB
subtask1_02.txt AC 21 ms 784 KB
subtask1_03.txt AC 22 ms 920 KB
subtask1_04.txt AC 22 ms 808 KB
subtask1_05.txt AC 21 ms 920 KB
subtask1_06.txt AC 21 ms 792 KB
subtask1_07.txt AC 21 ms 792 KB
subtask1_08.txt AC 21 ms 916 KB
subtask1_09.txt AC 21 ms 912 KB
subtask1_10.txt AC 22 ms 796 KB
subtask1_11.txt AC 23 ms 796 KB
subtask1_12.txt AC 23 ms 796 KB
subtask2_01.txt AC 20 ms 920 KB
subtask2_02.txt AC 22 ms 796 KB
subtask2_03.txt AC 21 ms 920 KB
subtask2_04.txt AC 22 ms 792 KB
subtask2_05.txt AC 20 ms 920 KB
subtask2_06.txt AC 21 ms 788 KB
subtask2_07.txt AC 21 ms 916 KB
subtask2_08.txt AC 23 ms 848 KB
subtask2_09.txt AC 22 ms 796 KB
subtask2_10.txt AC 22 ms 796 KB
subtask2_11.txt AC 20 ms 912 KB
subtask2_12.txt AC 23 ms 912 KB
subtask3_01.txt AC 21 ms 908 KB
subtask3_02.txt AC 22 ms 792 KB
subtask3_03.txt AC 21 ms 924 KB
subtask3_04.txt AC 23 ms 924 KB
subtask3_05.txt AC 21 ms 920 KB
subtask3_06.txt AC 22 ms 912 KB
subtask3_07.txt AC 22 ms 816 KB
subtask3_08.txt AC 22 ms 812 KB
subtask3_09.txt AC 20 ms 916 KB
subtask3_10.txt AC 23 ms 920 KB
subtask3_11.txt AC 23 ms 912 KB
subtask3_12.txt AC 21 ms 920 KB