Contest Duration: - (local time) (90 minutes) Back to Home

Submission #171533

Source Code Expand

Copy
```#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int MOD = 1000000007;

// a,b の最大公約数と、ax + by = gcd(a,b) となる x,y を求める
long long extgcd(long long a, long long b, long long &x, long long &y) {
long long g = a;
if(b != 0){
g = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}else{
x = 1;
y = 0;
}
return g;
}

// ax ≡ gcd(a, m) (mod m) となる x を求める
// a, m が互いに素ならば、関数値は mod m での a の逆数となる
long long mod_inverse(long long a, long long m)
{
long long x, y;
extgcd(a, m, x, y);
return (x % m + m) % m;
}

// 組合せ
long long combination(int n, int r)
{
if(n < r)
return 0;
if(n-r < r)
r = n-r;
long long ret = 1;
for(int i=0; i<r; i++){
ret *= (n--);
ret %= MOD;
ret *= mod_inverse(i+1, MOD);
ret %= MOD;
}
return ret;
}

// 重複組合せ
long long homogeneous(int n, int r)
{
return combination(n+r-1,r);
}

int main()
{
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; ++i)
cin >> a[i];

int k = 0;
long long ret = 1;
for(int i=1; i<n; ++i){
if(a[i] != -1){
ret *= homogeneous(a[i] - a[k] + 1, i - k - 1);
ret %= MOD;
k = i;
}
}
cout << ret << endl;

return 0;
}```

#### Submission Info

Submission Time 2014-05-17 21:11:35+0900 C - タコヤ木 mamekin C++ (G++ 4.6.4) 100 1803 Byte AC 23 ms 924 KB

#### Judge Result

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
Case Name Status Exec Time Memory
sample_01.txt AC 23 ms 792 KB
sample_02.txt AC 19 ms 916 KB
sample_03.txt AC 20 ms 916 KB
subtask1_01.txt AC 23 ms 796 KB
subtask1_02.txt AC 19 ms 916 KB
subtask1_03.txt AC 22 ms 796 KB
subtask1_04.txt AC 22 ms 920 KB
subtask1_05.txt AC 22 ms 796 KB
subtask1_06.txt AC 22 ms 796 KB
subtask1_07.txt AC 22 ms 792 KB
subtask1_08.txt AC 22 ms 920 KB
subtask1_09.txt AC 22 ms 796 KB
subtask1_10.txt AC 21 ms 796 KB
subtask1_11.txt AC 22 ms 792 KB
subtask1_12.txt AC 22 ms 924 KB
subtask2_01.txt AC 22 ms 916 KB
subtask2_02.txt AC 21 ms 920 KB
subtask2_03.txt AC 21 ms 920 KB
subtask2_04.txt AC 22 ms 920 KB
subtask2_05.txt AC 23 ms 796 KB
subtask2_06.txt AC 23 ms 800 KB
subtask2_07.txt AC 22 ms 796 KB
subtask2_08.txt AC 21 ms 920 KB
subtask2_09.txt AC 21 ms 796 KB
subtask2_10.txt AC 21 ms 924 KB
subtask2_11.txt AC 22 ms 920 KB
subtask2_12.txt AC 21 ms 912 KB
subtask3_01.txt AC 22 ms 792 KB
subtask3_02.txt AC 22 ms 920 KB
subtask3_03.txt AC 22 ms 796 KB
subtask3_04.txt AC 22 ms 808 KB
subtask3_05.txt AC 21 ms 800 KB
subtask3_06.txt AC 23 ms 908 KB
subtask3_07.txt AC 22 ms 916 KB
subtask3_08.txt AC 23 ms 812 KB
subtask3_09.txt AC 22 ms 908 KB
subtask3_10.txt AC 22 ms 812 KB
subtask3_11.txt AC 22 ms 812 KB
subtask3_12.txt AC 22 ms 916 KB