Submission #2431968
Source Code Expand
/** * File : C.cpp * Author : Kazune Takahashi * Created : 2018-4-28 22:56:15 * Powered by Visual Studio Code */ #include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> #include <random> // random_device rd; mt19937 mt(rd()); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> using namespace std; #define DEBUG 0 // change 0 -> 1 if we need debug. typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; // const int C = 1e6+10; // const ll M = 1000000007; const int MAX_SIZE = 1000010; const long long MOD = 1000000007; long long inv[MAX_SIZE]; long long fact[MAX_SIZE]; long long factinv[MAX_SIZE]; void init() { inv[1] = 1; for (int i=2; i<MAX_SIZE; i++) { inv[i] = ((MOD - inv[MOD%i]) * (MOD/i))%MOD; } fact[0] = factinv[0] = 1; for (int i=1; i<MAX_SIZE; i++) { fact[i] = (i * fact[i-1])%MOD; factinv[i] = (inv[i] * factinv[i-1])%MOD; } } long long C(int n, int k) { if (n >=0 && k >= 0 && n-k >= 0) { return ((fact[n] * factinv[k])%MOD * factinv[n-k])%MOD; } return 0; } long long power(long long x, long long n) { if (n == 0) { return 1; } else if (n%2 == 1) { return (x * power(x, n-1)) % MOD; } else { long long half = power(x, n/2); return (half * half) % MOD; } } long long gcm(long long a, long long b) { if (a < b) { return gcm(b, a); } if (b == 0) return a; return gcm(b, a%b); } ll N; ll Ika[200010]; int main() { init(); cin >> N; Ika[0] = Ika[1] = 0; if (N == 2) { cout << 1 << endl; return 0; } for (auto A = 2; A <= N - 1; A++) { ll x = N - 1 - A; if (x >= 0 && A >= 0) { Ika[A] = ((C(A - 1, N - 1 - A) * fact[x]) % MOD * fact[A]) % MOD; if (N < 100) { cerr << "Ika[" << A << "] = " << Ika[A] << endl; } } } ll ans = 0; for (ll A = 1; A <= N - 1; A++) { ans += (A * (Ika[A] + MOD - Ika[A - 1])) % MOD; ans %= MOD; } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Painting Machines |
User | kazunetakahashi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2438 Byte |
Status | WA |
Exec Time | 50 ms |
Memory | 25216 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 35 ms | 23680 KB |
sample_02.txt | AC | 35 ms | 23680 KB |
sample_03.txt | AC | 35 ms | 23680 KB |
sample_04.txt | AC | 37 ms | 24448 KB |
subtask_1_01.txt | AC | 35 ms | 23680 KB |
subtask_1_02.txt | WA | 50 ms | 25216 KB |
subtask_1_03.txt | WA | 47 ms | 25216 KB |
subtask_1_04.txt | WA | 46 ms | 25216 KB |
subtask_1_05.txt | WA | 41 ms | 25216 KB |
subtask_1_06.txt | WA | 39 ms | 25216 KB |
subtask_1_07.txt | WA | 41 ms | 25216 KB |
subtask_1_08.txt | AC | 36 ms | 24320 KB |
subtask_1_09.txt | WA | 39 ms | 25216 KB |
subtask_1_10.txt | WA | 42 ms | 25216 KB |
subtask_1_11.txt | WA | 44 ms | 25216 KB |
subtask_1_12.txt | WA | 48 ms | 25216 KB |
subtask_1_13.txt | WA | 48 ms | 25216 KB |
subtask_1_14.txt | WA | 48 ms | 25216 KB |
subtask_1_15.txt | WA | 48 ms | 25216 KB |
subtask_1_16.txt | WA | 48 ms | 25216 KB |