problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } sort(x.begin(), x.end()); int ans = 100 * 100 * 100 + 1; for (int i = x.at(1); i <= x.at(x.size() - 1); i++) { int tmp = 0; for (int j = 0; j < n; j++) { tmp += (i - x.at(j)) * (i - x.at(j)); } ans = min(tmp, ans); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } sort(x.begin(), x.end()); int ans = 100 * 100 * 100 + 1; for (int i = x.at(0); i <= x.at(x.size() - 1); i++) { int tmp = 0; for (int j = 0; j < n; j++) { tmp += (i - x.at(j)) * (i - x.at(j)); } ans = min(tmp, ans); } cout << ans << endl; }
replace
11
12
11
12
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, count = 0; cin >> N; if (N == 1) { cout << 0; exit(0); } vector<int> X(N, 0); for (int i = 0; i < N; i++) { cin >> X.at(i); } sort(X.begin(), X.end()); vector<int> A(X.at(N - 1) - X.at(0) - 1, 0); for (int i = X.at(0) + 1; i < X.at(N - 1); i++) { for (int j = 0; j < N; j++) { A.at(count) += (X.at(j) - i) * (X.at(j) - i); } count++; } sort(A.begin(), A.end()); cout << A.at(0); }
#include <bits/stdc++.h> using namespace std; int main() { int N, count = 0; cin >> N; if (N == 1) { cout << 0; exit(0); } vector<int> X(N, 0); for (int i = 0; i < N; i++) { cin >> X.at(i); } sort(X.begin(), X.end()); if (X.at(N - 1) == X.at(0)) { cout << 0; exit(0); } vector<int> A(X.at(N - 1) - X.at(0) - 1, 0); for (int i = X.at(0) + 1; i < X.at(N - 1); i++) { for (int j = 0; j < N; j++) { A.at(count) += (X.at(j) - i) * (X.at(j) - i); } count++; } sort(A.begin(), A.end()); cout << A.at(0); }
insert
18
18
18
23
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int people; cin >> people; vector<int> vi; for (int i = 0; i < people; i++) { int a; cin >> a; vi.push_back(a); } vector<int> vii; for (int i = vi[0]; i <= vi[vi.size() - 1]; i++) { int sum = 0; for (int j = 0; j < vi.size(); j++) { sum += (vi[j] - i) * (vi[j] - i); } vii.push_back(sum); } sort(vii.begin(), vii.end()); cout << vii[0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int people; cin >> people; vector<int> vi; for (int i = 0; i < people; i++) { int a; cin >> a; vi.push_back(a); } sort(vi.begin(), vi.end()); vector<int> vii; for (int i = vi[0]; i <= vi[vi.size() - 1]; i++) { int sum = 0; for (int j = 0; j < vi.size(); j++) { sum += (vi[j] - i) * (vi[j] - i); } vii.push_back(sum); } sort(vii.begin(), vii.end()); cout << vii[0] << endl; return 0; }
insert
11
11
11
12
0
p02767
C++
Runtime Error
#include <bits/stdc++.h> #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--) #define rep(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; template <typename T> using V = vector<T>; constexpr ll Mod = 998244353; constexpr ll mod = 1e9 + 7; constexpr ll inf = 1LL << 60; const double PI = acos(-1); template <typename T> constexpr bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> constexpr bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } /*-------------------------------------------*/ int main() { int n, sum; sum = 0; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); vector<int> s; for (int p = x[0]; p < x[n - 1] - x[0]; p++) { for (int i : x) { sum += (i - p) * (i - p); } s.push_back(sum); sum = 0; } sort(s.begin(), s.end()); cout << s[0] << endl; }
#include <bits/stdc++.h> #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--) #define rep(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; template <typename T> using V = vector<T>; constexpr ll Mod = 998244353; constexpr ll mod = 1e9 + 7; constexpr ll inf = 1LL << 60; const double PI = acos(-1); template <typename T> constexpr bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> constexpr bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } /*-------------------------------------------*/ int main() { int n, sum; sum = 0; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x.at(i); } sort(x.begin(), x.end()); vector<int> s; for (int p = x[0]; p <= x[n - 1]; p++) { for (int i : x) { sum += (i - p) * (i - p); } s.push_back(sum); sum = 0; } sort(s.begin(), s.end()); cout << s[0] << endl; }
replace
37
38
37
38
0
p02768
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using Int = long long; int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0); // int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv // ./prog.exe") >> 8), 0); const Int MOD = 1000000007; Int POW(Int n, Int k) { if (k == 0) return 1; if (k % 2 == 0) return POW(n * n % MOD, k / 2); return n * POW(n, k - 1) % MOD; } Int COM(int n, int k) { if (n < k || n < 0 || k < 0) return 0; Int a = 1, b = 1; for (int i = 0; i < k; i++) { a = a * (n - i) % MOD; b = b * (i + 1) % MOD; } return a * POW(b, MOD - 2) % MOD; } int main() { int N, A, B; cin >> N >> A >> B; Int ans = 1; for (int i = 0; i < N; i++) { ans = ans * 2 % MOD; } ans += 3 * MOD - 1 - COM(N, A) - COM(N, B); ans %= MOD; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using Int = long long; int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0); // int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv // ./prog.exe") >> 8), 0); const Int MOD = 1000000007; Int POW(Int n, Int k) { if (k == 0) return 1; if (k % 2 == 0) return POW(n * n % MOD, k / 2); return n * POW(n, k - 1) % MOD; } Int COM(int n, int k) { if (n < k || n < 0 || k < 0) return 0; Int a = 1, b = 1; for (int i = 0; i < k; i++) { a = a * (n - i) % MOD; b = b * (i + 1) % MOD; } return a * POW(b, MOD - 2) % MOD; } int main() { int N, A, B; cin >> N >> A >> B; Int ans = POW(2, N); ans += 3 * MOD - 1 - COM(N, A) - COM(N, B); ans %= MOD; cout << ans << endl; return 0; }
replace
28
32
28
29
TLE
p02768
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<string, int> P; const double PI = 3.14159265358979323846; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } const int mod = 1000000007; struct mint { ll x; mint(ll x = 0) : x(x % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; mint f(int n) { if (n == 0) return 1; mint x = f(n / 2); x *= x; if (n % 2 == 1) x *= 2; return x; } mint comb(int n, int a) { ll x = 1, y = 1; rep(i, a) { x *= n - i; y *= i + 1; } return x / y; } int main(int argc, char *args[]) { ll n; int a, b; cin >> n >> a >> b; mint ans = f(n); ans -= 1; ans -= comb(n, a); ans -= comb(n, b); cout << ans.x << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<string, int> P; const double PI = 3.14159265358979323846; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } const int mod = 1000000007; struct mint { ll x; mint(ll x = 0) : x(x % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; mint f(int n) { if (n == 0) return 1; mint x = f(n / 2); x *= x; if (n % 2 == 1) x *= 2; return x; } mint comb(int n, int a) { mint x = 1, y = 1; rep(i, a) { x *= n - i; y *= i + 1; } return x / y; } int main(int argc, char *args[]) { ll n; int a, b; cin >> n >> a >> b; mint ans = f(n); ans -= 1; ans -= comb(n, a); ans -= comb(n, b); cout << ans.x << endl; }
replace
79
80
79
80
0
p02768
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; const int MOD = 1000000007; long long power(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long d = power(a, b / 2); return d * d % MOD; } return a * power(a, b - 1) % MOD; } long long comb(long long x, long long y) { long long res = 1; for (long long i = x; i > x - y; i--) res = res * i % MOD; for (long long i = 1; i <= y; i++) res = (res * power(i, MOD - 2)) % MOD; return res; } int main() { int n, a, b; cin >> n >> a >> b; long long m = 1; for (int i = 0; i < n; ++i) { m = (2 * m) % MOD; } --m; long long ca = comb(n, a); long long cb = comb(n, b); cout << (2 * MOD + m - ca - cb) % MOD << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; const int MOD = 1000000007; long long power(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long d = power(a, b / 2); return d * d % MOD; } return a * power(a, b - 1) % MOD; } long long comb(long long x, long long y) { long long res = 1; for (long long i = x; i > x - y; i--) res = res * i % MOD; for (long long i = 1; i <= y; i++) res = (res * power(i, MOD - 2)) % MOD; return res; } int main() { int n, a, b; cin >> n >> a >> b; long long m = power(2, n) - 1; long long ca = comb(n, a); long long cb = comb(n, b); cout << (2 * MOD + m - ca - cb) % MOD << endl; }
replace
36
41
36
37
TLE
p02768
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n, a, b; const int MAXN = 212345; long long m = 1e9 + 7; long long inv[MAXN]; long long inverse_factorial[MAXN]; long long binomial_coefficient(int n, int k) { long long prod = 1; for (int i = n; i >= n - k + 1; i--) prod = (i * prod) % m; return (prod * inverse_factorial[k] % m) % m; } long long Pow(long long base, long long i) { base %= m; if (i <= 0) return 1; else if (i == 1) return base; else { long long aux = Pow(base, i / 2); if (i % 2 == 0) return (aux * aux) % m; else return (base * ((aux * aux) % m)) % m; } } int main() { ios_base::sync_with_stdio(0); freopen("input.txt", "r", stdin); cin >> n >> a >> b; inv[1] = 1; for (int i = 2; i < MAXN; ++i) inv[i] = (m - (m / i) * inv[m % i] % m) % m; inverse_factorial[0] = inv[1]; for (int i = 1; i < MAXN; i++) inverse_factorial[i] = (inverse_factorial[i - 1] * inv[i]) % m; long long d = Pow(2, n); cout << (2 * m + d - 1 - binomial_coefficient(n, a) - binomial_coefficient(n, b)) % m; }
#include <bits/stdc++.h> using namespace std; long long n, a, b; const int MAXN = 212345; long long m = 1e9 + 7; long long inv[MAXN]; long long inverse_factorial[MAXN]; long long binomial_coefficient(int n, int k) { long long prod = 1; for (int i = n; i >= n - k + 1; i--) prod = (i * prod) % m; return (prod * inverse_factorial[k] % m) % m; } long long Pow(long long base, long long i) { base %= m; if (i <= 0) return 1; else if (i == 1) return base; else { long long aux = Pow(base, i / 2); if (i % 2 == 0) return (aux * aux) % m; else return (base * ((aux * aux) % m)) % m; } } int main() { ios_base::sync_with_stdio(0); // freopen("input.txt","r",stdin); cin >> n >> a >> b; inv[1] = 1; for (int i = 2; i < MAXN; ++i) inv[i] = (m - (m / i) * inv[m % i] % m) % m; inverse_factorial[0] = inv[1]; for (int i = 1; i < MAXN; i++) inverse_factorial[i] = (inverse_factorial[i - 1] * inv[i]) % m; long long d = Pow(2, n); cout << (2 * m + d - 1 - binomial_coefficient(n, a) - binomial_coefficient(n, b)) % m; }
replace
35
36
35
36
0
p02768
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define cinf(n, x) \ for (int i = 0; i < (n); i++) \ cin >> x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define mod 1000000007 using namespace std; typedef long long ll; template <class T> using V = vector<T>; using Graph = vector<vector<int>>; using P = pair<ll, ll>; typedef unsigned long long ull; typedef long double ldouble; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // V,P(大文字)使用不可 const ll INF = 1e18; // const ll MAX = 200010;//自分で大きさを調節 // const ll MOD = 1000000007; // long long fac[MAX], finv[MAX], inv[MAX]; // // テーブルを作る前処理 // void COMinit() { // fac[0] = fac[1] = 1; // finv[0] = finv[1] = 1; // inv[1] = 1; // for (int i = 2; i < MAX; i++){ // fac[i] = fac[i - 1] * i % MOD; // inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; // finv[i] = finv[i - 1] * inv[i] % MOD; // } // } // // 二項係数計算 // long long COM(ll n,ll k){ // if (n < k) return 0; // if (n < 0 || k < 0) return 0; // return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; // } ll mod_pow(ll x, ll n, ll m) { if (n == 0) return 1; ll res = mod_pow(x * x % m, n / 2, m); if (n & 1) res = res * x % m; return res; } // ll mod_fact(ll n,ll p,ll &e){ // e=0; // if(n==0) return 1; // ll res=mod_fact(n/p,p,e); // e+=n/p; // if(n/p%2!=0) return res*(p-fac[n%p])%p; // return res*fac[n%p]%p; // } ll c(ll n, ll k) { if (k == 0 || n == k || n == 0) return 1; if (k == 1) return n; return (c(n - 1, k - 1) + c(n - 1, k)) % mod; } signed main() { ll n, a, b; cin >> n >> a >> b; ll ans = 0; ll s, t, u, v, w, x; ans = (mod_pow(2, n, mod) - 1 - c(n, a) - c(n, b)) % mod; cout << ans << endl; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define cinf(n, x) \ for (int i = 0; i < (n); i++) \ cin >> x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define mod 1000000007 using namespace std; typedef long long ll; template <class T> using V = vector<T>; using Graph = vector<vector<int>>; using P = pair<ll, ll>; typedef unsigned long long ull; typedef long double ldouble; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // V,P(大文字)使用不可 const ll INF = 1e18; // const ll MAX = 200010;//自分で大きさを調節 // const ll MOD = 1000000007; // long long fac[MAX], finv[MAX], inv[MAX]; // // テーブルを作る前処理 // void COMinit() { // fac[0] = fac[1] = 1; // finv[0] = finv[1] = 1; // inv[1] = 1; // for (int i = 2; i < MAX; i++){ // fac[i] = fac[i - 1] * i % MOD; // inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; // finv[i] = finv[i - 1] * inv[i] % MOD; // } // } // // 二項係数計算 // long long COM(ll n,ll k){ // if (n < k) return 0; // if (n < 0 || k < 0) return 0; // return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; // } ll mod_pow(ll x, ll n, ll m) { if (n == 0) return 1; ll res = mod_pow(x * x % m, n / 2, m); if (n & 1) res = res * x % m; return res; } // ll mod_fact(ll n,ll p,ll &e){ // e=0; // if(n==0) return 1; // ll res=mod_fact(n/p,p,e); // e+=n/p; // if(n/p%2!=0) return res*(p-fac[n%p])%p; // return res*fac[n%p]%p; // } ll c(ll n, ll k) { if (k == 0 || n == k || n == 0) return 1; if (k == 1) return n; return (c(n - 1, k - 1) + c(n - 1, k)) % mod; } signed main() { ll n, a, b; cin >> n >> a >> b; ll ans = 0; ll cnt = 1; ll bb = 1; for (ll i = 0; i <= a - 1; i++) cnt = cnt * (n - i) % mod; for (ll i = 2; i <= a; i++) cnt = cnt * mod_pow(i, mod - 2, mod) % mod; for (ll i = 0; i <= b - 1; i++) bb = bb * (n - i) % mod; for (ll i = 2; i <= b; i++) bb = bb * mod_pow(i, mod - 2, mod) % mod; ans = (mod_pow(2, n, mod) - 1 - cnt - bb) % mod; if (ans < 0) { while (ans < 0) ans += mod; } cout << ans << endl; }
replace
92
94
92
107
0
p02768
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using MinPriorityQueue = priority_queue<T, vector<T>, greater<T>>; #ifdef HOME #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << std ::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); int len = comma - names; for (int i = 0; i < len; ++i) { cout << names[i]; } cout << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define int long long #define db double #define eb emplace_back #define pb push_back #define fast_io() \ ios_base ::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) const int MOD = 1e9 + 7; const int INF = INT_MAX; const db PI = acos(-1), EPS = 1e-6; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int mul(int x, int y) { int res = ((x % MOD) * (y % MOD)) % MOD; return res; } int sub(int x, int y) { int res = ((x % MOD) - (y % MOD) + MOD) % MOD; return res; } int binpow(int a, int b) { a %= MOD; int res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; } int comb(int n, int k) { int fact1 = 1, fact2 = 1; for (int i = 1; i <= k; i++) fact1 = mul(fact1, i); for (int i = 0; i < k; i++) fact2 = mul(fact2, n - i); int x = binpow(fact1, MOD - 2); int res = mul(fact2, x); return res; } void test() { int n, a, b; cin >> n >> a >> b; int ans = sub(binpow(2, n), comb(n, a)); ans = sub(ans, comb(n, b)); ans -= 1; cout << ans << "\n"; } int32_t main() { fast_io(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cout << fixed << setprecision(15); int t = 1; // cin >> t; for (int i = 0; i < t; ++i) { test(); } #ifdef HOME cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms"; #endif return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using MinPriorityQueue = priority_queue<T, vector<T>, greater<T>>; #ifdef HOME #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << std ::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); int len = comma - names; for (int i = 0; i < len; ++i) { cout << names[i]; } cout << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define int long long #define db double #define eb emplace_back #define pb push_back #define fast_io() \ ios_base ::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) const int MOD = 1e9 + 7; const int INF = INT_MAX; const db PI = acos(-1), EPS = 1e-6; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int mul(int x, int y) { int res = ((x % MOD) * (y % MOD)) % MOD; return res; } int sub(int x, int y) { int res = ((x % MOD) - (y % MOD) + MOD) % MOD; return res; } int binpow(int a, int b) { a %= MOD; int res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; } int comb(int n, int k) { int fact1 = 1, fact2 = 1; for (int i = 1; i <= k; i++) fact1 = mul(fact1, i); for (int i = 0; i < k; i++) fact2 = mul(fact2, n - i); int x = binpow(fact1, MOD - 2); int res = mul(fact2, x); return res; } void test() { int n, a, b; cin >> n >> a >> b; int ans = sub(binpow(2, n), comb(n, a)); ans = sub(ans, comb(n, b)); ans -= 1; cout << ans << "\n"; } int32_t main() { fast_io(); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif cout << fixed << setprecision(15); int t = 1; // cin >> t; for (int i = 0; i < t; ++i) { test(); } #ifdef HOME cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms"; #endif return 0; }
replace
86
90
86
90
TLE
p02768
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned long long ull; using namespace std; #define FALSE printf("false\n"); #define TRUE printf("true\n"); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < ((int)(n)); ++i) #define pb push_back #define mp make_pair #define fi first #define se second #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define test(a) \ cout << "line:" << __LINE__ << "[" << (#a) << ": " << (a) << "]" << endl const int INF = 1e9 + 7; const ll INFL = 9 * 1e18; // const int dx[4] = { 1, 0, -1, 0 }; // const int dy[4] = { 0, 1, 0, -1 }; // const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1}; // const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1}; #define SUM(vec) accumulate(all(vec), 0LL) // 配列の中身を全部足す template <typename T> void print(T &&x) { cout << x << endl; } // 改行付き出力 ll inline digit(ll num) { int tmp = 0; while (num) { tmp++; num /= 10; } return tmp; } // 桁数 template <typename T> inline T digitSum(T num) { T sum = 0; while (num) { sum += num % 10; num /= 10; } return sum; } // 各桁の和 template <typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } // 最大公約数 template <typename T> inline T lcm(T a, T b) { T g = gcd(a, b); return a / g * b; } // 最小公倍数 template <typename T> inline T power(T a, T b) { T tmp = 1; rep(i, b) { tmp *= a; } return tmp; } // 累乗 template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int ctoi(char c) { return c - '0'; } const ll COM_MAX = (ll)(1e6 + 100); // combinationの最大値 vector<ll> fac(COM_MAX), finv(COM_MAX), inv(COM_MAX); void comb_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < COM_MAX; ++i) { fac[i] = fac[i - 1] * i % INF; inv[i] = INF - inv[INF % i] * (INF / i) % INF; finv[i] = finv[i - 1] * inv[i] % INF; } } ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % INF) % INF; } template <long long MOD> struct mod_int { using ll = long long; ll val; constexpr mod_int() : val(0) {} constexpr mod_int(ll x) noexcept : val(x >= 0 ? x % MOD : (MOD - (-x) % MOD) % MOD) {} constexpr ll value() const noexcept { return val; } constexpr mod_int operator+(mod_int const &rhs) { return mod_int(*this) += rhs; } constexpr mod_int operator-(mod_int const &rhs) { return mod_int(*this) -= rhs; } constexpr mod_int operator*(mod_int const &rhs) { return mod_int(*this) *= rhs; } constexpr mod_int operator/(mod_int const &rhs) { return mod_int(*this) /= rhs; } constexpr mod_int &operator+=(mod_int const &rhs) noexcept { val += rhs.val; if (val >= MOD) val -= MOD; return *this; } constexpr mod_int &operator-=(mod_int const &rhs) noexcept { if (val < rhs.val) val += MOD; val -= rhs.val; return *this; } constexpr mod_int &operator*=(mod_int const &rhs) noexcept { (val *= rhs.val) %= MOD; return *this; } constexpr mod_int &operator/=(mod_int rhs) noexcept { *this *= rhs.inverse(); return *this; } constexpr bool operator==(mod_int const &rhs) const { return val == rhs.val; } constexpr bool operator!=(mod_int const &rhs) const { return !(val == rhs.val); } constexpr bool operator<(mod_int const &rhs) const { return val < rhs.val; } constexpr bool operator>(mod_int const &rhs) const { return val > rhs.val; } constexpr bool operator<=(mod_int const &rhs) const { return !(val > rhs.val); } constexpr bool operator>=(mod_int const &rhs) const { return !(val < rhs.val); } constexpr friend std::ostream &operator<<(std::ostream &os, mod_int const &mi) { return os << mi.val; } constexpr friend std::istream &operator>>(std::istream &is, mod_int &mi) { ll t; is >> t; mi = mod_int<MOD>(t); return is; } constexpr mod_int inverse() { ll a = val, b = MOD, u = 1, v = 0, t = 1; while (b > 0) { t = a / b; std::swap(a -= t * b, b); std::swap(u -= t * v, v); } return mod_int(u); } constexpr mod_int mpow(ll n) const { mod_int res(1), e(*this); while (n) { if (n & 1) res *= e; e *= e; n >>= 1; } return res; } }; using mint = mod_int<1000000007>; mint mpow(ll x, ll n) { mint res(1), e(x); while (n) { if (n & 1) res *= e; e *= e; n >>= 1; } return res; } // TODO: write int main() { int n; cin >> n; int a, b; cin >> a >> b; comb_init(); if (n == 2) { print(0); return 0; } mint ans = mpow(2, n) - 1; ans -= comb(n, a); ans -= comb(n, b); print(ans); return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned long long ull; using namespace std; #define FALSE printf("false\n"); #define TRUE printf("true\n"); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < ((int)(n)); ++i) #define pb push_back #define mp make_pair #define fi first #define se second #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define test(a) \ cout << "line:" << __LINE__ << "[" << (#a) << ": " << (a) << "]" << endl const int INF = 1e9 + 7; const ll INFL = 9 * 1e18; // const int dx[4] = { 1, 0, -1, 0 }; // const int dy[4] = { 0, 1, 0, -1 }; // const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1}; // const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1}; #define SUM(vec) accumulate(all(vec), 0LL) // 配列の中身を全部足す template <typename T> void print(T &&x) { cout << x << endl; } // 改行付き出力 ll inline digit(ll num) { int tmp = 0; while (num) { tmp++; num /= 10; } return tmp; } // 桁数 template <typename T> inline T digitSum(T num) { T sum = 0; while (num) { sum += num % 10; num /= 10; } return sum; } // 各桁の和 template <typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } // 最大公約数 template <typename T> inline T lcm(T a, T b) { T g = gcd(a, b); return a / g * b; } // 最小公倍数 template <typename T> inline T power(T a, T b) { T tmp = 1; rep(i, b) { tmp *= a; } return tmp; } // 累乗 template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int ctoi(char c) { return c - '0'; } const ll COM_MAX = (ll)(1e6 + 100); // combinationの最大値 vector<ll> fac(COM_MAX), finv(COM_MAX), inv(COM_MAX); void comb_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < COM_MAX; ++i) { fac[i] = fac[i - 1] * i % INF; inv[i] = INF - inv[INF % i] * (INF / i) % INF; finv[i] = finv[i - 1] * inv[i] % INF; } } ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % INF) % INF; } template <long long MOD> struct mod_int { using ll = long long; ll val; constexpr mod_int() : val(0) {} constexpr mod_int(ll x) noexcept : val(x >= 0 ? x % MOD : (MOD - (-x) % MOD) % MOD) {} constexpr ll value() const noexcept { return val; } constexpr mod_int operator+(mod_int const &rhs) { return mod_int(*this) += rhs; } constexpr mod_int operator-(mod_int const &rhs) { return mod_int(*this) -= rhs; } constexpr mod_int operator*(mod_int const &rhs) { return mod_int(*this) *= rhs; } constexpr mod_int operator/(mod_int const &rhs) { return mod_int(*this) /= rhs; } constexpr mod_int &operator+=(mod_int const &rhs) noexcept { val += rhs.val; if (val >= MOD) val -= MOD; return *this; } constexpr mod_int &operator-=(mod_int const &rhs) noexcept { if (val < rhs.val) val += MOD; val -= rhs.val; return *this; } constexpr mod_int &operator*=(mod_int const &rhs) noexcept { (val *= rhs.val) %= MOD; return *this; } constexpr mod_int &operator/=(mod_int rhs) noexcept { *this *= rhs.inverse(); return *this; } constexpr bool operator==(mod_int const &rhs) const { return val == rhs.val; } constexpr bool operator!=(mod_int const &rhs) const { return !(val == rhs.val); } constexpr bool operator<(mod_int const &rhs) const { return val < rhs.val; } constexpr bool operator>(mod_int const &rhs) const { return val > rhs.val; } constexpr bool operator<=(mod_int const &rhs) const { return !(val > rhs.val); } constexpr bool operator>=(mod_int const &rhs) const { return !(val < rhs.val); } constexpr friend std::ostream &operator<<(std::ostream &os, mod_int const &mi) { return os << mi.val; } constexpr friend std::istream &operator>>(std::istream &is, mod_int &mi) { ll t; is >> t; mi = mod_int<MOD>(t); return is; } constexpr mod_int inverse() { ll a = val, b = MOD, u = 1, v = 0, t = 1; while (b > 0) { t = a / b; std::swap(a -= t * b, b); std::swap(u -= t * v, v); } return mod_int(u); } constexpr mod_int mpow(ll n) const { mod_int res(1), e(*this); while (n) { if (n & 1) res *= e; e *= e; n >>= 1; } return res; } }; using mint = mod_int<1000000007>; mint mpow(ll x, ll n) { mint res(1), e(x); while (n) { if (n & 1) res *= e; e *= e; n >>= 1; } return res; } // TODO: write int main() { int n; cin >> n; int a, b; cin >> a >> b; comb_init(); if (n == 2) { print(0); return 0; } mint ans = mpow(2, n) - 1; mint aKai = 1; mint bKai = 1; rep(i, a + 1) if (i) aKai *= i; rep(i, b + 1) if (i) bKai *= i; mint aTmp = 1; rep(i, a) aTmp *= (n - i); ans -= aTmp / aKai; mint bTmp = 1; rep(i, b) bTmp *= (n - i); ans -= bTmp / bKai; print(ans); return 0; }
replace
215
217
215
226
0
p02768
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; int N; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; N = n; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; if (n <= N) return fact[n] * ifact[k] * ifact[n - k]; else if (k <= N) { mint ans = 1; rep(i, k) ans *= n - i; ans *= ifact[k]; return ans; } else cout << "Err" << endl; return 0; } }; int main() { ios::sync_with_stdio(false); int n, a, b; cin >> n >> a >> b; combination c(max(a, b)); mint ans = 1; rep(i, n) { ans *= 2; } ans = ans - 1 - c(n, a) - c(n, b); cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; int N; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; N = n; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; if (n <= N) return fact[n] * ifact[k] * ifact[n - k]; else if (k <= N) { mint ans = 1; rep(i, k) ans *= n - i; ans *= ifact[k]; return ans; } else cout << "Err" << endl; return 0; } }; int main() { ios::sync_with_stdio(false); int n, a, b; cin >> n >> a >> b; combination c(max(a, b)); mint ans = 1; vector<mint> x2(32, 2); // 2^(2^i) rep(i, 31) x2[i + 1] = x2[i] * x2[i]; rep(i, 32) { if (n >> i & 1) ans *= x2[i]; } ans = ans - 1 - c(n, a) - c(n, b); cout << ans << endl; }
replace
97
98
97
103
TLE
p02768
C++
Runtime Error
#include "bits/stdc++.h" #define REP(i, num) for (int i = 0; i < (num); ++i) #define LOOP(i) while (i--) #define ALL(c) c.begin(), c.end() #define PRINTALL(c) \ for (auto pitr = c.begin(); pitr != c.end(); ++pitr) { \ cout << *pitr; \ if (next(pitr, 1) != c.end()) \ cout << ' '; \ } \ cout << endl; #define PAIRCOMP(c, comp) \ [](const pair<ll, ll> &lhs, const pair<ll, ll> &rhs) { \ return lhs.c comp rhs.c; \ } using namespace std; using ll = long long; constexpr ll atcoder_mod = 1e9 + 7; template <typename T = int> T in() { T x; cin >> x; return (x); } template <typename T = int, typename C = vector<T>> C vecin(int N) { C x(N); REP(i, N) { x[i] = in<T>(); } return move(x); } void vout() { cout << endl; } template <typename Head, typename... Tail> void vout(Head &&h, Tail &&...t) { cout << ' ' << h; vout(forward<Tail>(t)...); } void out() { cout << endl; } template <typename Head, typename... Tail> void out(Head &&h, Tail &&...t) { cout << h; vout(forward<Tail>(t)...); } class Combination { constexpr static int atcoder_mod = 1000000007; vector<ll> fac, finv, inv; public: Combination(ll N) { fac.resize(N + 1); finv.resize(N + 1); inv.resize(N + 1); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i <= N; i++) { fac[i] = fac[i - 1] * i % atcoder_mod; inv[i] = atcoder_mod - inv[atcoder_mod % i] * (atcoder_mod / i) % atcoder_mod; finv[i] = finv[i - 1] * inv[i] % atcoder_mod; } } ll Caluclation(ll n, ll r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % atcoder_mod) % atcoder_mod; } ll GetFInv(ll i) { return finv[i]; } }; ll powermod(ll a, ll b, ll m) { if (b == 0) { return 1LL; } if (b % 2) { return (a * powermod(a, b - 1LL, m)) % m; } return powermod((a * a) % m, b / 2LL, m); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int N = in(), A = in(), B = in(); Combination comb(B); vector<ll> dp(N + 1); dp[0] = 1; REP(i, B) { dp[i + 1] = ((dp[i] * (N - i)) % atcoder_mod); dp[i + 1] %= atcoder_mod; } int L = (dp[A] * comb.GetFInv(A)) % atcoder_mod + (dp[B] * comb.GetFInv(B)) % atcoder_mod; L %= atcoder_mod; out((powermod(2, N, atcoder_mod) - 1 - L + atcoder_mod) % atcoder_mod); return 0; }
#include "bits/stdc++.h" #define REP(i, num) for (int i = 0; i < (num); ++i) #define LOOP(i) while (i--) #define ALL(c) c.begin(), c.end() #define PRINTALL(c) \ for (auto pitr = c.begin(); pitr != c.end(); ++pitr) { \ cout << *pitr; \ if (next(pitr, 1) != c.end()) \ cout << ' '; \ } \ cout << endl; #define PAIRCOMP(c, comp) \ [](const pair<ll, ll> &lhs, const pair<ll, ll> &rhs) { \ return lhs.c comp rhs.c; \ } using namespace std; using ll = long long; constexpr ll atcoder_mod = 1e9 + 7; template <typename T = int> T in() { T x; cin >> x; return (x); } template <typename T = int, typename C = vector<T>> C vecin(int N) { C x(N); REP(i, N) { x[i] = in<T>(); } return move(x); } void vout() { cout << endl; } template <typename Head, typename... Tail> void vout(Head &&h, Tail &&...t) { cout << ' ' << h; vout(forward<Tail>(t)...); } void out() { cout << endl; } template <typename Head, typename... Tail> void out(Head &&h, Tail &&...t) { cout << h; vout(forward<Tail>(t)...); } class Combination { constexpr static int atcoder_mod = 1000000007; vector<ll> fac, finv, inv; public: Combination(ll N) { fac.resize(N + 1); finv.resize(N + 1); inv.resize(N + 1); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i <= N; i++) { fac[i] = fac[i - 1] * i % atcoder_mod; inv[i] = atcoder_mod - inv[atcoder_mod % i] * (atcoder_mod / i) % atcoder_mod; finv[i] = finv[i - 1] * inv[i] % atcoder_mod; } } ll Caluclation(ll n, ll r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % atcoder_mod) % atcoder_mod; } ll GetFInv(ll i) { return finv[i]; } }; ll powermod(ll a, ll b, ll m) { if (b == 0) { return 1LL; } if (b % 2) { return (a * powermod(a, b - 1LL, m)) % m; } return powermod((a * a) % m, b / 2LL, m); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int N = in(), A = in(), B = in(); Combination comb(B); vector<ll> dp(B + 1); dp[0] = 1; REP(i, B) { dp[i + 1] = ((dp[i] * (N - i)) % atcoder_mod); dp[i + 1] %= atcoder_mod; } int L = (dp[A] * comb.GetFInv(A)) % atcoder_mod + (dp[B] * comb.GetFInv(B)) % atcoder_mod; L %= atcoder_mod; out((powermod(2, N, atcoder_mod) - 1 - L + atcoder_mod) % atcoder_mod); return 0; }
replace
90
91
90
91
0
p02768
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 constexpr int kMod = 1000000007; typedef long long LL; LL modpow(LL a, LL n) { LL pow = 1; while (n > 0) { if (n & 1) pow = pow * a % kMod; a = a * a % kMod; n >>= 1; } return pow; } LL modinv(LL a) { return modpow(a, kMod - 2); } LL modsub(LL a, LL b) { return (a + kMod - b) % kMod; } LL nCr(LL n, LL r) { LL x = 1, y = 1; for (int i = 1; i <= r; ++i) { x = (x * (n - i + 1)) % kMod; y = (y * i) % kMod; } return (x * modinv(y)) % kMod; } int main() { LL n, a, b; std::cin >> n >> a >> b; LL ans = 1; for (int i = 0; i < n; ++i) ans = (2 * ans) % kMod; --ans; LL nCa = nCr(n, a); LL nCb = nCr(n, b); ans = modsub(ans, nCa); ans = modsub(ans, nCb); std::cout << ans << std::endl; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 constexpr int kMod = 1000000007; typedef long long LL; LL modpow(LL a, LL n) { LL pow = 1; while (n > 0) { if (n & 1) pow = pow * a % kMod; a = a * a % kMod; n >>= 1; } return pow; } LL modinv(LL a) { return modpow(a, kMod - 2); } LL modsub(LL a, LL b) { return (a + kMod - b) % kMod; } LL nCr(LL n, LL r) { LL x = 1, y = 1; for (int i = 1; i <= r; ++i) { x = (x * (n - i + 1)) % kMod; y = (y * i) % kMod; } return (x * modinv(y)) % kMod; } int main() { LL n, a, b; std::cin >> n >> a >> b; LL ans = modpow(2, n) - 1; LL nCa = nCr(n, a); LL nCb = nCr(n, b); ans = modsub(ans, nCa); ans = modsub(ans, nCb); std::cout << ans << std::endl; }
replace
44
49
44
45
TLE
p02768
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; typedef vector<vector<ll>> mat; typedef vector<ll> vec; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() const ll mod = 1000000007; const ll INF = mod * mod; const ld eps = 1e-12; const ld pi = acos(-1.0); // int qp(int a,ll b){int // ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最小公倍数 int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); } template <typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template <typename T> bool chmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; } template <typename T> bool chmin(T &m, const T q) { if (q < m) { m = q; return true; } else return false; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } struct mint { ll n; mint(ll a = 0) { n = a % mod; } mint &operator+=(mint a) { n += a.n; n %= mod; return *this; } mint &operator-=(mint a) { n += mod; n -= a.n; n %= mod; return *this; } mint &operator*=(mint a) { n *= a.n; n %= mod; return *this; } mint &operator%=(mint a) { n %= a.n; return *this; } mint &operator++() { n++; n %= mod; return *this; } mint &operator--() { n += mod; n--; n %= mod; return *this; } }; mint operator+(mint a, mint b) { a += b; return a; } mint operator-(mint a, mint b) { a -= b; return a; } mint operator*(mint a, mint b) { a *= b; return a; } mint factMod(ll n) { if (n == 0) { return 1; } mint ans = 1; while (n > 1) { ans *= n; n--; } return ans; } mint powMod(mint x, ll y) { if (x.n <= 1) { return x; } if (y == 0) { return 1; } else if (y == 1) { return x; } else if (y % 2 == 0) { mint tmp = powMod(x, y / 2); return tmp * tmp; } else { mint tmp = powMod(x, y / 2); return tmp * tmp * x; } } mint modinv(mint n) { return powMod(n, mod - 2); } vector<ll> invtbl; void preCalcInv(ll up) { invtbl.resize(up + 1); invtbl[1] = 1; for (ll a = 2; a <= up; a++) { invtbl[a] = mod - invtbl[mod % a] * (mod / a) % mod; } } mint operator/(mint a, mint b) { if (b.n < invtbl.size()) { a *= invtbl[b.n]; } else { a *= modinv(b); } return a; } mint &operator/=(mint &a, mint b) { a = a / b; return a; } mint nCrMod(ll n, ll r) { if (n < r || n < 0 || r < 0) { return 0; } r = min(r, n - r); mint a = 1; for (ll i = n - r + 1; i <= n; i++) { a *= i; } a /= factMod(r); return a; } mint nHrMod(ll n, ll r) { return nCrMod(n + r - 1, r); } template <class T> constexpr auto modK_belowN(T k, T MOD, T n) { return (n + MOD - k - 1) / MOD; } void solve() { ll N, A, B; cin >> N >> A >> B; mint n = N; mint co = 0; rep1(i, N) { if (i == A || i == B) continue; mint m = i; co += nCrMod(n.n, m.n); } cout << co.n << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); std::cout << fixed << setprecision(10); solve(); // stop return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; typedef vector<vector<ll>> mat; typedef vector<ll> vec; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() const ll mod = 1000000007; const ll INF = mod * mod; const ld eps = 1e-12; const ld pi = acos(-1.0); // int qp(int a,ll b){int // ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最小公倍数 int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); } template <typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); } template <typename T> bool chmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; } template <typename T> bool chmin(T &m, const T q) { if (q < m) { m = q; return true; } else return false; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } struct mint { ll n; mint(ll a = 0) { n = a % mod; } mint &operator+=(mint a) { n += a.n; n %= mod; return *this; } mint &operator-=(mint a) { n += mod; n -= a.n; n %= mod; return *this; } mint &operator*=(mint a) { n *= a.n; n %= mod; return *this; } mint &operator%=(mint a) { n %= a.n; return *this; } mint &operator++() { n++; n %= mod; return *this; } mint &operator--() { n += mod; n--; n %= mod; return *this; } }; mint operator+(mint a, mint b) { a += b; return a; } mint operator-(mint a, mint b) { a -= b; return a; } mint operator*(mint a, mint b) { a *= b; return a; } mint factMod(ll n) { if (n == 0) { return 1; } mint ans = 1; while (n > 1) { ans *= n; n--; } return ans; } mint powMod(mint x, ll y) { if (x.n <= 1) { return x; } if (y == 0) { return 1; } else if (y == 1) { return x; } else if (y % 2 == 0) { mint tmp = powMod(x, y / 2); return tmp * tmp; } else { mint tmp = powMod(x, y / 2); return tmp * tmp * x; } } mint modinv(mint n) { return powMod(n, mod - 2); } vector<ll> invtbl; void preCalcInv(ll up) { invtbl.resize(up + 1); invtbl[1] = 1; for (ll a = 2; a <= up; a++) { invtbl[a] = mod - invtbl[mod % a] * (mod / a) % mod; } } mint operator/(mint a, mint b) { if (b.n < invtbl.size()) { a *= invtbl[b.n]; } else { a *= modinv(b); } return a; } mint &operator/=(mint &a, mint b) { a = a / b; return a; } mint nCrMod(ll n, ll r) { if (n < r || n < 0 || r < 0) { return 0; } r = min(r, n - r); mint a = 1; for (ll i = n - r + 1; i <= n; i++) { a *= i; } a /= factMod(r); return a; } mint nHrMod(ll n, ll r) { return nCrMod(n + r - 1, r); } template <class T> constexpr auto modK_belowN(T k, T MOD, T n) { return (n + MOD - k - 1) / MOD; } void solve() { ll N, A, B; cin >> N >> A >> B; mint co = powMod((mint)2, N) - 1 - nCrMod(N, A) - nCrMod(N, B); cout << co.n << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); std::cout << fixed << setprecision(10); solve(); // stop return 0; }
replace
287
298
287
288
TLE
p02768
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define INF 1e9 #define PI 3.14159265359 #define MOD 1000000007 #define ALL(v) v.begin(), v.end() typedef long long ll; // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } ll pow2(ll n) { ll ans = 1; rep(i, n) { ans = (ans * 2) % MOD; } return ans; } ll COM(ll n, ll k) { ll ans = 1; rep(i, k) { ans = ans * (n - i) % MOD; ans = ans * modinv(i + 1, MOD) % MOD; } return ans; } int main() { ll n, a, b; cin >> n >> a >> b; ll ans = pow2(n) - 1 - COM(n, a) - COM(n, b); if (ans < 0) { ans += MOD; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define INF 1e9 #define PI 3.14159265359 #define MOD 1000000007 #define ALL(v) v.begin(), v.end() typedef long long ll; // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } ll pow2(ll n) { ll ans = 1; rep(i, n) { ans = (ans * 2) % MOD; } return ans; } ll COM(ll n, ll k) { ll ans = 1; rep(i, k) { ans = ans * (n - i) % MOD; ans = ans * modinv(i + 1, MOD) % MOD; } return ans; } int main() { ll n, a, b; cin >> n >> a >> b; ll ans = (((modpow(2, n, MOD) - 1) % MOD - COM(n, a)) % MOD - COM(n, b)) % MOD; if (ans < 0) { ans += MOD; } cout << ans << endl; }
replace
41
42
41
43
TLE
p02768
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int64_t mod = 1000000007; int64_t mypow(int64_t x, int64_t y) { if (y == 1) return x; else if (y % 2 == 1) return mypow(x, y - 1) * x % mod; else { int64_t tmp = mypow(x, y / 2); return tmp * tmp % mod; } } int64_t soujo(int64_t x, int64_t y) // x~y { if (x == y) return y; else return x * soujo(x + 1, y) % mod; } int64_t combi(int64_t x, int64_t y) // y C x,y < x { int64_t X = soujo(x - y + 1, x); int64_t Y = soujo(1, y); return X * mypow(Y, mod - 2) % mod; } int main() { int64_t N, A, B; cin >> N >> A >> B; int64_t ans = mypow(2, N) - 1; ans -= combi(N, min(A, N - A)); ans -= combi(N, min(B, N - B)); cout << (ans + mod * 2) % mod; }
#include <bits/stdc++.h> using namespace std; int64_t mod = 1000000007; int64_t mypow(int64_t x, int64_t y) { if (y == 1) return x; else if (y % 2 == 1) return mypow(x, y - 1) * x % mod; else { int64_t tmp = mypow(x, y / 2); return tmp * tmp % mod; } } int64_t soujo(int64_t x, int64_t y) // x~y { if (x == y) return y; else return x * soujo(x + 1, y) % mod; } int64_t combi(int64_t x, int64_t y) // y C x,y < x { int64_t X = soujo(x - y + 1, x); int64_t Y = soujo(1, y); return X * mypow(Y, mod - 2) % mod; } int main() { int64_t N, A, B; cin >> N >> A >> B; int64_t ans = mypow(2, N) - 1; ans -= combi(N, A); ans -= combi(N, B); cout << (ans + mod * 2) % mod; }
replace
36
38
36
38
0
p02768
C++
Runtime Error
#include <bits/stdc++.h> #define INF 1e9 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 組み合わせを求める(グローバル汚さない版) // 上の関数にまとめたバージョン // nCk mod. p を出したくて、nが<1e7 かつ pが素数(1e9+7は素数)ならおk // MAX 1e7で1400msぐらいかかるので注意(元版はそれの半分の時間で済む) // 上と同じ2回目以降はキャッシュされるのでO(1) // 第三引数は初回のみに使用する。 // nCkのnの最大値を入れる(1e6+1推奨)。O(k)を使用する場合は不要 else O(k) // [nが固定されている必要はある] // O(k)とO(n)の両方を選択することは出来ないのでそういったときはこの関数を命名分けて2個作る必要がある。 long long combination(int n, int k, int init_max_n = -1) { static vector<ll> fac, finv, inv, big_n_tbl; static const int mod = 1e9 + 7; static bool big_n = false; static bool created = false; if (big_n) cerr << "big_n: trueのため、nは初期化時に使用した値になります" << endl; if (created && init_max_n != -1) cerr << "初期化済みのためinit_max_nの値は無視されます" << endl; if (!created) { if (init_max_n == -1) { cerr << "初期化に失敗しました。" << endl; exit(1); } if (init_max_n < 1e7 + 1) { // O(n) tbl fac.resize(init_max_n, 0); finv.resize(init_max_n, 0); inv.resize(init_max_n, 0); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < init_max_n; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } else { // O(k) table (nは変更不可) chmin(k, n - k); big_n_tbl.resize(k + 1, 1); inv.resize(k + 2, 1); FOR(i, 1, k + 1) { inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod; big_n_tbl[i] = (i == 1) ? n : ((n - i + 1) * inv[i]) % mod * big_n_tbl[i - 1]; if (i == 1) cerr << "i:1 " << big_n_tbl[i] << endl; big_n_tbl[i] %= mod; } big_n = true; } created = true; } if (big_n) return big_n_tbl[k]; if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } long long modpow(long long a, long long n) { long long res = 1; static const int mod = 1e9 + 7; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { ll n, a, b; const int mod = 1e9 + 7; cin >> n >> a >> b; ll ans = modpow(2, n) - 1; ans %= mod; ans += (ans < 0) ? mod : 0; auto cb = combination(n, b, 1e6 + 1); auto ca = combination(n, a); cerr << "comb[a]: " << ca << endl; cerr << "comb[b]: " << cb << endl; ans -= ca; ans %= mod; ans += (ans < 0) ? mod : 0; ans -= cb; ans %= mod; ans += (ans < 0) ? mod : 0; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define INF 1e9 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 組み合わせを求める(グローバル汚さない版) // 上の関数にまとめたバージョン // nCk mod. p を出したくて、nが<1e7 かつ pが素数(1e9+7は素数)ならおk // MAX 1e7で1400msぐらいかかるので注意(元版はそれの半分の時間で済む) // 上と同じ2回目以降はキャッシュされるのでO(1) // 第三引数は初回のみに使用する。 // nCkのnの最大値を入れる(1e6+1推奨)。O(k)を使用する場合は不要 else O(k) // [nが固定されている必要はある] // O(k)とO(n)の両方を選択することは出来ないのでそういったときはこの関数を命名分けて2個作る必要がある。 long long combination(int n, int k, int init_max_n = -1) { static vector<ll> fac, finv, inv, big_n_tbl; static const int mod = 1e9 + 7; static bool big_n = false; static bool created = false; if (big_n) cerr << "big_n: trueのため、nは初期化時に使用した値になります" << endl; if (created && init_max_n != -1) cerr << "初期化済みのためinit_max_nの値は無視されます" << endl; if (!created) { if (init_max_n == -1) { cerr << "初期化に失敗しました。" << endl; exit(1); } if (max(init_max_n, n) < 1e7 + 1) { // O(n) tbl fac.resize(init_max_n, 0); finv.resize(init_max_n, 0); inv.resize(init_max_n, 0); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < init_max_n; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } else { // O(k) table (nは変更不可) chmin(k, n - k); big_n_tbl.resize(k + 1, 1); inv.resize(k + 2, 1); FOR(i, 1, k + 1) { inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod; big_n_tbl[i] = (i == 1) ? n : ((n - i + 1) * inv[i]) % mod * big_n_tbl[i - 1]; if (i == 1) cerr << "i:1 " << big_n_tbl[i] << endl; big_n_tbl[i] %= mod; } big_n = true; } created = true; } if (big_n) return big_n_tbl[k]; if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } long long modpow(long long a, long long n) { long long res = 1; static const int mod = 1e9 + 7; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { ll n, a, b; const int mod = 1e9 + 7; cin >> n >> a >> b; ll ans = modpow(2, n) - 1; ans %= mod; ans += (ans < 0) ? mod : 0; auto cb = combination(n, b, 1e6 + 1); auto ca = combination(n, a); cerr << "comb[a]: " << ca << endl; cerr << "comb[b]: " << cb << endl; ans -= ca; ans %= mod; ans += (ans < 0) ? mod : 0; ans -= cb; ans %= mod; ans += (ans < 0) ? mod : 0; cout << ans << endl; return 0; }
replace
50
51
50
51
0
comb[a]: 4 comb[b]: 4
p02768
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rp(i, k, n) for (int i = k; i < n; i++) typedef long long ll; typedef double ld; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const ll INF = 1ll << 60; const ll MOD = 1e9 + 7ll; const double PI = 3.14159265358979323846; ll mypow(ll X, ll n) { // 繰り返し2乗法 計算量log(n) if (n == 0) return 1ll; ll Y = mypow(X, n / 2); if (n % 2 == 1) return X * Y % MOD * Y % MOD; else return Y * Y % MOD; } // 二項係数ライブラリ---------------------------------------------------------------------------------------// const ll MAX_COM = 1000007; ll fac[MAX_COM], finv[MAX_COM], inv[MAX_COM]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1ll; finv[0] = finv[1] = 1ll; inv[1] = 1ll; for (int i = 2; i < MAX_COM; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = (finv[i - 1] * inv[i]) % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] % MOD * finv[k] % MOD * finv[n - k] % MOD; } // Nが大きいときの二項係数計算 // N = 10^9, k = 2*10^5まで使える const ll MAX_COM_NB = 200010; vector<ll> COM_NB(MAX_COM_NB); ll COM_NBinit(int N) { // COMinit(); COM_NB[0] = 1ll; rp(i, 1, MAX_COM_NB) { COM_NB[i] = COM_NB[i - 1] * (N + 1 - i) % MOD * inv[i] % MOD; } } // 二項係数ライブラリここまで-----------------------------------------------------------------------------------// int main() { int N, a, b; cin >> N >> a >> b; ll res = mypow(2, N) + MOD - 1; res %= MOD; COMinit(); COM_NBinit(N); res = (res + MOD - COM_NB[a]) % MOD; res = (res + MOD - COM_NB[b]) % MOD; cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rp(i, k, n) for (int i = k; i < n; i++) typedef long long ll; typedef double ld; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const ll INF = 1ll << 60; const ll MOD = 1e9 + 7ll; const double PI = 3.14159265358979323846; ll mypow(ll X, ll n) { // 繰り返し2乗法 計算量log(n) if (n == 0) return 1ll; ll Y = mypow(X, n / 2); if (n % 2 == 1) return X * Y % MOD * Y % MOD; else return Y * Y % MOD; } // 二項係数ライブラリ---------------------------------------------------------------------------------------// const ll MAX_COM = 1000007; ll fac[MAX_COM], finv[MAX_COM], inv[MAX_COM]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1ll; finv[0] = finv[1] = 1ll; inv[1] = 1ll; for (int i = 2; i < MAX_COM; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = (finv[i - 1] * inv[i]) % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] % MOD * finv[k] % MOD * finv[n - k] % MOD; } // Nが大きいときの二項係数計算 // N = 10^9, k = 2*10^5まで使える const ll MAX_COM_NB = 200010; vector<ll> COM_NB(MAX_COM_NB); void COM_NBinit(int N) { // COMinit(); COM_NB[0] = 1ll; rp(i, 1, MAX_COM_NB) { COM_NB[i] = COM_NB[i - 1] * (N + 1 - i) % MOD * inv[i] % MOD; } } // 二項係数ライブラリここまで-----------------------------------------------------------------------------------// int main() { int N, a, b; cin >> N >> a >> b; ll res = mypow(2, N) + MOD - 1; res %= MOD; COMinit(); COM_NBinit(N); res = (res + MOD - COM_NB[a]) % MOD; res = (res + MOD - COM_NB[b]) % MOD; cout << res << endl; return 0; }
replace
64
65
64
65
0
p02768
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define ll long long #define dd double #define MOD 1000000007 #define nl cout << endl #define rt int Q[100005] = {0} #define mp make_pair #define test() \ int t; \ cin >> t; \ while (t--) #define pb push_back #define ff first #define ss second #define all(v) v.begin(), v.end() #define s(ar, n) sort(ar, ar + n) #define rs(ar, n) sort(ar, ar + n, greater<int>()) #define oa(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; \ nl #define cn(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define ov(a, n) \ for (int i = n - 1; i >= 0; i--) \ cout << a[i] << " "; \ nl #define ovp(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i].ff << " " << a[i].ss << endl; #define maxa(ar, N) *max_element(ar, ar + N) #define mina(ar, N) *min_element(ar, ar + N) #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef pair<int, int> pii; ll powe(ll n, ll m) { if (m == 0) return 1; ll t = powe(n, m / 2); if (m % 2 == 0) return (t * t); return (((t * t)) * n); } ll mpowe(ll n, ll m) { if (m == 0) return 1; ll t = mpowe(n, m / 2); t %= MOD; if (m % 2 == 0) return (t * t) % MOD; return (((t * t) % MOD) * n) % MOD; } int logtwo(int n) { if (n == 1) return 0; return logtwo(n / 2) + 1; } vector<int> v[200005]; // Vector for maintaining adjacency list explained above int level[200005]; bool vis[200005]; // Mark the node if visited void bfs(int s) { queue<int> q; q.push(s); level[s] = 0; // Setting the level of the source node as 0 vis[s] = true; while (!q.empty()) { int p = q.front(); q.pop(); for (int i = 0; i < v[p].size(); i++) { if (vis[v[p][i]] == false) { // Setting the level of each node with an increment in the level of // parent node level[v[p][i]] = level[p] + 1; q.push(v[p][i]); vis[v[p][i]] = true; } } } } int main() { fastio(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, a, b; cin >> n >> a >> b; ll na = 1, nrn = 1; for (ll i = 1; i <= a; i++) { na = (na * i) % MOD; } for (ll i = n; i >= n - a + 1; i--) { nrn = (nrn * i) % MOD; } ll nca = (nrn * mpowe(na, MOD - 2) % MOD) % MOD; na = 1; nrn = 1; for (ll i = 1; i <= b; i++) { na = (na * i) % MOD; } for (ll i = n; i >= n - b + 1; i--) { nrn = (nrn * i) % MOD; } ll ncb = (nrn * mpowe(na, MOD - 2) % MOD) % MOD; // cout<<ncb<<endl; ll ans = (mpowe(2, n) - 1 - nca - ncb + 2 * MOD) % MOD; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define ll long long #define dd double #define MOD 1000000007 #define nl cout << endl #define rt int Q[100005] = {0} #define mp make_pair #define test() \ int t; \ cin >> t; \ while (t--) #define pb push_back #define ff first #define ss second #define all(v) v.begin(), v.end() #define s(ar, n) sort(ar, ar + n) #define rs(ar, n) sort(ar, ar + n, greater<int>()) #define oa(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; \ nl #define cn(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define ov(a, n) \ for (int i = n - 1; i >= 0; i--) \ cout << a[i] << " "; \ nl #define ovp(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i].ff << " " << a[i].ss << endl; #define maxa(ar, N) *max_element(ar, ar + N) #define mina(ar, N) *min_element(ar, ar + N) #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef pair<int, int> pii; ll powe(ll n, ll m) { if (m == 0) return 1; ll t = powe(n, m / 2); if (m % 2 == 0) return (t * t); return (((t * t)) * n); } ll mpowe(ll n, ll m) { if (m == 0) return 1; ll t = mpowe(n, m / 2); t %= MOD; if (m % 2 == 0) return (t * t) % MOD; return (((t * t) % MOD) * n) % MOD; } int logtwo(int n) { if (n == 1) return 0; return logtwo(n / 2) + 1; } vector<int> v[200005]; // Vector for maintaining adjacency list explained above int level[200005]; bool vis[200005]; // Mark the node if visited void bfs(int s) { queue<int> q; q.push(s); level[s] = 0; // Setting the level of the source node as 0 vis[s] = true; while (!q.empty()) { int p = q.front(); q.pop(); for (int i = 0; i < v[p].size(); i++) { if (vis[v[p][i]] == false) { // Setting the level of each node with an increment in the level of // parent node level[v[p][i]] = level[p] + 1; q.push(v[p][i]); vis[v[p][i]] = true; } } } } int main() { fastio(); /* #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ ll n, a, b; cin >> n >> a >> b; ll na = 1, nrn = 1; for (ll i = 1; i <= a; i++) { na = (na * i) % MOD; } for (ll i = n; i >= n - a + 1; i--) { nrn = (nrn * i) % MOD; } ll nca = (nrn * mpowe(na, MOD - 2) % MOD) % MOD; na = 1; nrn = 1; for (ll i = 1; i <= b; i++) { na = (na * i) % MOD; } for (ll i = n; i >= n - b + 1; i--) { nrn = (nrn * i) % MOD; } ll ncb = (nrn * mpowe(na, MOD - 2) % MOD) % MOD; // cout<<ncb<<endl; ll ans = (mpowe(2, n) - 1 - nca - ncb + 2 * MOD) % MOD; cout << ans << endl; }
replace
87
91
87
91
TLE
p02768
Python
Runtime Error
def create_array(n: int, r: int, mod, mod2): m_ls = [1] * (r + 1) for i, j in zip(range(n, 0, -1), range(1, r + 1)): m_ls[j] = (m_ls[j - 1] * i * pow(j, mod2, mod)) % mod return m_ls def main(): n, a, b = map(int, input().split()) _mod = 1_000_000_007 _mod2 = 1_000_000_005 m_ls = create_array(n, b, _mod, _mod2) _all_cnts = pow(2, n, _mod) - 1 ans = _all_cnts + (_mod - m_ls[a]) + (_mod - m_ls[b]) ans %= _mod print(ans) main()
def create_array(n: int, r: int, mod, mod2): m_ls = [1] * (r + 1) for i, j in zip(range(n, 0, -1), range(1, r + 1)): m_ls[j] = (m_ls[j - 1] * i * pow(j, mod2, mod)) % mod return m_ls def main(): n, a, b = map(int, input().split()) _mod = 1000000007 _mod2 = 1000000005 m_ls = create_array(n, b, _mod, _mod2) _all_cnts = pow(2, n, _mod) - 1 ans = _all_cnts + (_mod - m_ls[a]) + (_mod - m_ls[b]) ans %= _mod print(ans) main()
replace
10
12
10
12
0
p02768
Python
Runtime Error
n, a, b = map(int, input().split()) mod = 10**9 + 7 max = min(n, 2 * 10**5) fac1 = [n] * max fac2 = [1] * max for i in range(2, max): fac1[i] = fac1[i - 1] * (n - i + 1) % mod fac2[i] = fac2[i - 1] * i % mod c = fac1[a] * pow(fac2[a], mod - 2, mod) % mod d = fac1[b] * pow(fac2[b], mod - 2, mod) % mod print((pow(2, n, mod) - c - d - 1) % mod)
n, a, b = map(int, input().split()) mod = 10**9 + 7 max = min(n, 2 * 10**5) fac1 = [n] * (max + 1) fac2 = [1] * (max + 1) for i in range(2, max + 1): fac1[i] = fac1[i - 1] * (n - i + 1) % mod fac2[i] = fac2[i - 1] * i % mod c = fac1[a] * pow(fac2[a], mod - 2, mod) % mod d = fac1[b] * pow(fac2[b], mod - 2, mod) % mod print((pow(2, n, mod) - c - d - 1) % mod)
replace
4
7
4
7
0
p02768
Python
Runtime Error
n, a, b = map(int, input().split()) mod = 10**9 + 7 def choose(n, r, mod): r = min(r, n - r) x = 1 y = 1 for i in range(r): x = x * (n - i) % mod y = y * (i + 1) % mod y = pow(y, -2, mod) return x * y % mod ans = pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod) while ans < 0: ans += mod print(ans)
n, a, b = map(int, input().split()) mod = 10**9 + 7 def choose(n, r, mod): r = min(r, n - r) x = 1 y = 1 for i in range(r): x = x * (n - i) % mod y = y * (i + 1) % mod y = pow(y, mod - 2, mod) return x * y % mod ans = pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod) while ans < 0: ans += mod print(ans)
replace
11
12
11
12
0
p02768
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; typedef long long ll; typedef pair<int, int> P; const int inf = 1 << 21; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; const ll MAX = 200005; ll fac[MAX], finv[MAX], inv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll com(ll n, ll k) { if (n < k) return 0; if (n < 0 or k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, a, b; cin >> n >> a >> b; ll ans = 1; rep(i, n) { ans *= 2; ans %= mod; } ans--; cominit(); ll tmp = 1; ll invv = 1; rep(i, a) { tmp = tmp * (n - i) % mod; } tmp = tmp * finv[a] % mod; ans = ans + mod - tmp; ans %= mod; tmp = 1; invv = 1; rep(i, b) { tmp = tmp * (n - i) % mod; } tmp = tmp * finv[b] % mod; ans = ans + mod - tmp; ans %= mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; typedef long long ll; typedef pair<int, int> P; const int inf = 1 << 21; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; const ll MAX = 200005; ll fac[MAX], finv[MAX], inv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll com(ll n, ll k) { if (n < k) return 0; if (n < 0 or k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, a, b; cin >> n >> a >> b; ll ans = 1; ll tt = n; ll aa = 2; while (tt > 0) { if (tt & 1) ans = ans * aa % mod; aa = aa * aa % mod; tt >>= 1; } ans--; cominit(); ll tmp = 1; ll invv = 1; rep(i, a) { tmp = tmp * (n - i) % mod; } tmp = tmp * finv[a] % mod; ans = ans + mod - tmp; ans %= mod; tmp = 1; invv = 1; rep(i, b) { tmp = tmp * (n - i) % mod; } tmp = tmp * finv[b] % mod; ans = ans + mod - tmp; ans %= mod; cout << ans << endl; return 0; }
replace
41
44
41
48
TLE
p02768
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 310000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; ll result = n; for (int i = 1; i < k; i++) { result = (result * (n - i)) % MOD; } return result * (finv[k] % MOD) % MOD; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, A, B; cin >> N >> A >> B; COMinit(); ll answer = 1; for (int i = 0; i < N; i++) { answer = (answer * 2) % MOD; } answer--; answer = (answer - COM(N, A) + MOD) % MOD; answer = (answer - COM(N, B) + MOD) % MOD; cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 310000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; ll result = n; for (int i = 1; i < k; i++) { result = (result * (n - i)) % MOD; } return result * (finv[k] % MOD) % MOD; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, A, B; cin >> N >> A >> B; COMinit(); ll answer = 1; ll kisuu = 2; ll temp = N; while (temp > 0) { if (temp & 1) { answer = (answer * kisuu) % MOD; } kisuu = (kisuu * kisuu) % MOD; temp >>= 1; } answer--; answer = (answer - COM(N, A) + MOD) % MOD; answer = (answer - COM(N, B) + MOD) % MOD; cout << answer << endl; return 0; }
replace
41
43
41
49
TLE
p02768
C++
Runtime Error
#include <bits/stdc++.h> #include <type_traits> using namespace std; using ll = int64_t; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define ddrep(i, n) for (int i = n; i > 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define ssrep(i, s, t) for (int i = s; i <= t; ++i) #define rng(a) a.begin(), a.end() #define pb push_back #define eb emplace_back #define fi first #define se second #define chmax(x, y) (x = max(x, y)) #define chmin(x, y) (x = min(x, y)) using pi = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; rep(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } template <typename T, size_t S> void printArray(const T (&array)[S]) { for (auto val : array) std::cout << val << ", "; std::cout << "\n"; } const int mod = 1e9 + 7; const int inf = 1e9 + 5; inline ll mypwn(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return mypwn(x * x % mod, n / 2); else return x * mypwn(x, n - 1) % mod; } inline int madd(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int msub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline int mmul(int x, int y) { return 1ll * x * y % mod; } const int MAX = 1e5 + 5; ll finv[MAX], inv[MAX]; void initComb() { finv[0] = finv[1] = 1; inv[1] = 1; srep(i, 2, MAX) { inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; ll ret = 1; rep(i, k) ret = mmul(ret, n - i); return mmul(ret, finv[k]); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << std::setprecision(10); int n, a, b; std::cin >> n >> a >> b; if (n == 2) { std::cout << '0' << "\n"; return 0; } ll ans = mypwn(2, n) - 1; initComb(); ans = msub(ans, comb(n, a)); ans = msub(ans, comb(n, b)); std::cout << ans << "\n"; }
#include <bits/stdc++.h> #include <type_traits> using namespace std; using ll = int64_t; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define ddrep(i, n) for (int i = n; i > 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define ssrep(i, s, t) for (int i = s; i <= t; ++i) #define rng(a) a.begin(), a.end() #define pb push_back #define eb emplace_back #define fi first #define se second #define chmax(x, y) (x = max(x, y)) #define chmin(x, y) (x = min(x, y)) using pi = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; rep(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } template <typename T, size_t S> void printArray(const T (&array)[S]) { for (auto val : array) std::cout << val << ", "; std::cout << "\n"; } const int mod = 1e9 + 7; const int inf = 1e9 + 5; inline ll mypwn(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return mypwn(x * x % mod, n / 2); else return x * mypwn(x, n - 1) % mod; } inline int madd(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int msub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline int mmul(int x, int y) { return 1ll * x * y % mod; } const int MAX = 2 * 1e5 + 5; ll finv[MAX], inv[MAX]; void initComb() { finv[0] = finv[1] = 1; inv[1] = 1; srep(i, 2, MAX) { inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; ll ret = 1; rep(i, k) ret = mmul(ret, n - i); return mmul(ret, finv[k]); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << std::setprecision(10); int n, a, b; std::cin >> n >> a >> b; if (n == 2) { std::cout << '0' << "\n"; return 0; } ll ans = mypwn(2, n) - 1; initComb(); ans = msub(ans, comb(n, a)); ans = msub(ans, comb(n, b)); std::cout << ans << "\n"; }
replace
76
77
76
77
0
p02768
C++
Time Limit Exceeded
// Created by sz #include <bits/stdc++.h> using namespace std; using ll = long long; int mod = 1e9 + 7; struct modular { int value; modular(long long v = 0) { value = v % mod; if (value < 0) value += mod; } modular(long long a, long long b) : value(0) { *this += a; *this /= b; } modular &operator+=(modular const &b) { value += b.value; if (value >= mod) value -= mod; return *this; } modular &operator-=(modular const &b) { value -= b.value; if (value < 0) value += mod; return *this; } modular &operator*=(modular const &b) { value = (long long)value * b.value % mod; return *this; } // 其他函数调用mexp(modular(10),3); friend modular mexp(modular a, long long e) { modular res = 1; while (e) { if (e & 1) res *= a; a *= a; e >>= 1; } return res; } friend modular inverse(modular a) { return mexp(a, mod - 2); } modular &operator/=(modular const &b) { return *this *= inverse(b); } friend modular operator+(modular a, modular const b) { return a += b; } friend modular operator-(modular a, modular const b) { return a -= b; } friend modular operator-(modular const a) { return 0 - a; } friend modular operator*(modular a, modular const b) { return a *= b; } // 除法只有在mod是素数可用; friend modular operator/(modular a, modular const b) { return a /= b; } friend ostream &operator<<(ostream &os, modular const &a) { return os << a.value; } friend istream &operator>>(istream &is, modular &a) { long long value; is >> value; a.value = 0; a += value; return is; } friend bool operator==(modular const &a, modular const &b) { return a.value == b.value; } friend bool operator!=(modular const &a, modular const &b) { return a.value != b.value; } }; ll quick_pow(ll a, ll b) { ll res = 1; a %= mod; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int main() { #ifdef LOCAL freopen("./input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, a, b; cin >> n >> a >> b; modular ans = 1; for (int i = 0; i < n; i++) { ans *= 2; } ans -= 1; vector<int> fac(max(a, b) + 1), finv(max(a, b) + 1); int to = max(a, b); fac[0] = finv[0] = 1; for (int i = 1; i <= to; ++i) fac[i] = (ll)fac[i - 1] * i % mod; finv[to] = quick_pow(fac[to], mod - 2); for (int i = to - 1; i; --i) finv[i] = (ll)finv[i + 1] * (i + 1) % mod; auto combo = [&](int n, int k) { modular res = 1; for (int i = 0; i < k; i++) { res *= n - i; } res *= finv[k]; return res; }; ans -= combo(n, a); ans -= combo(n, b); cout << ans << "\n"; return 0; }
// Created by sz #include <bits/stdc++.h> using namespace std; using ll = long long; int mod = 1e9 + 7; struct modular { int value; modular(long long v = 0) { value = v % mod; if (value < 0) value += mod; } modular(long long a, long long b) : value(0) { *this += a; *this /= b; } modular &operator+=(modular const &b) { value += b.value; if (value >= mod) value -= mod; return *this; } modular &operator-=(modular const &b) { value -= b.value; if (value < 0) value += mod; return *this; } modular &operator*=(modular const &b) { value = (long long)value * b.value % mod; return *this; } // 其他函数调用mexp(modular(10),3); friend modular mexp(modular a, long long e) { modular res = 1; while (e) { if (e & 1) res *= a; a *= a; e >>= 1; } return res; } friend modular inverse(modular a) { return mexp(a, mod - 2); } modular &operator/=(modular const &b) { return *this *= inverse(b); } friend modular operator+(modular a, modular const b) { return a += b; } friend modular operator-(modular a, modular const b) { return a -= b; } friend modular operator-(modular const a) { return 0 - a; } friend modular operator*(modular a, modular const b) { return a *= b; } // 除法只有在mod是素数可用; friend modular operator/(modular a, modular const b) { return a /= b; } friend ostream &operator<<(ostream &os, modular const &a) { return os << a.value; } friend istream &operator>>(istream &is, modular &a) { long long value; is >> value; a.value = 0; a += value; return is; } friend bool operator==(modular const &a, modular const &b) { return a.value == b.value; } friend bool operator!=(modular const &a, modular const &b) { return a.value != b.value; } }; ll quick_pow(ll a, ll b) { ll res = 1; a %= mod; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int main() { #ifdef LOCAL freopen("./input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, a, b; cin >> n >> a >> b; modular ans = quick_pow(2, n); ans -= 1; vector<int> fac(max(a, b) + 1), finv(max(a, b) + 1); int to = max(a, b); fac[0] = finv[0] = 1; for (int i = 1; i <= to; ++i) fac[i] = (ll)fac[i - 1] * i % mod; finv[to] = quick_pow(fac[to], mod - 2); for (int i = to - 1; i; --i) finv[i] = (ll)finv[i + 1] * (i + 1) % mod; auto combo = [&](int n, int k) { modular res = 1; for (int i = 0; i < k; i++) { res *= n - i; } res *= finv[k]; return res; }; ans -= combo(n, a); ans -= combo(n, b); cout << ans << "\n"; return 0; }
replace
92
97
92
93
TLE
p02768
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; const double PI = acos(-1.0); const ll MOD = 1000000007ll; ll n, a, b; ll kai[200010]; ll inkai[200010]; void input() { cin >> n >> a >> b; } ll power(ll p, ll q) { ll res = 1; while (q > 0) { if (q & 1) res = res * p % MOD; p = p * p % MOD; q >>= 1; } return res; } ll nCr(ll p, ll q) { ll res = 1; for (ll i = 0; i < q; ++i) res = res * (p - i) % MOD; res = res * inkai[q] % MOD; return res; } void solve() { kai[1] = 1ll; for (ll i = 1; i < 200010; ++i) kai[i + 1] = ((i + 1ll) * kai[i]) % MOD; inkai[200005] = power(kai[200005], MOD - 2ll); for (ll i = 200005; i > 0; --i) inkai[i - 1] = i * inkai[i] % MOD; ll ans = power(2, n) - 1ll - nCr(n, a) - nCr(n, b); while (ans < 0) ans += MOD; cout << ans << endl; } int main() { cin.tie(); ios::sync_with_stdio(false); input(); solve(); return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; const double PI = acos(-1.0); const ll MOD = 1000000007ll; ll n, a, b; ll kai[200010]; ll inkai[200010]; void input() { cin >> n >> a >> b; } ll power(ll p, ll q) { ll res = 1; while (q > 0) { if (q & 1) res = res * p % MOD; p = p * p % MOD; q >>= 1; } return res; } ll nCr(ll p, ll q) { ll res = 1; for (ll i = 0; i < q; ++i) res = res * (p - i) % MOD; res = res * inkai[q] % MOD; return res; } void solve() { kai[1] = 1ll; for (ll i = 1; i < 200005; ++i) kai[i + 1] = ((i + 1ll) * kai[i]) % MOD; inkai[200005] = power(kai[200005], MOD - 2ll); for (ll i = 200005; i > 0; --i) inkai[i - 1] = i * inkai[i] % MOD; ll ans = power(2, n) - 1ll - nCr(n, a) - nCr(n, b); while (ans < 0) ans += MOD; cout << ans << endl; } int main() { cin.tie(); ios::sync_with_stdio(false); input(); solve(); return 0; }
replace
38
39
38
39
0
p02768
C++
Time Limit Exceeded
#include <bits/stdc++.h> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #define clz __builtin_clzll #define popcount __builtin_popcountll #define FORS(i, s, n) for (i64 i = (s); i < (n); ++i) #define RFORS(i, s, n) for (i64 i = (n)-1; i >= (s); --i) #define FOR(i, n) FORS(i, 0, n) #define RFOR(i, n) RFORS(i, 0, n) #define FI(n) FOR(i, n) #define RFI(n) RFOR(i, n) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SZ(c) i64((c).size()) #define FOR_SETTED_BIT(bit, mask) \ for (int bit = 0; (mask) >> bit; ++bit) \ if (1 & (mask >> bit)) #define FOR_NONZERO_SUBMASK(submask, mask) \ for (int submask = (mask); submask; submask = (submask - 1) & (mask)) #define PI (3.141592653589793L) #define MODULO ((i64)1e9 + 7LL) using namespace std; typedef int_fast8_t i8; typedef int_fast16_t i16; typedef int_fast32_t i32; typedef int_fast64_t i64; typedef uint_fast8_t u8; typedef uint_fast16_t u16; typedef uint_fast32_t u32; typedef uint_fast64_t u64; typedef pair<i64, i64> pi64; typedef vector<i8> vb; typedef vector<i32> vi32; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef vector<list<int>> AdjacencyLists; typedef vector<list<pair<int, i64>>> WeightedAdjacencyLists; typedef vvi64 AdjacencyMatrix; template <class T> inline T sqr(const T &x) { return x * x; } inline i64 sqr(int x) { return sqr<i64>(x); } template <class T> T binpow(const T &a, i64 n) { return n == T(0) ? T(1) : sqr(binpow(a, n / 2)) * (n % 2 ? a : T(1)); } i64 binpow(i64 a, i64 n, i64 modulo) { return n == 0 ? 1 : sqr(binpow(a, n / 2, modulo)) % modulo * (n % 2 ? a : 1) % modulo; } constexpr inline i64 phi(i64 n) { i64 result = n; for (i64 i = 2; i * i <= n; ++i) if (n % i == 0) { while (n % i == 0) n /= i; result -= result / i; } if (n > 1) result -= result / n; return result; } inline vi64 inverseAll(i64 m) { vi64 r(m); r[1] = 1; for (int i = 2; i < m; ++i) r[i] = (m - (m / i) * r[m % i] % m) % m; return r; } i64 gcd(i64 a, i64 b, i64 &x, i64 &y) { if (a == 0) { x = 0; y = 1; return b; } i64 x1, y1; i64 d = gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } inline i64 gcd(i64 a, i64 b) { return gcd(a, b, a, b); } inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; } template <class T, const T modulo, class TT = i64> class IntModulo { constexpr static const T order = phi(modulo); T value; public: explicit IntModulo(const TT &value = 0) : value(T(((abs(value) + modulo - TT(1)) / modulo * modulo + value) % modulo)) {} inline IntModulo &operator+=(const IntModulo &i) { value = T((TT(value) + TT(i.value)) % modulo); return *this; } inline IntModulo &operator-=(const IntModulo &i) { return *this += -i; } inline IntModulo &operator*=(const IntModulo &i) { value = T((TT(value) * TT(i.value)) % modulo); return *this; } inline IntModulo &operator/=(const IntModulo &i) { return *this *= i.inverse(); }; inline IntModulo inverse() const { return binpow(*this, order - 1); }; inline operator T() const { return value; } friend inline IntModulo operator-(const IntModulo &i) { return IntModulo<T, modulo, TT>(modulo - i.value); } friend inline bool operator==(const IntModulo &a, const IntModulo &b) { return a.value == b.value; } }; template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator+(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) += b; } template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator-(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) -= b; } template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator*(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) *= b; } template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator/(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) /= b; } template <class T, const T modulo, class TT = i64> inline bool operator!=(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return !(a == b); } mt19937_64 rng( #ifdef DEBUG 0LL #else chrono::steady_clock::now().time_since_epoch().count() #endif ); inline i64 random(i64 low, i64 high) { return uniform_int_distribution<i64>(low, high)(rng); } inline i64 random(i64 high = numeric_limits<i64>::max()) { return random(0, high); } #define rand random struct Dinic { struct Edge { int u, v; i64 cap, flow; Edge() {} Edge(int u, int v, i64 cap) : u(u), v(v), cap(cap), flow(0) {} }; int N; vector<Edge> E; vector<vector<int>> g; vector<int> d, pt; Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {} void AddEdge(int u, int v, i64 cap) { if (u != v) { E.emplace_back(Edge(u, v, cap)); g[u].emplace_back(E.size() - 1); E.emplace_back(Edge(v, u, 0)); g[v].emplace_back(E.size() - 1); } } bool BFS(int S, int T) { queue<int> q({S}); fill(d.begin(), d.end(), N + 1); d[S] = 0; while (!q.empty()) { int u = q.front(); q.pop(); if (u == T) break; for (int k : g[u]) { Edge &e = E[k]; if (e.flow < e.cap && d[e.v] > d[e.u] + 1) { d[e.v] = d[e.u] + 1; q.emplace(e.v); } } } return d[T] != N + 1; } i64 DFS(int u, int T, i64 flow = -1) { if (u == T || flow == 0) return flow; for (int &i = pt[u]; i < g[u].size(); ++i) { Edge &e = E[g[u][i]]; Edge &oe = E[g[u][i] ^ 1]; if (d[e.v] == d[e.u] + 1) { i64 amt = e.cap - e.flow; if (flow != -1 && amt > flow) amt = flow; if (i64 pushed = DFS(e.v, T, amt)) { e.flow += pushed; oe.flow -= pushed; return pushed; } } } return 0; } i64 MaxFlow(int S, int T) { i64 total = 0; while (BFS(S, T)) { fill(pt.begin(), pt.end(), 0); while (i64 flow = DFS(S, T)) total += flow; } return total; } }; vi64 Dijkstra(const WeightedAdjacencyLists &g, int s) { vi64 d(SZ(g), numeric_limits<i64>::max() / 2LL); priority_queue<pair<i64, int>> q; d[s] = 0; q.emplace(-0, s); while (!q.empty()) { if (q.top().first > d[q.top().second]) { q.pop(); continue; } int v = q.top().second; q.pop(); for (const auto &cw : g[v]) { if (d[v] + cw.second < d[cw.first]) { d[cw.first] = d[v] + cw.second; q.emplace(-d[cw.first], cw.first); } } } return d; } struct UnionFind { vi64 parent; vi64 rank; UnionFind(i64 n) : parent(n), rank(n) { for (i64 i = 0; i < n; ++i) { parent[i] = i; rank[i] = 0; } } i64 find_set(i64 v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(i64 a, i64 b) { a = find_set(a); b = find_set(b); if (a != b) { if (rank[a] < rank[b]) swap(a, b); parent[b] = a; if (rank[a] == rank[b]) ++rank[a]; } } }; // https://codeforces.com/blog/entry/18051 template <class T> const T assign(const T &a, const T &b) { return b; } template <class T> const T &my_min(const T &a, const T &b) { return a < b ? a : b; } template <class T> struct SegmentTree { typedef function<T(T, T)> Function; const i64 n; vector<T> t; const function<T(const T &, const T &)> operation; const T &operation_default_value; const function<T(const T &, const T &)> modification; const T &modification_default_value; SegmentTree() {} SegmentTree(const i64 n, Function operation, const T &operation_default_value = T(), Function modification = assign<T>, const T &modification_default_value = T()) : n(n), t(n << 1, operation_default_value), operation(operation), operation_default_value(operation_default_value), modification(modification), modification_default_value(modification_default_value) { build(); } template <class Iterator> SegmentTree(const Iterator &begin, const Iterator &end, Function operation, const T &operation_default_value = T(), Function modification = assign<T>, const T &modification_default_value = T()) : SegmentTree(end - begin, operation, operation_default_value, modification, modification_default_value) { copy(begin, end, t.begin() + n); build(); } void build() { for (i64 i = n - 1; i > 0; --i) t[i] = operation(t[i << 1], t[i << 1 | 1]); } void modify(i64 p, const T &value) { p += n; for (t[p] = modification(t[p], value); p > 1; p >>= 1) t[p >> 1] = operation(t[p], t[p ^ 1]); } T query(i64 l, i64 r) const { // [l, r) T res = operation_default_value; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) res = operation(res, t[l++]); if (r & 1) res = operation(res, t[--r]); } return res; } }; inline i64 factorial(i64 n) { i64 answer = 1; FORS(i, 2, 1 + n) { answer *= i; answer %= MODULO; } return answer; } inline i64 inv(i64 n) { return binpow(n, MODULO - 2, MODULO); } inline i64 choose(i64 n, i64 k) { i64 answer = 1; FORS(i, n - k + 1, 1 + n) { answer *= i; answer %= MODULO; } answer *= inv(factorial(k)); answer %= MODULO; return answer; } int main(int argc, const char *argv[]) { #ifdef DEBUG assert(choose(4, 3) == 4); #endif ios::sync_with_stdio(false); cin.tie(0); cout.precision(13); cout.setf(ios::fixed); srand((unsigned int)time(NULL)); // enter your code here int n, a, b; while (scanf("%d%d%d", &n, &a, &b)) { printf("%d\n", int((binpow(2LL, n, MODULO) - 1 - choose(n, a) - choose(n, b) + 3 * MODULO) % MODULO)); } return 0; }
#include <bits/stdc++.h> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #define clz __builtin_clzll #define popcount __builtin_popcountll #define FORS(i, s, n) for (i64 i = (s); i < (n); ++i) #define RFORS(i, s, n) for (i64 i = (n)-1; i >= (s); --i) #define FOR(i, n) FORS(i, 0, n) #define RFOR(i, n) RFORS(i, 0, n) #define FI(n) FOR(i, n) #define RFI(n) RFOR(i, n) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SZ(c) i64((c).size()) #define FOR_SETTED_BIT(bit, mask) \ for (int bit = 0; (mask) >> bit; ++bit) \ if (1 & (mask >> bit)) #define FOR_NONZERO_SUBMASK(submask, mask) \ for (int submask = (mask); submask; submask = (submask - 1) & (mask)) #define PI (3.141592653589793L) #define MODULO ((i64)1e9 + 7LL) using namespace std; typedef int_fast8_t i8; typedef int_fast16_t i16; typedef int_fast32_t i32; typedef int_fast64_t i64; typedef uint_fast8_t u8; typedef uint_fast16_t u16; typedef uint_fast32_t u32; typedef uint_fast64_t u64; typedef pair<i64, i64> pi64; typedef vector<i8> vb; typedef vector<i32> vi32; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef vector<list<int>> AdjacencyLists; typedef vector<list<pair<int, i64>>> WeightedAdjacencyLists; typedef vvi64 AdjacencyMatrix; template <class T> inline T sqr(const T &x) { return x * x; } inline i64 sqr(int x) { return sqr<i64>(x); } template <class T> T binpow(const T &a, i64 n) { return n == T(0) ? T(1) : sqr(binpow(a, n / 2)) * (n % 2 ? a : T(1)); } i64 binpow(i64 a, i64 n, i64 modulo) { return n == 0 ? 1 : sqr(binpow(a, n / 2, modulo)) % modulo * (n % 2 ? a : 1) % modulo; } constexpr inline i64 phi(i64 n) { i64 result = n; for (i64 i = 2; i * i <= n; ++i) if (n % i == 0) { while (n % i == 0) n /= i; result -= result / i; } if (n > 1) result -= result / n; return result; } inline vi64 inverseAll(i64 m) { vi64 r(m); r[1] = 1; for (int i = 2; i < m; ++i) r[i] = (m - (m / i) * r[m % i] % m) % m; return r; } i64 gcd(i64 a, i64 b, i64 &x, i64 &y) { if (a == 0) { x = 0; y = 1; return b; } i64 x1, y1; i64 d = gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } inline i64 gcd(i64 a, i64 b) { return gcd(a, b, a, b); } inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; } template <class T, const T modulo, class TT = i64> class IntModulo { constexpr static const T order = phi(modulo); T value; public: explicit IntModulo(const TT &value = 0) : value(T(((abs(value) + modulo - TT(1)) / modulo * modulo + value) % modulo)) {} inline IntModulo &operator+=(const IntModulo &i) { value = T((TT(value) + TT(i.value)) % modulo); return *this; } inline IntModulo &operator-=(const IntModulo &i) { return *this += -i; } inline IntModulo &operator*=(const IntModulo &i) { value = T((TT(value) * TT(i.value)) % modulo); return *this; } inline IntModulo &operator/=(const IntModulo &i) { return *this *= i.inverse(); }; inline IntModulo inverse() const { return binpow(*this, order - 1); }; inline operator T() const { return value; } friend inline IntModulo operator-(const IntModulo &i) { return IntModulo<T, modulo, TT>(modulo - i.value); } friend inline bool operator==(const IntModulo &a, const IntModulo &b) { return a.value == b.value; } }; template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator+(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) += b; } template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator-(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) -= b; } template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator*(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) *= b; } template <class T, const T modulo, class TT = i64> inline IntModulo<T, modulo, TT> operator/(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return IntModulo<T, modulo, TT>(a) /= b; } template <class T, const T modulo, class TT = i64> inline bool operator!=(const IntModulo<T, modulo, TT> &a, const IntModulo<T, modulo, TT> &b) { return !(a == b); } mt19937_64 rng( #ifdef DEBUG 0LL #else chrono::steady_clock::now().time_since_epoch().count() #endif ); inline i64 random(i64 low, i64 high) { return uniform_int_distribution<i64>(low, high)(rng); } inline i64 random(i64 high = numeric_limits<i64>::max()) { return random(0, high); } #define rand random struct Dinic { struct Edge { int u, v; i64 cap, flow; Edge() {} Edge(int u, int v, i64 cap) : u(u), v(v), cap(cap), flow(0) {} }; int N; vector<Edge> E; vector<vector<int>> g; vector<int> d, pt; Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {} void AddEdge(int u, int v, i64 cap) { if (u != v) { E.emplace_back(Edge(u, v, cap)); g[u].emplace_back(E.size() - 1); E.emplace_back(Edge(v, u, 0)); g[v].emplace_back(E.size() - 1); } } bool BFS(int S, int T) { queue<int> q({S}); fill(d.begin(), d.end(), N + 1); d[S] = 0; while (!q.empty()) { int u = q.front(); q.pop(); if (u == T) break; for (int k : g[u]) { Edge &e = E[k]; if (e.flow < e.cap && d[e.v] > d[e.u] + 1) { d[e.v] = d[e.u] + 1; q.emplace(e.v); } } } return d[T] != N + 1; } i64 DFS(int u, int T, i64 flow = -1) { if (u == T || flow == 0) return flow; for (int &i = pt[u]; i < g[u].size(); ++i) { Edge &e = E[g[u][i]]; Edge &oe = E[g[u][i] ^ 1]; if (d[e.v] == d[e.u] + 1) { i64 amt = e.cap - e.flow; if (flow != -1 && amt > flow) amt = flow; if (i64 pushed = DFS(e.v, T, amt)) { e.flow += pushed; oe.flow -= pushed; return pushed; } } } return 0; } i64 MaxFlow(int S, int T) { i64 total = 0; while (BFS(S, T)) { fill(pt.begin(), pt.end(), 0); while (i64 flow = DFS(S, T)) total += flow; } return total; } }; vi64 Dijkstra(const WeightedAdjacencyLists &g, int s) { vi64 d(SZ(g), numeric_limits<i64>::max() / 2LL); priority_queue<pair<i64, int>> q; d[s] = 0; q.emplace(-0, s); while (!q.empty()) { if (q.top().first > d[q.top().second]) { q.pop(); continue; } int v = q.top().second; q.pop(); for (const auto &cw : g[v]) { if (d[v] + cw.second < d[cw.first]) { d[cw.first] = d[v] + cw.second; q.emplace(-d[cw.first], cw.first); } } } return d; } struct UnionFind { vi64 parent; vi64 rank; UnionFind(i64 n) : parent(n), rank(n) { for (i64 i = 0; i < n; ++i) { parent[i] = i; rank[i] = 0; } } i64 find_set(i64 v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(i64 a, i64 b) { a = find_set(a); b = find_set(b); if (a != b) { if (rank[a] < rank[b]) swap(a, b); parent[b] = a; if (rank[a] == rank[b]) ++rank[a]; } } }; // https://codeforces.com/blog/entry/18051 template <class T> const T assign(const T &a, const T &b) { return b; } template <class T> const T &my_min(const T &a, const T &b) { return a < b ? a : b; } template <class T> struct SegmentTree { typedef function<T(T, T)> Function; const i64 n; vector<T> t; const function<T(const T &, const T &)> operation; const T &operation_default_value; const function<T(const T &, const T &)> modification; const T &modification_default_value; SegmentTree() {} SegmentTree(const i64 n, Function operation, const T &operation_default_value = T(), Function modification = assign<T>, const T &modification_default_value = T()) : n(n), t(n << 1, operation_default_value), operation(operation), operation_default_value(operation_default_value), modification(modification), modification_default_value(modification_default_value) { build(); } template <class Iterator> SegmentTree(const Iterator &begin, const Iterator &end, Function operation, const T &operation_default_value = T(), Function modification = assign<T>, const T &modification_default_value = T()) : SegmentTree(end - begin, operation, operation_default_value, modification, modification_default_value) { copy(begin, end, t.begin() + n); build(); } void build() { for (i64 i = n - 1; i > 0; --i) t[i] = operation(t[i << 1], t[i << 1 | 1]); } void modify(i64 p, const T &value) { p += n; for (t[p] = modification(t[p], value); p > 1; p >>= 1) t[p >> 1] = operation(t[p], t[p ^ 1]); } T query(i64 l, i64 r) const { // [l, r) T res = operation_default_value; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) res = operation(res, t[l++]); if (r & 1) res = operation(res, t[--r]); } return res; } }; inline i64 factorial(i64 n) { i64 answer = 1; FORS(i, 2, 1 + n) { answer *= i; answer %= MODULO; } return answer; } inline i64 inv(i64 n) { return binpow(n, MODULO - 2, MODULO); } inline i64 choose(i64 n, i64 k) { i64 answer = 1; FORS(i, n - k + 1, 1 + n) { answer *= i; answer %= MODULO; } answer *= inv(factorial(k)); answer %= MODULO; return answer; } int main(int argc, const char *argv[]) { #ifdef DEBUG assert(choose(4, 3) == 4); #endif ios::sync_with_stdio(false); cin.tie(0); cout.precision(13); cout.setf(ios::fixed); srand((unsigned int)time(NULL)); // enter your code here int n, a, b; while (~scanf("%d%d%d", &n, &a, &b)) { printf("%d\n", int((binpow(2LL, n, MODULO) - 1 - choose(n, a) - choose(n, b) + 3 * MODULO) % MODULO)); } return 0; }
replace
406
407
406
407
TLE
p02768
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define all(x) begin(x), end(x) typedef long long ll; typedef pair<int, int> pii; const int inf = 1010001000; const ll INF = 1001000100010001000; const int mod = (int)1e9 + 7; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vector<long long> fact, fact_inv, inv; // fact[i]=i! nが10^7より大きいと配列が大きすぎる? void init_nCk(int SIZE) { // inv[i]=i^(-1) fact.resize(SIZE + 5); // fact_inv[i]=inv[i]の累積積 fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact[0] = fact[1] = 1; fact_inv[0] = fact_inv[1] = 1; inv[1] = 1; for (int i = 2; i < SIZE + 5; i++) { fact[i] = fact[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; fact_inv[i] = fact_inv[i - 1] * inv[i] % mod; } } /* nCk :MODでの二項係数を求める(前処理 int_nCk が必要) 計算量:O(1) */ long long nCk(int n, int k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); if (n <= 10000000) return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod; else { ll ans = 1; for (ll i = n; i > n - k; i--) { ans = ans * i % mod; } for (ll i = 1; i <= k; i++) { ans = (ans * modpow(i, mod - 2)) % mod; } return ans; } } int main() { int n, a, b; cin >> n >> a >> b; cout << (2 * mod + modpow(2, n) - 1 - nCk(n, a) - nCk(n, b)) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define all(x) begin(x), end(x) typedef long long ll; typedef pair<int, int> pii; const int inf = 1010001000; const ll INF = 1001000100010001000; const int mod = (int)1e9 + 7; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vector<long long> fact, fact_inv, inv; // fact[i]=i! nが10^7より大きいと配列が大きすぎる? void init_nCk(int SIZE) { // inv[i]=i^(-1) fact.resize(SIZE + 5); // fact_inv[i]=inv[i]の累積積 fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact[0] = fact[1] = 1; fact_inv[0] = fact_inv[1] = 1; inv[1] = 1; for (int i = 2; i < SIZE + 5; i++) { fact[i] = fact[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; fact_inv[i] = fact_inv[i - 1] * inv[i] % mod; } } /* nCk :MODでの二項係数を求める(前処理 int_nCk が必要) 計算量:O(1) */ long long nCk(int n, int k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); if (n <= 10000000) return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod; else { ll ans = 1; for (ll i = n; i > n - k; i--) { ans = ans * i % mod; } for (ll i = 1; i <= k; i++) { ans = (ans * modpow(i, mod - 2)) % mod; } return ans; } } int main() { int n, a, b; cin >> n >> a >> b; init_nCk(510000); cout << (2 * mod + modpow(2, n) - 1 - nCk(n, a) - nCk(n, b)) % mod << endl; return 0; }
insert
61
61
61
62
-11
p02768
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define chmin(x, y) x = min(x, y) using namespace std; typedef long long ll; typedef pair<int, int> P; const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int main() { ll n; int a, b; cin >> n >> a >> b; combination comb(n); mint res(2); mint ans = res.pow(n) - comb(n, a) - comb(n, b); std::cout << ans.x - 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define chmin(x, y) x = min(x, y) using namespace std; typedef long long ll; typedef pair<int, int> P; const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int main() { ll n; int a, b; cin >> n >> a >> b; mint res(2), temp(1); mint ans = res.pow(n); if (a > b) swap(a, b); for (int i = 1; i <= b; ++i) { temp *= (n - i + 1); temp /= i; if (i == a || i == b) ans -= temp; } std::cout << ans.x - 1 << endl; return 0; }
replace
78
81
78
88
0
p02768
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; long long mod = 1e9 + 7; struct nCk { long long pow(long long x, long long n) { long long ret = 1; if (n > 0) { ret = pow(x, n / 2); if (n % 2 == 0) { (ret = (ret * ret)) %= mod; } else { (ret = ((ret * ret) % mod) * x) %= mod; } } return ret; } long long inv(long long n) { return pow(n, mod - 2); } long long nck(long long n, long long k) { long long ret = 1; for (int i = n; i > n - k; i--) { (ret *= i) %= mod; } for (int i = k; i >= 1; i--) { (ret *= inv(i)) %= mod; } return ret; } }; int main() { long long n, a, b; cin >> n >> a >> b; nCk nii; long long ans = 1; for (int i = 0; i < n; i++) { (ans *= 2) %= mod; } (ans += mod - 1) %= mod; long long A = nii.nck(n, a); long long B = nii.nck(n, b); (ans += mod - A) %= mod; (ans += mod - B) %= mod; cout << ans << endl; return 0; }
#include <iostream> #include <vector> using namespace std; long long mod = 1e9 + 7; struct nCk { long long pow(long long x, long long n) { long long ret = 1; if (n > 0) { ret = pow(x, n / 2); if (n % 2 == 0) { (ret = (ret * ret)) %= mod; } else { (ret = ((ret * ret) % mod) * x) %= mod; } } return ret; } long long inv(long long n) { return pow(n, mod - 2); } long long nck(long long n, long long k) { long long ret = 1; for (int i = n; i > n - k; i--) { (ret *= i) %= mod; } for (int i = k; i >= 1; i--) { (ret *= inv(i)) %= mod; } return ret; } }; int main() { long long n, a, b; cin >> n >> a >> b; nCk nii; long long ans = nii.pow(2, n); (ans += mod - 1) %= mod; long long A = nii.nck(n, a); long long B = nii.nck(n, b); (ans += mod - A) %= mod; (ans += mod - B) %= mod; cout << ans << endl; return 0; }
replace
33
37
33
34
TLE
p02768
C++
Runtime Error
#include <bits/stdc++.h> // #include <unistd.h> // #include <iostream> using namespace std; #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl; #define DEBUG_MAT(v) \ cerr << #v << endl; \ for (int i = 0; i < v.size(); i++) { \ for (int j = 0; j < v[i].size(); j++) { \ cerr << v[i][j] << " "; \ } \ cerr << endl; \ } typedef long long ll; // #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector<vector<int>> #define vll vector<vector<ll>> #define vs vector<string> #define pii pair<int, int> #define pis pair<int, string> #define psi pair<string, int> #define pll pair<ll, ll> template <class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template <class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rrep1(i, n) for (int i = (n); i > 0; i--) #define REP(i, a, b) for (int i = a; i < b; i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(), c.end() template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout << setprecision(25) << fixed << p << endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; vi dx2 = {1, 1, 0, -1, -1, -1, 0, 1}, dy2 = {0, 1, 1, 1, 0, -1, -1, -1}; #define fio() \ cin.tie(0); \ ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair // #define endl '\n' const int MAXN = 200010; vl fact(MAXN); vl rfact(MAXN); ll mod_pow(ll x, ll p, ll M = MOD) { if (p < 0) { x = mod_pow(x, M - 2, M); p = -p; } ll a = 1; while (p) { if (p % 2) a = a * x % M; x = x * x % M; p /= 2; } return a; } ll mod_inverse(ll a, ll M = MOD) { return mod_pow(a, M - 2, M); } void set_fact(ll n, ll M = MOD) { fact[0] = fact[1] = rfact[0] = rfact[1] = 1; for (ll i = 2; i <= n; i++) { fact[i] = i * fact[i - 1] % M; // rfact[i] = mod_inverse(fact[i], M); } } // http://drken1215.hatenablog.com/entry/2018/06/08/210000 // n���傫��fact���v�Z�ł��Ȃ��Ƃ��̂ق��̌v�Z���@�ɂ‚��ď����Ă��� ll nCr(ll n, ll r, ll M = MOD) { ll ans = 1; for (int i = 0; i < r; i++) { ans = ans * (n - i) % MOD; } ans = ans * mod_inverse(fact[r]) % MOD; return ans; } ll nHr(ll n, ll r) { return nCr(n + r - 1, r); } signed main() { fio(); set_fact(211111); ll n, a, b; cin >> n >> a >> b; ll ans = mod_pow(2, n) - 1 - nCr(n, a) - nCr(n, b); ans = (ans % MOD + MOD) % MOD; cout << ans << endl; }
#include <bits/stdc++.h> // #include <unistd.h> // #include <iostream> using namespace std; #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl; #define DEBUG_MAT(v) \ cerr << #v << endl; \ for (int i = 0; i < v.size(); i++) { \ for (int j = 0; j < v[i].size(); j++) { \ cerr << v[i][j] << " "; \ } \ cerr << endl; \ } typedef long long ll; // #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector<vector<int>> #define vll vector<vector<ll>> #define vs vector<string> #define pii pair<int, int> #define pis pair<int, string> #define psi pair<string, int> #define pll pair<ll, ll> template <class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template <class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rrep1(i, n) for (int i = (n); i > 0; i--) #define REP(i, a, b) for (int i = a; i < b; i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(), c.end() template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout << setprecision(25) << fixed << p << endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; vi dx2 = {1, 1, 0, -1, -1, -1, 0, 1}, dy2 = {0, 1, 1, 1, 0, -1, -1, -1}; #define fio() \ cin.tie(0); \ ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair // #define endl '\n' const int MAXN = 222222; vl fact(MAXN); vl rfact(MAXN); ll mod_pow(ll x, ll p, ll M = MOD) { if (p < 0) { x = mod_pow(x, M - 2, M); p = -p; } ll a = 1; while (p) { if (p % 2) a = a * x % M; x = x * x % M; p /= 2; } return a; } ll mod_inverse(ll a, ll M = MOD) { return mod_pow(a, M - 2, M); } void set_fact(ll n, ll M = MOD) { fact[0] = fact[1] = rfact[0] = rfact[1] = 1; for (ll i = 2; i <= n; i++) { fact[i] = i * fact[i - 1] % M; // rfact[i] = mod_inverse(fact[i], M); } } // http://drken1215.hatenablog.com/entry/2018/06/08/210000 // n���傫��fact���v�Z�ł��Ȃ��Ƃ��̂ق��̌v�Z���@�ɂ‚��ď����Ă��� ll nCr(ll n, ll r, ll M = MOD) { ll ans = 1; for (int i = 0; i < r; i++) { ans = ans * (n - i) % MOD; } ans = ans * mod_inverse(fact[r]) % MOD; return ans; } ll nHr(ll n, ll r) { return nCr(n + r - 1, r); } signed main() { fio(); set_fact(211111); ll n, a, b; cin >> n >> a >> b; ll ans = mod_pow(2, n) - 1 - nCr(n, a) - nCr(n, b); ans = (ans % MOD + MOD) % MOD; cout << ans << endl; }
replace
85
86
85
86
-11
p02768
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define inf 0x3f3f3f3f using namespace std; typedef long long LL; typedef pair<int, int> pll; const int maxn = 1e5 + 10; const int p = 1e9 + 7; const double EPS = 1e-6; LL quick_mod(LL a, LL b) { LL ans = 1; a %= p; while (b) { if (b & 1) { ans = ans * a % p; b--; } b >>= 1; a = a * a % p; } return ans; } LL C(LL n, LL m) { if (m > n) return 0; LL ans = 1; for (int i = 1; i <= m; i++) { LL a = (n + i - m) % p; LL b = i % p; ans = ans * (a * quick_mod(b, p - 2) % p) % p; } return ans; } LL Lucas(LL n, LL m) { if (m == 0) return 1; return C(n % p, m % p) * Lucas(n / p, m / p) % p; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, a, b; cin >> n >> a >> b; LL ans = 0; for (int i = 1; i <= n / 2; i++) { // int d=Lucas(n,i); if (i * 2 < n) { ans = (ans + 2 * Lucas(n, i) % p) % p; } else { ans = (ans + Lucas(n, i)) % p; } } /*cout << ans << endl; cout << Lucas(n,a) << endl; cout << Lucas(n,b) << endl;*/ cout << (ans + 1 - Lucas(n, a) - Lucas(n, b)) % p << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define inf 0x3f3f3f3f using namespace std; typedef long long LL; typedef pair<int, int> pll; const int maxn = 1e5 + 10; const int p = 1e9 + 7; const double EPS = 1e-6; LL quick_mod(LL a, LL b) { LL ans = 1; a %= p; while (b) { if (b & 1) { ans = ans * a % p; b--; } b >>= 1; a = a * a % p; } return ans; } LL C(LL n, LL m) { if (m > n) return 0; LL ans = 1; for (int i = 1; i <= m; i++) { LL a = (n + i - m) % p; LL b = i % p; ans = ans * (a * quick_mod(b, p - 2) % p) % p; } return ans; } LL Lucas(LL n, LL m) { if (m == 0) return 1; return C(n % p, m % p) * Lucas(n / p, m / p) % p; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, a, b; cin >> n >> a >> b; // cout << quick_mod(2,n) << " " << Lucas(n,a) << " " << Lucas(n,b) << endl; cout << ((quick_mod(2, n) - 1 - Lucas(n, a) + p) % p - Lucas(n, b) + p) % p << endl; return 0; }
replace
57
71
57
60
TLE
p02769
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; const int MAX{200010}; const ll MOD{1000000007}, oo{1LL << 62}; ll fs[MAX], inv[MAX]; ll mod_pow(ll a, ll n) { ll res = 1, base = a; while (n) { if (n & 1) res = (res * base) % MOD; base = (base * base) % MOD; n >>= 1; } return res; } void precomp() { fs[0] = 1; for (ll i = 1; i < MAX; ++i) fs[i] = (fs[i - 1] * i) % MOD; inv[0] = 1; for (ll i = 1; i < MAX; ++i) inv[i] = mod_pow(fs[i], MOD - 2); } ll mod(ll a) { return (((a % MOD) + MOD) % MOD); } ll binom(ll n, ll m) { ll res = mod(fs[n] * inv[m]); res = mod(res * inv[n - m]); return res; } ll solve(ll N, ll K) { if (K >= N - 1) return binom(2 * N - 1, N - 1); ll ans = 0; for (int k = 0; k <= K; ++k) { ll x = mod(binom(N - 1, k) * binom(N, k)); ans = mod(ans + x); } return ans; } int main() { ios::sync_with_stdio(false); precomp(); ll N, K; cin >> N >> K; auto ans = solve(N, K); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; const int MAX{400010}; const ll MOD{1000000007}, oo{1LL << 62}; ll fs[MAX], inv[MAX]; ll mod_pow(ll a, ll n) { ll res = 1, base = a; while (n) { if (n & 1) res = (res * base) % MOD; base = (base * base) % MOD; n >>= 1; } return res; } void precomp() { fs[0] = 1; for (ll i = 1; i < MAX; ++i) fs[i] = (fs[i - 1] * i) % MOD; inv[0] = 1; for (ll i = 1; i < MAX; ++i) inv[i] = mod_pow(fs[i], MOD - 2); } ll mod(ll a) { return (((a % MOD) + MOD) % MOD); } ll binom(ll n, ll m) { ll res = mod(fs[n] * inv[m]); res = mod(res * inv[n - m]); return res; } ll solve(ll N, ll K) { if (K >= N - 1) return binom(2 * N - 1, N - 1); ll ans = 0; for (int k = 0; k <= K; ++k) { ll x = mod(binom(N - 1, k) * binom(N, k)); ans = mod(ans + x); } return ans; } int main() { ios::sync_with_stdio(false); precomp(); ll N, K; cin >> N >> K; auto ans = solve(N, K); cout << ans << '\n'; return 0; }
replace
6
7
6
7
0
p02769
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; typedef long long ll; const int N = 1e5 + 10; ll a[N]; ll qmi(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } ll c(ll n, ll m) { return a[n] % mod * qmi(a[m], mod - 2) % mod * qmi(a[n - m], mod - 2) % mod; } int main() { a[0] = 1; for (int i = 1; i < N; i++) a[i] = a[i - 1] * i % mod; ll ans = 0; ll n, k; cin >> n >> k; for (int i = 0; i <= min(k, n - 1); i++) ans = (ans + c(n, i) * c(n - 1, i) % mod) % mod; //, cout << ans << endl ; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; typedef long long ll; const int N = 2e5 + 10; ll a[N]; ll qmi(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } ll c(ll n, ll m) { return a[n] % mod * qmi(a[m], mod - 2) % mod * qmi(a[n - m], mod - 2) % mod; } int main() { a[0] = 1; for (int i = 1; i < N; i++) a[i] = a[i - 1] * i % mod; ll ans = 0; ll n, k; cin >> n >> k; for (int i = 0; i <= min(k, n - 1); i++) ans = (ans + c(n, i) * c(n - 1, i) % mod) % mod; //, cout << ans << endl ; printf("%lld\n", ans); return 0; }
replace
4
5
4
5
0
p02769
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 10; const ll p = 1e9 + 7; int a[N]; ll inv(ll a, ll p) { // p为素数,a<p if (a == 1) return 1; return (p - p / a) * inv(p % a, p) % p; } ll C(ll n, ll m) { ll res = 1; for (ll i = 1, j = n - m + 1; i <= m; ++i, ++j) { res = res * inv(i, p) % p * j % p; } return res; } int main() { ll n, m; cin >> n >> m; ll res = 0; for (int i = 0; i <= min(m, n - 1); ++i) res = (res + C(n, i) * C(n - 1, i) % p) % p; cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 10; const ll p = 1e9 + 7; int a[N]; ll inv(ll a, ll p) { // p为素数,a<p if (a == 1) return 1; return (p - p / a) * inv(p % a, p) % p; } ll C(ll n, ll m) { ll res = 1; for (ll i = 1, j = n - m + 1; i <= m; ++i, ++j) { res = res * inv(i, p) % p * j % p; } return res; } int main() { ll n, m; cin >> n >> m; ll res = 0; ll C1 = 1, C2 = 1; for (int i = 0; i <= min(m, n - 1); ++i) { res = (res + C1 * C2 % p) % p; C1 = C1 * inv(i + 1, p) % p * (n - i) % p; C2 = C2 * inv(i + 1, p) % p * (n - i - 1) % p; } cout << res; return 0; }
replace
22
24
22
28
TLE
p02769
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define r1(i, n) for (int i = 0; i < n; i++) #define r2(i, n) for (int i = 1; i < n; i++) #define intc(n) \ int n; \ cin >> n; #define ll long long #define llc(n) \ ll n; \ cin >> n; using namespace std; // テーブルを作る前処理 const ll MAX = 300000; const ll mod = 1000000007; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main() { COMinit(); ll n, k, ans = 0; cin >> n >> k; r1(i, k + 1) { ll a = COM(n, i) % mod; a = a * (COM(n - 1, i) % mod) % mod; ans = (ans + a) % mod; } cout << ans << endl; }
#include <bits/stdc++.h> #define r1(i, n) for (int i = 0; i < n; i++) #define r2(i, n) for (int i = 1; i < n; i++) #define intc(n) \ int n; \ cin >> n; #define ll long long #define llc(n) \ ll n; \ cin >> n; using namespace std; // テーブルを作る前処理 const ll MAX = 300000; const ll mod = 1000000007; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main() { COMinit(); ll n, k, ans = 0; cin >> n >> k; r1(i, min(n, k + 1)) { ll a = COM(n, i) % mod; a = a * (COM(n - 1, i) % mod) % mod; ans = (ans + a) % mod; } cout << ans << endl; }
replace
38
39
38
39
TLE
p02769
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; #define mod 1000000007 #define INF (1LL << 60) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rep1(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define YES puts("YES") #define Yes puts("Yes") #define NO puts("NO") #define No puts("No") #define ALL(v) (v).begin(), (v).end() int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #if 1 //------------- // DUMPマクロ // https://www.creativ.xyz/dump-cpp-652/ // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } #endif int modpow(int a, int k, int p) { int ans = 1; while (k > 0) { if (k % 2 == 1) { ans *= a; ans %= p; } a = (a * a) % p; k = k / 2; } return ans; } // ax+by=1の解 int extgcd(int a, int b, int &x, int &y) { int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } // mod mでのaの逆数 int mod_inv(int a, int m) { int x, y; extgcd(a, m, x, y); return (m + x % m) % m; } // nの階乗 mod p int factorial(int n, int p) { int r = 1; for (int i = 1; i <= n; i++) r = (r * i) % p; return r; } // nPr mod p int permutation(int n, int r, int p) { int a = 1; for (int i = n - r + 1; i <= n; i++) a = (a * i) % p; return a; } // 階乗の事前計算 const int MAX = 223456; int fac[MAX], fac_inv[MAX]; void make_table(int N) { fac[0] = fac[1] = 1; for (int i = 2; i <= N; i++) fac[i] = (fac[i - 1] * i) % mod; for (int i = 0; i <= N; i++) fac_inv[i] = mod_inv(fac[i], mod); } int combination(int n, int r, int p) { return (fac[n] * fac_inv[r]) % p * fac_inv[n - r] % p; } void solve() { int n, k; cin >> n >> k; make_table(523456); if (k >= n) { cout << combination(2 * n - 1, n, mod) << endl; return; } int ans = 0; // zeroの数を固定 for (int x = 0; x <= k; x++) { ans += combination(n, x, mod) * combination(n - 1, n - x - 1, mod) % mod; ans %= mod; } cout << ans << endl; } signed main() { cout << fixed << setprecision(18); cerr << fixed << setprecision(18); solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; #define mod 1000000007 #define INF (1LL << 60) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rep1(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define YES puts("YES") #define Yes puts("Yes") #define NO puts("NO") #define No puts("No") #define ALL(v) (v).begin(), (v).end() int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #if 1 //------------- // DUMPマクロ // https://www.creativ.xyz/dump-cpp-652/ // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } #endif int modpow(int a, int k, int p) { int ans = 1; while (k > 0) { if (k % 2 == 1) { ans *= a; ans %= p; } a = (a * a) % p; k = k / 2; } return ans; } // ax+by=1の解 int extgcd(int a, int b, int &x, int &y) { int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } // mod mでのaの逆数 int mod_inv(int a, int m) { int x, y; extgcd(a, m, x, y); return (m + x % m) % m; } // nの階乗 mod p int factorial(int n, int p) { int r = 1; for (int i = 1; i <= n; i++) r = (r * i) % p; return r; } // nPr mod p int permutation(int n, int r, int p) { int a = 1; for (int i = n - r + 1; i <= n; i++) a = (a * i) % p; return a; } // 階乗の事前計算 const int MAX = 623456; int fac[MAX], fac_inv[MAX]; void make_table(int N) { fac[0] = fac[1] = 1; for (int i = 2; i <= N; i++) fac[i] = (fac[i - 1] * i) % mod; for (int i = 0; i <= N; i++) fac_inv[i] = mod_inv(fac[i], mod); } int combination(int n, int r, int p) { return (fac[n] * fac_inv[r]) % p * fac_inv[n - r] % p; } void solve() { int n, k; cin >> n >> k; make_table(523456); if (k >= n) { cout << combination(2 * n - 1, n, mod) << endl; return; } int ans = 0; // zeroの数を固定 for (int x = 0; x <= k; x++) { ans += combination(n, x, mod) * combination(n - 1, n - x - 1, mod) % mod; ans %= mod; } cout << ans << endl; } signed main() { cout << fixed << setprecision(18); cerr << fixed << setprecision(18); solve(); }
replace
156
157
156
157
-11
p02769
C++
Time Limit Exceeded
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define INF (1 << 30) - 1 #define LINF 1LL << 60 const int MOD = 1000000007; using ll = long long; using P = pair<int, int>; const int mod = 1000000007; struct mint { ll x; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; mint f(int n) { if (n == 0) return 1; mint x = f(n / 2); x *= x; if (n % 2 == 1) x *= 2; return x; } mint choose(int n, int a) { mint x = 1, y = 1; for (int i = 0; i < a; ++i) { x *= n - i; y *= i + 1; } return x / y; } mint fact[400400]; mint inv_fact[400400]; void init() { fact[0] = 1; for (int i = 1; i < 400400; ++i) { fact[i] = fact[i - 1] * i; } inv_fact[400400 - 1] = fact[400400 - 1].inv(); for (int i = 400400 - 1; i >= 1; --i) { inv_fact[i - 1] = inv_fact[i] * i; } } mint comb(int n, int k) { return fact[n] * inv_fact[n - k] * inv_fact[k]; } int main() { init(); int n, k; cin >> n >> k; mint ans = 1; if (k >= n - 1) ans = comb(2 * n - 1, n); else { for (int i = 1; i <= k; ++i) { mint tmp = 0; for (int j = 1; j <= min(n - i, i); ++j) { tmp += comb(n - i, j) * comb(i - 1, j - 1); } ans += comb(n, i) * tmp; } } cout << ans.x << endl; return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define INF (1 << 30) - 1 #define LINF 1LL << 60 const int MOD = 1000000007; using ll = long long; using P = pair<int, int>; const int mod = 1000000007; struct mint { ll x; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; mint f(int n) { if (n == 0) return 1; mint x = f(n / 2); x *= x; if (n % 2 == 1) x *= 2; return x; } mint choose(int n, int a) { mint x = 1, y = 1; for (int i = 0; i < a; ++i) { x *= n - i; y *= i + 1; } return x / y; } mint fact[400400]; mint inv_fact[400400]; void init() { fact[0] = 1; for (int i = 1; i < 400400; ++i) { fact[i] = fact[i - 1] * i; } inv_fact[400400 - 1] = fact[400400 - 1].inv(); for (int i = 400400 - 1; i >= 1; --i) { inv_fact[i - 1] = inv_fact[i] * i; } } mint comb(int n, int k) { return fact[n] * inv_fact[n - k] * inv_fact[k]; } int main() { init(); int n, k; cin >> n >> k; mint ans = 1; for (int i = 1; i <= min(k, n - 1); ++i) { mint r = comb(n - 1, i); ans += comb(n, i) * r; } cout << ans.x << endl; return 0; }
replace
95
105
95
98
TLE
p02769
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) typedef long long ll; ll mod = 1000000007; ll modsize = 200010; vector<ll> fac(modsize); vector<ll> inv(modsize); vector<ll> facinv(modsize); void modcalc() { if (modsize == 0) abort(); fac[0] = 1; fac[1] = 1; inv[1] = 1; facinv[0] = 1; facinv[1] = 1; for (ll i = 2; i < modsize; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; facinv[i] = facinv[i - 1] * inv[i] % mod; } } ll modinv(ll a) { if (a == 0) abort(); ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } ll modcomb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[k] % mod * facinv[n - k] % mod; } int main() { modcalc(); int n, k; cin >> n >> k; ll ans = 0; rep(i, k + 1) { ans += modcomb(n, i) * modcomb(n - 1, n - i - 1); ans %= mod; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) typedef long long ll; ll mod = 1000000007; ll modsize = 200010; vector<ll> fac(modsize); vector<ll> inv(modsize); vector<ll> facinv(modsize); void modcalc() { if (modsize == 0) abort(); fac[0] = 1; fac[1] = 1; inv[1] = 1; facinv[0] = 1; facinv[1] = 1; for (ll i = 2; i < modsize; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; facinv[i] = facinv[i - 1] * inv[i] % mod; } } ll modinv(ll a) { if (a == 0) abort(); ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } ll modcomb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[k] % mod * facinv[n - k] % mod; } int main() { modcalc(); int n, k; cin >> n >> k; ll ans = 0; k = min(k, n - 1); rep(i, k + 1) { ans += modcomb(n, i) * modcomb(n - 1, n - i - 1); ans %= mod; } cout << ans << endl; }
insert
57
57
57
58
TLE
p02769
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n); i > 0; i--) #define all(n) n.begin(), n.end() #define print(n) cout << n << endl const int MAX = 200001; const int MOD = 1000000007; vector<ll> fac(MAX), finv(MAX), inv(MAX); void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n, k, ans = 0; cin >> n >> k; COMinit(); rep(i, k + 1) ans = (ans + COM(n, i) * COM(n - 1, n - 1 - i) % MOD) % MOD; print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n); i > 0; i--) #define all(n) n.begin(), n.end() #define print(n) cout << n << endl const int MAX = 200001; const int MOD = 1000000007; vector<ll> fac(MAX), finv(MAX), inv(MAX); void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n, k, ans = 0; cin >> n >> k; COMinit(); rep(i, min(n - 1, k) + 1) ans = (ans + COM(n, i) * COM(n - 1, n - 1 - i) % MOD) % MOD; print(ans); return 0; }
replace
39
40
39
41
TLE
p02769
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll modulo = 1000000007ll; ll binpow(ll a, ll b) { if (b == 0) return 1; if (b % 2 == 0) { return (binpow(a, b / 2) * binpow(a, b / 2)) % modulo; } else { return (((binpow(a, b / 2) * binpow(a, b / 2)) % modulo) * a) % modulo; } } ll factorial(ll n) { ll temp = 1; for (ll i = n; i >= 1; --i) { temp = (temp * i) % modulo; } return temp; } ll factorial1(ll n, ll p) { ll temp = 1; for (ll i = n; i >= (p + 1); --i) { temp = (temp * i) % modulo; } return temp; } ll moduloinverse(ll n) { /// cout<<"dvsd"<<endl; ll p = modulo - 2; return binpow(n, p) % modulo; } ll com(ll n, ll r) { if (r == 0) return 1; ll temp1 = std::max(r, n - r); ll temp2 = std::min(r, n - r); ll a = factorial1(n, temp1); ll b = factorial(temp2); // cout<<a<<" "<<b<<endl; return (a * moduloinverse(b)) % modulo; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; ll ans = 0; ll temp = std::min(k, n - 1); for (ll i = 0; i <= temp; ++i) { ans = (ans + (com(n, i) * com(n - 1, i)) % modulo) % modulo; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll modulo = 1000000007ll; ll binpow(ll a, ll b) { if (b == 0) return 1; if (b % 2 == 0) { return (binpow(a, b / 2) * binpow(a, b / 2)) % modulo; } else { return (((binpow(a, b / 2) * binpow(a, b / 2)) % modulo) * a) % modulo; } } ll factorial(ll n) { ll temp = 1; for (ll i = n; i >= 1; --i) { temp = (temp * i) % modulo; } return temp; } ll factorial1(ll n, ll p) { ll temp = 1; for (ll i = n; i >= (p + 1); --i) { temp = (temp * i) % modulo; } return temp; } ll moduloinverse(ll n) { /// cout<<"dvsd"<<endl; ll p = modulo - 2; return binpow(n, p) % modulo; } ll com(ll n, ll r) { if (r == 0) return 1; ll temp1 = std::max(r, n - r); ll temp2 = std::min(r, n - r); ll a = factorial1(n, temp1); ll b = factorial(temp2); // cout<<a<<" "<<b<<endl; return (a * moduloinverse(b)) % modulo; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; ll ans = 0; ll temp = std::min(k, n - 1); ll first = (com(n, 0) * com(n - 1, 0)) % modulo; ans = first; for (ll i = 0; i <= temp - 1; ++i) { ll v = ((n - i) * (n - i - 1)) % modulo; v = (v * first) % modulo; ll u = ((i + 1) * (i + 1)) % modulo; v = (v * moduloinverse(u)) % modulo; ans = (ans + v) % modulo; first = v; // cout<<first<<" "; } cout << ans << endl; }
replace
54
57
54
64
TLE
p02769
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; long long mod = 1e9 + 7; struct all { vector<long long> kai, gya, nck; all(long long n) { kai.resize(n); gya.resize(n); nck.resize(n); } long long pow(long long x, long long n) { long long ret = 1; if (n > 0) { ret = pow(x, n / 2); if (n % 2 == 0) { (ret = (ret * ret)) %= mod; } else { (ret = ((ret * ret) % mod) * x) %= mod; } } return ret; } long long inv(long long n) { return pow(n, mod - 2); } vector<long long> cul(long long n) { kai[n] = n; for (int i = n - 1; i > 0; i--) { (kai[i] = kai[i + 1] * i) %= mod; } gya[1] = inv(1); for (int i = 2; i <= n; i++) { (gya[i] = gya[i - 1] * inv(i)) %= mod; } for (int i = 1; i <= n; i++) { (nck[i] = kai[n + 1 - i] * gya[i]) %= mod; } nck[0] = 1; nck[n] = 1; return nck; } }; int main() { long long n, k; cin >> n >> k; if (k >= n - 1) { all nii(2 * n - 1); vector<long long> hoge = nii.cul(2 * n - 1); cout << hoge[n] << endl; } else { long long ans = 0; all nii(n); all mii(n - 1); vector<long long> hogen = nii.cul(n); vector<long long> hogenn = mii.cul(n - 1); for (int i = 0; i <= k; i++) { (ans += (hogen[i] * hogenn[i])) %= mod; } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; long long mod = 1e9 + 7; struct all { vector<long long> kai, gya, nck; all(long long n) { kai.resize(n + 1); gya.resize(n + 1); nck.resize(n + 1); } long long pow(long long x, long long n) { long long ret = 1; if (n > 0) { ret = pow(x, n / 2); if (n % 2 == 0) { (ret = (ret * ret)) %= mod; } else { (ret = ((ret * ret) % mod) * x) %= mod; } } return ret; } long long inv(long long n) { return pow(n, mod - 2); } vector<long long> cul(long long n) { kai[n] = n; for (int i = n - 1; i > 0; i--) { (kai[i] = kai[i + 1] * i) %= mod; } gya[1] = inv(1); for (int i = 2; i <= n; i++) { (gya[i] = gya[i - 1] * inv(i)) %= mod; } for (int i = 1; i <= n; i++) { (nck[i] = kai[n + 1 - i] * gya[i]) %= mod; } nck[0] = 1; nck[n] = 1; return nck; } }; int main() { long long n, k; cin >> n >> k; if (k >= n - 1) { all nii(2 * n - 1); vector<long long> hoge = nii.cul(2 * n - 1); cout << hoge[n] << endl; } else { long long ans = 0; all nii(n); all mii(n - 1); vector<long long> hogen = nii.cul(n); vector<long long> hogenn = mii.cul(n - 1); for (int i = 0; i <= k; i++) { (ans += (hogen[i] * hogenn[i])) %= mod; } cout << ans << endl; } return 0; }
replace
12
15
12
15
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02769
C++
Time Limit Exceeded
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define FOR(i, l, r) for (int i = (l); i <= (r); ++i) typedef long long LL; const LL mod = 1000000007; LL n, k; LL pow(LL x, LL n) { LL ret = 1; while (n) { if (n & 1) { ret *= x; ret %= mod; } x *= x; x %= mod; n >>= 1; } return ret; } LL inv(LL x) { return pow(x, mod - 2); } LL C(int n, int k) { if (k < 0 || k > n) return 0; if (k == 0) return 1; if (k == 1) return n; LL ret = n; for (int i = 2; i <= k; ++i) { ret *= (n - i + 1); ret %= mod; ret *= inv(i); ret %= mod; } return ret; } LL Cnext(LL n, LL k, LL Cnkm1) { LL ret = Cnkm1 * (n - k + 1); ret %= mod; ret *= inv(k); ret %= mod; return ret; } const int maxn = 200005; LL a[maxn], b[maxn]; int main() { #ifdef __APPLE__ freopen("main.in", "r", stdin); #endif cin >> n >> k; if (k == 1) { cout << n << endl; return 0; } if (k >= n) k = n - 1; /*a[0] = 1; for (int i = 1; i <= k; ++i) { LL next = Cnext(n - 1 + i - 1, i, a[i - 1]); a[i] = (a[i - 1] + next) % mod; } LL ans = 0; for (int i = 0; i <= k; ++i) { ans += a[i]; ans %= mod; } cout << ans << endl;*/ for (int i = 0; i <= n - 1; ++i) a[i] = C(n - 1, i); for (int i = 0; i <= n; ++i) b[i] = C(n, i); LL ans = 0; for (int i = 0; i <= k; ++i) { LL cur = b[i]; cur *= a[n - i - 1]; cur %= mod; ans += cur; ans %= mod; } cout << ans << endl; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define FOR(i, l, r) for (int i = (l); i <= (r); ++i) typedef long long LL; const LL mod = 1000000007; LL n, k; LL pow(LL x, LL n) { LL ret = 1; while (n) { if (n & 1) { ret *= x; ret %= mod; } x *= x; x %= mod; n >>= 1; } return ret; } LL inv(LL x) { return pow(x, mod - 2); } LL C(int n, int k) { if (k < 0 || k > n) return 0; if (k == 0) return 1; if (k == 1) return n; LL ret = n; for (int i = 2; i <= k; ++i) { ret *= (n - i + 1); ret %= mod; ret *= inv(i); ret %= mod; } return ret; } LL Cnext(LL n, LL k, LL Cnkm1) { LL ret = Cnkm1 * (n - k + 1); ret %= mod; ret *= inv(k); ret %= mod; return ret; } const int maxn = 200005; LL a[maxn], b[maxn]; int main() { #ifdef __APPLE__ freopen("main.in", "r", stdin); #endif cin >> n >> k; if (k == 1) { cout << n << endl; return 0; } if (k >= n) k = n - 1; /*a[0] = 1; for (int i = 1; i <= k; ++i) { LL next = Cnext(n - 1 + i - 1, i, a[i - 1]); a[i] = (a[i - 1] + next) % mod; } LL ans = 0; for (int i = 0; i <= k; ++i) { ans += a[i]; ans %= mod; } cout << ans << endl;*/ a[0] = 1; for (int i = 1; i <= n - 1; ++i) { a[i] = Cnext(n - 1, i, a[i - 1]); } b[0] = 1; for (int i = 1; i <= n; ++i) { b[i] = Cnext(n, i, b[i - 1]); } LL ans = 0; for (int i = 0; i <= k; ++i) { LL cur = b[i]; cur *= a[n - i - 1]; cur %= mod; ans += cur; ans %= mod; } cout << ans << endl; }
replace
75
79
75
85
TLE
p02769
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) { st << a.get(); return st; }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } template <typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac; Comb() { fac.resize(FAC_MAX, 1); ifac.resize(FAC_MAX, 1); rep(i, 1, FAC_MAX) fac[i] = fac[i - 1] * i; ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1]; rrep(i, FAC_MAX - 2, 1) ifac[i] = ifac[i + 1] * T(i + 1); } T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; } T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; } // nHk = (n+k-1)Ck : n is separator T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0; return aCb(n + k - 1, k); } T pairCombination(int n) { if (n % 2 == 1) return T(0); return fac[n] * ifac[n / 2] / (T(2) ^ (n / 2)); } // combination of paris for n }; typedef ModInt<1000000007> mint; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, K; Comb<mint, 201010> com; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> K; chmin(K, N - 1); mint ans = com.nHk(N, N); rep(zero, K + 1, N) ans -= com.aCb(N, zero) * com.nHk(N - zero, N - (N - zero)); cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) { st << a.get(); return st; }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } template <typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac; Comb() { fac.resize(FAC_MAX, 1); ifac.resize(FAC_MAX, 1); rep(i, 1, FAC_MAX) fac[i] = fac[i - 1] * i; ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1]; rrep(i, FAC_MAX - 2, 1) ifac[i] = ifac[i + 1] * T(i + 1); } T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; } T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; } // nHk = (n+k-1)Ck : n is separator T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0; return aCb(n + k - 1, k); } T pairCombination(int n) { if (n % 2 == 1) return T(0); return fac[n] * ifac[n / 2] / (T(2) ^ (n / 2)); } // combination of paris for n }; typedef ModInt<1000000007> mint; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, K; Comb<mint, 401010> com; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> K; chmin(K, N - 1); mint ans = com.nHk(N, N); rep(zero, K + 1, N) ans -= com.aCb(N, zero) * com.nHk(N - zero, N - (N - zero)); cout << ans << endl; }
replace
136
137
136
137
0
p02769
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define INF 1e9 const ll mod = 1e9 + 7; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll ans = 1; ll N; vector<vector<bool>> homon(2 * (int)1e5 + 3, vector<bool>(1e5, false)); void dfs(int n, int lock, int k) { if (n <= 0 || k <= 0) { return; } cerr << "n:" << n << " k:" << k << endl; if (homon[n][lock]) return; homon[n][lock] = true; if (lock != 0) { ans += (n * COM(N, lock)) % mod; ans %= mod; dfs(n - 1, lock, k - 1); } if (n - 2 >= 0) { ans += (n * (n - 1)) % mod; ans %= mod; dfs(n - 2, lock + 1, k - 1); } } int main() { COMinit(); ll n, k; cin >> n >> k; N = n; if (k == 1) { cout << n * (n - 1) % mod << endl; return 0; } ans = 1; FOR(i, 1, min(N + 1, k + 1)) { ans += (COM(N, i) * COM(N - i + i - 1, i)) % mod; ans %= mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define INF 1e9 const ll mod = 1e9 + 7; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll ans = 1; ll N; int main() { COMinit(); ll n, k; cin >> n >> k; N = n; if (k == 1) { cout << n * (n - 1) % mod << endl; return 0; } ans = 1; FOR(i, 1, min(N + 1, k + 1)) { ans += (COM(N, i) * COM(N - i + i - 1, i)) % mod; ans %= mod; } cout << ans << endl; return 0; }
delete
37
57
37
37
MLE
p02769
C++
Runtime Error
#include <algorithm> // minmax, sort, swap #include <cmath> #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr #include <map> // key-value pairs sorted by keys #include <numeric> // iota #include <queue> // queue, priority_queue #include <set> // set #include <string> // string, stoi, to_string #include <vector> // vector #ifdef DEBUG #include "debug.hpp" #else #define debug(...) #endif #define int long long // at least int64 > 9*10^18 #define ENDL '\n' #define rep(i, n) for (int i = 0; i < (n); i++) #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() /* libraries */ constexpr int MOD = 1e9 + 7; struct mint { int v; mint() : v(0) {} mint(int v) : v((v + MOD) % MOD) {} mint operator-() const { return mint(0) - *this; } mint &operator+=(const mint &a) { if ((v += a.v) >= MOD) v -= MOD; return *this; } mint &operator-=(const mint &a) { if ((v += MOD - a.v) >= MOD) v -= MOD; return *this; } mint &operator*=(const mint &a) { (v *= a.v) %= MOD; return *this; } mint &operator/=(const mint &a) { (*this) *= a.inv(); return *this; } mint operator+(const mint &a) const { return mint(*this) += a; } mint operator-(const mint &a) const { return mint(*this) -= a; } mint operator*(const mint &a) const { return mint(*this) *= a; } mint operator/(const mint &a) const { return mint(*this) /= a; } bool operator<(const mint &a) const { return v < a.v; } bool operator==(const mint &a) const { return v == a.v; } mint pow(int k) const { mint r(1), t(v); while (k) { if (k & 1) r *= t; t *= t; k >>= 1; } return r; } mint inv() const { return pow(MOD - 2); } static mint comb(int n, int k) { if (n - k < k) k = n - k; mint num(1), dom(1); for (int i = 0; i < k; i++) { num *= n - i; dom *= i + 1; } return num / dom; } }; std::istream &operator>>(std::istream &i, mint &a) { int t; i >> t; a = mint(t); return i; } std::ostream &operator<<(std::ostream &o, const mint &a) { o << a.v; return o; } std::vector<mint> construct_comb(int n) { std::vector<mint> c(n + 1); mint a = 1; c[0] = a; for (int i = 1; i <= n; i++) { a = a * mint(n + 1 - i) / i; c[i] = a; } return c; } signed main() { int n, k; std::cin >> n >> k; // sum of nCk*(n-1)Ck auto n0 = construct_comb(n); auto n1 = construct_comb(n - 1); mint sum = 0; for (int i = 0; i <= k; i++) { sum += n0[i] * n1[i]; } print(sum); return 0; }
#include <algorithm> // minmax, sort, swap #include <cmath> #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr #include <map> // key-value pairs sorted by keys #include <numeric> // iota #include <queue> // queue, priority_queue #include <set> // set #include <string> // string, stoi, to_string #include <vector> // vector #ifdef DEBUG #include "debug.hpp" #else #define debug(...) #endif #define int long long // at least int64 > 9*10^18 #define ENDL '\n' #define rep(i, n) for (int i = 0; i < (n); i++) #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() /* libraries */ constexpr int MOD = 1e9 + 7; struct mint { int v; mint() : v(0) {} mint(int v) : v((v + MOD) % MOD) {} mint operator-() const { return mint(0) - *this; } mint &operator+=(const mint &a) { if ((v += a.v) >= MOD) v -= MOD; return *this; } mint &operator-=(const mint &a) { if ((v += MOD - a.v) >= MOD) v -= MOD; return *this; } mint &operator*=(const mint &a) { (v *= a.v) %= MOD; return *this; } mint &operator/=(const mint &a) { (*this) *= a.inv(); return *this; } mint operator+(const mint &a) const { return mint(*this) += a; } mint operator-(const mint &a) const { return mint(*this) -= a; } mint operator*(const mint &a) const { return mint(*this) *= a; } mint operator/(const mint &a) const { return mint(*this) /= a; } bool operator<(const mint &a) const { return v < a.v; } bool operator==(const mint &a) const { return v == a.v; } mint pow(int k) const { mint r(1), t(v); while (k) { if (k & 1) r *= t; t *= t; k >>= 1; } return r; } mint inv() const { return pow(MOD - 2); } static mint comb(int n, int k) { if (n - k < k) k = n - k; mint num(1), dom(1); for (int i = 0; i < k; i++) { num *= n - i; dom *= i + 1; } return num / dom; } }; std::istream &operator>>(std::istream &i, mint &a) { int t; i >> t; a = mint(t); return i; } std::ostream &operator<<(std::ostream &o, const mint &a) { o << a.v; return o; } std::vector<mint> construct_comb(int n) { std::vector<mint> c(n + 1); mint a = 1; c[0] = a; for (int i = 1; i <= n; i++) { a = a * mint(n + 1 - i) / i; c[i] = a; } return c; } signed main() { int n, k; std::cin >> n >> k; // sum of nCk*(n-1)Ck auto n0 = construct_comb(n); auto n1 = construct_comb(n - 1); k = std::min(k, n - 1); mint sum = 0; for (int i = 0; i <= k; i++) { sum += n0[i] * n1[i]; } print(sum); return 0; }
insert
107
107
107
108
0
p02769
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); COMinit(); ll n, k; cin >> n >> k; ll res = 0; for (ll i = 0; i <= k; i++) { res += COM(n, i) * COM(n - 1, n - i - 1) % mod; res %= mod; } cout << res << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); COMinit(); ll n, k; cin >> n >> k; ll res = 0; for (ll i = 0; i <= min(n, k); i++) { res += COM(n, i) * COM(n - 1, n - i - 1) % mod; res %= mod; } cout << res << endl; }
replace
61
62
61
62
TLE
p02769
C++
Runtime Error
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep0(i, n) for (int i = 0; i <= (int)(n); ++i) #define rep1(i, n) for (int i = 1; i <= (int)(n); ++i) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; template <typename T> using Graph = vector<vector<T>>; template <typename T> using Spacial = vector<vector<vector<T>>>; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MOD = 1e9 + 7; const int MOD2 = 998244353; const double EPS = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template <typename T> struct is_pair : false_type {}; template <typename T1, typename T2> struct is_pair<pair<T1, T2>> : true_type {}; template <typename T> struct is_vector : false_type {}; template <typename T> struct is_vector<vector<T>> : true_type {}; template <typename T1, typename T2> istream &operator>>(istream &istr, pair<T1, T2> &p) { istr >> p.first >> p.second; return istr; } template <typename T1, typename T2> ostream &operator<<(ostream &ostr, const pair<T1, T2> &p) { ostr << p.first << " " << p.second; return ostr; } template <typename T> ostream &operator<<(ostream &ostr, const vector<T> &vec) { if (vec.empty()) return ostr; bool vp = is_vector<T>() || is_pair<T>(); ostr << vec.front(); for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) { ostr << (vp ? "\n" : " ") << *itr; } return ostr; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } int modpow(int a, long long n, int mod = MOD) { int ret = 1; do { if (n & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; } while (n >>= 1); return ret; } template <typename T> T GCD(T a, T b) { return b ? GCD(b, a % b) : a; } template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; } template <typename T1, typename T2> bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) { return a.second != b.second ? a.second < b.second : a.first < b.first; } template <typename T> bool CompareBySlope(pair<T, T> a, pair<T, T> b) { // counterclockwise from 12 o'clock direction if (a.first * b.first < 0) return a.first < b.first; if (a.first == 0) return a.second >= 0 || b.first > 0; if (b.first == 0) return b.second < 0 && a.first < 0; return a.second * b.first < a.first * b.second; } /* -------- <templates end> -------- */ vector<long long> fac, finv, inv; void com_init(int MAX) { ++MAX; fac.resize(MAX); fac[0] = fac[1] = 1; finv.resize(MAX); finv[0] = finv[1] = 1; inv.resize(MAX); inv[1] = 1; for (int i = 2; i < MAX; ++i) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long combination(int n, int r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } void solve() { int n, k; cin >> n >> k; com_init(n); if (k >= n - 1) { cout << combination(2 * n - 1, n) << endl; return; } int ans = 1; rep1(i, k) { (ans += combination(n, i) * combination(n - 1, i) % MOD) %= MOD; } cout << ans << endl; } /* -------- <programs end> -------- */ signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); solve(); return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep0(i, n) for (int i = 0; i <= (int)(n); ++i) #define rep1(i, n) for (int i = 1; i <= (int)(n); ++i) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; template <typename T> using Graph = vector<vector<T>>; template <typename T> using Spacial = vector<vector<vector<T>>>; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MOD = 1e9 + 7; const int MOD2 = 998244353; const double EPS = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template <typename T> struct is_pair : false_type {}; template <typename T1, typename T2> struct is_pair<pair<T1, T2>> : true_type {}; template <typename T> struct is_vector : false_type {}; template <typename T> struct is_vector<vector<T>> : true_type {}; template <typename T1, typename T2> istream &operator>>(istream &istr, pair<T1, T2> &p) { istr >> p.first >> p.second; return istr; } template <typename T1, typename T2> ostream &operator<<(ostream &ostr, const pair<T1, T2> &p) { ostr << p.first << " " << p.second; return ostr; } template <typename T> ostream &operator<<(ostream &ostr, const vector<T> &vec) { if (vec.empty()) return ostr; bool vp = is_vector<T>() || is_pair<T>(); ostr << vec.front(); for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) { ostr << (vp ? "\n" : " ") << *itr; } return ostr; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } int modpow(int a, long long n, int mod = MOD) { int ret = 1; do { if (n & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; } while (n >>= 1); return ret; } template <typename T> T GCD(T a, T b) { return b ? GCD(b, a % b) : a; } template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; } template <typename T1, typename T2> bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) { return a.second != b.second ? a.second < b.second : a.first < b.first; } template <typename T> bool CompareBySlope(pair<T, T> a, pair<T, T> b) { // counterclockwise from 12 o'clock direction if (a.first * b.first < 0) return a.first < b.first; if (a.first == 0) return a.second >= 0 || b.first > 0; if (b.first == 0) return b.second < 0 && a.first < 0; return a.second * b.first < a.first * b.second; } /* -------- <templates end> -------- */ vector<long long> fac, finv, inv; void com_init(int MAX) { ++MAX; fac.resize(MAX); fac[0] = fac[1] = 1; finv.resize(MAX); finv[0] = finv[1] = 1; inv.resize(MAX); inv[1] = 1; for (int i = 2; i < MAX; ++i) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long combination(int n, int r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } void solve() { int n, k; cin >> n >> k; com_init(2 * n); if (k >= n - 1) { cout << combination(2 * n - 1, n) << endl; return; } int ans = 1; rep1(i, k) { (ans += combination(n, i) * combination(n - 1, i) % MOD) %= MOD; } cout << ans << endl; } /* -------- <programs end> -------- */ signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); solve(); return 0; }
replace
115
116
115
116
0
p02769
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> using namespace std; #define int __int128 inline int gi() { short tmp = getchar(); int flag = 1; while (!isdigit(tmp)) { if (tmp == '-') { flag = -1; tmp = getchar(); break; } tmp = getchar(); } int ans = 0; while (isdigit(tmp)) { ans = (ans << 3) + (ans << 1) + tmp - '0'; tmp = getchar(); } return ans * flag; } inline void write(int x) { static int stk[100], top = 0; if (x == 0) { putchar('0'); putchar(' '); return; } if (x < 0) { x = -x; putchar('-'); } while (x) { stk[++top] = x % 10; x /= 10; } while (top) { putchar(stk[top--] + '0'); } putchar(' '); } #define line() putchar('\n'); #define Mem(Arr, V) memset(Arr, V, sizeof Arr); #define Mcpy(Arr, qwq) memcpy(Arr, qwq, sizeof qwq); #define max3(a, b, c) max(max(a, b), c) #define max4(a, b, c, d) max4(max3(a, b, c), d); #define in(a) a = gi() #define in2(a, b) in(a), in(b) #define in3(a, b, c) in2(a, b), in(c) #define in4(a, b, c, d) in3(a, b, c), in(d) #define write2(a, b) write(a), write(b) #define write3(a, b, c) write2(a, b), write(c) #define write4(a, b, c, d) write3(a, b, c), write(d) inline void smin(int &x, int y) { x = min(x, y); } inline void smax(int &x, int y) { x = max(x, y); } const int inf = 8000000; const int Mod = 1e9 + 7; inline int Pow(int b, int p, int k) { int ans = 1; while (p) { if (p & 1) { ans = ans * b % k; } b = b * b % k; p >>= 1; } return ans; } inline int Inv(int a) { return (Pow(a, Mod - 2, Mod)); } const int N = 2000000; int Fac[N]; inline void Prepare() { Fac[0] = 1; for (int i = 1; i <= 1000000; ++i) Fac[i] = i * Fac[i - 1] % Mod; } inline int C(int n, int m) { return Fac[n] * Inv(Fac[n - m] * Fac[m]) % Mod; } signed main() { freopen("data.in", "r", stdin); int n, k; in2(n, k); Prepare(); if (n <= k) { write(C(n + n - 1, n - 1)); } else { int all = C(n + n - 1, n - 1); for (int i = 1; i < n - k; ++i) { all -= C(n, i) * C(n - 1, i - 1) % Mod; all = (all % Mod + Mod) % Mod; } write(all); } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> using namespace std; #define int __int128 inline int gi() { short tmp = getchar(); int flag = 1; while (!isdigit(tmp)) { if (tmp == '-') { flag = -1; tmp = getchar(); break; } tmp = getchar(); } int ans = 0; while (isdigit(tmp)) { ans = (ans << 3) + (ans << 1) + tmp - '0'; tmp = getchar(); } return ans * flag; } inline void write(int x) { static int stk[100], top = 0; if (x == 0) { putchar('0'); putchar(' '); return; } if (x < 0) { x = -x; putchar('-'); } while (x) { stk[++top] = x % 10; x /= 10; } while (top) { putchar(stk[top--] + '0'); } putchar(' '); } #define line() putchar('\n'); #define Mem(Arr, V) memset(Arr, V, sizeof Arr); #define Mcpy(Arr, qwq) memcpy(Arr, qwq, sizeof qwq); #define max3(a, b, c) max(max(a, b), c) #define max4(a, b, c, d) max4(max3(a, b, c), d); #define in(a) a = gi() #define in2(a, b) in(a), in(b) #define in3(a, b, c) in2(a, b), in(c) #define in4(a, b, c, d) in3(a, b, c), in(d) #define write2(a, b) write(a), write(b) #define write3(a, b, c) write2(a, b), write(c) #define write4(a, b, c, d) write3(a, b, c), write(d) inline void smin(int &x, int y) { x = min(x, y); } inline void smax(int &x, int y) { x = max(x, y); } const int inf = 8000000; const int Mod = 1e9 + 7; inline int Pow(int b, int p, int k) { int ans = 1; while (p) { if (p & 1) { ans = ans * b % k; } b = b * b % k; p >>= 1; } return ans; } inline int Inv(int a) { return (Pow(a, Mod - 2, Mod)); } const int N = 2000000; int Fac[N]; inline void Prepare() { Fac[0] = 1; for (int i = 1; i <= 1000000; ++i) Fac[i] = i * Fac[i - 1] % Mod; } inline int C(int n, int m) { return Fac[n] * Inv(Fac[n - m] * Fac[m]) % Mod; } signed main() { int n, k; in2(n, k); Prepare(); if (n <= k) { write(C(n + n - 1, n - 1)); } else { int all = C(n + n - 1, n - 1); for (int i = 1; i < n - k; ++i) { all -= C(n, i) * C(n - 1, i - 1) % Mod; all = (all % Mod + Mod) % Mod; } write(all); } return 0; }
delete
86
87
86
86
TLE
p02769
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> using namespace std; const int MAX = 400000; // 欲しい最大数に応じて変動 n*2でOK const int MOD = 1000000007; // 10^9+7用mod long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { long long a, b; cin >> a >> b; COMinit(); if (a <= b) { long long total; total = COM(a * 2 - 1, a - 1); cout << total << endl; } else { long long ans = 0; for (int i = 0; i <= b; i++) { for (int j = 0; j < b - i; j++) { ans = (ans + (COM(a, b - i) * COM(a - b + i, b - i - j) % MOD) * COM(b - i - 1, b - i - 1 - j) % MOD) % MOD; } } cout << ans + 1 << endl; // 22583772 } }
#include <bits/stdc++.h> #include <iostream> using namespace std; const int MAX = 400000; // 欲しい最大数に応じて変動 n*2でOK const int MOD = 1000000007; // 10^9+7用mod long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { long long a, b; cin >> a >> b; COMinit(); if (a <= b) { long long total; total = COM(a * 2 - 1, a - 1); cout << total << endl; } else { long long ans = 0; for (int i = 0; i < b; i++) { ans = (ans + COM(a, b - i) * COM(a - 1, a - 1 - b + i) % MOD) % MOD; } cout << ans + 1 << endl; // 22583772 } }
replace
43
49
43
45
TLE
p02769
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void write(t x) { if (x < 0) putchar('-'), write(-x); else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } #define int long long const int mod = 1e9 + 7, N = 2e5 + 5; int n, ans, k, fac[N], inv[N]; int fpow(int x, int y) { int res = 1; for (; y; y >>= 1, x = x * x % mod) if (y & 1) res = res * x % mod; return res; } int C(int x, int y) { if (x < y || x < 0) return 0; return fac[x] * inv[y] % mod * inv[x - y] % mod; } signed main() { read(n); read(k); fac[0] = 1; for (int i = 1; i <= n + n; i++) fac[i] = fac[i - 1] * i % mod; inv[n + n] = fpow(fac[n + n], mod - 2); for (int i = n + n - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod; for (int i = max(1ll, n - k); i <= n; i++) ans = (ans + C(n, i) * C(n - 1, i - 1) % mod) % mod; write(ans); }
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void write(t x) { if (x < 0) putchar('-'), write(-x); else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } #define int long long const int mod = 1e9 + 7, N = 4e5 + 5; int n, ans, k, fac[N], inv[N]; int fpow(int x, int y) { int res = 1; for (; y; y >>= 1, x = x * x % mod) if (y & 1) res = res * x % mod; return res; } int C(int x, int y) { if (x < y || x < 0) return 0; return fac[x] * inv[y] % mod * inv[x - y] % mod; } signed main() { read(n); read(k); fac[0] = 1; for (int i = 1; i <= n + n; i++) fac[i] = fac[i - 1] * i % mod; inv[n + n] = fpow(fac[n + n], mod - 2); for (int i = n + n - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod; for (int i = max(1ll, n - k); i <= n; i++) ans = (ans + C(n, i) * C(n - 1, i - 1) % mod) % mod; write(ans); }
replace
26
27
26
27
0
p02769
C++
Runtime Error
#include <bits/stdc++.h> typedef long long lint; using namespace std; // nCr mod p(n<p)をキビキビ計算する // 構築:O(n), クエリ:O(1) struct combination_mod { using lint = long long int; int sz; lint mod; vector<lint> fac; vector<lint> finv; combination_mod(int _sz, lint _mod) : sz(_sz), mod(_mod) { fac.assign(sz + 1, 1); finv.assign(sz + 1, 1); vector<lint> inv(sz + 1, 1); for (int i = 2; i <= sz; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } lint query(int n, int r) { return fac[n] * (finv[r] * finv[n - r] % mod) % mod; } }; lint mod = 1e+9 + 7; lint n, k; int main() { cin >> n >> k; combination_mod comb(2 * n, mod); if (k >= n - 1) { cout << comb.query(2 * n - 1, n) << endl; } lint ans = (1 + n * (n - 1)) % mod; for (int i = 1; i < k; i++) { lint ta = comb.query(n, i + 1); ta *= comb.query(n - 1, i + 1); ta %= mod; ans = (ans + ta) % mod; } cout << ans << endl; }
#include <bits/stdc++.h> typedef long long lint; using namespace std; // nCr mod p(n<p)をキビキビ計算する // 構築:O(n), クエリ:O(1) struct combination_mod { using lint = long long int; int sz; lint mod; vector<lint> fac; vector<lint> finv; combination_mod(int _sz, lint _mod) : sz(_sz), mod(_mod) { fac.assign(sz + 1, 1); finv.assign(sz + 1, 1); vector<lint> inv(sz + 1, 1); for (int i = 2; i <= sz; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } lint query(int n, int r) { return fac[n] * (finv[r] * finv[n - r] % mod) % mod; } }; lint mod = 1e+9 + 7; lint n, k; int main() { cin >> n >> k; combination_mod comb(2 * n, mod); if (k >= n - 1) { cout << comb.query(2 * n - 1, n) << endl; return 0; } if (k == 1) { cout << n * (n - 1) % mod << endl; return 0; } lint ans = (1 + n * (n - 1)) % mod; for (int i = 1; i < k; i++) { lint ta = comb.query(n, i + 1); ta *= comb.query(n - 1, i + 1); ta %= mod; ans = (ans + ta) % mod; } cout << ans << endl; }
insert
35
35
35
40
0
p02769
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; const int MODN = 1e9 + 7; const int MAXN = 1e5 + 10; int fact[MAXN]; int quick_pow(int a, int b, int modn = MODN) { a %= MODN; int ret = 1; // int cheng=a; while (b) { if (b & 1) ret *= a; ret %= MODN; a *= a; a %= MODN; b >>= 1; } return ret; } int C(int n, int r) { return fact[n] * (quick_pow((fact[n - r] * fact[r]), MODN - 2)) % MODN; } int32_t main() { int n, k; cin >> n >> k; fact[0] = 1; for (int i = 1; i < MAXN; i++) fact[i] = (fact[i - 1] * i) % MODN; int sum = 0; for (int i = 0; i <= min(k, n - 1); i++) { sum += C(n, i) * C(n - 1, i); sum %= MODN; } cout << sum << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; const int MODN = 1e9 + 7; const int MAXN = 2e5 + 10; int fact[MAXN]; int quick_pow(int a, int b, int modn = MODN) { a %= MODN; int ret = 1; // int cheng=a; while (b) { if (b & 1) ret *= a; ret %= MODN; a *= a; a %= MODN; b >>= 1; } return ret; } int C(int n, int r) { return fact[n] * (quick_pow((fact[n - r] * fact[r]), MODN - 2)) % MODN; } int32_t main() { int n, k; cin >> n >> k; fact[0] = 1; for (int i = 1; i < MAXN; i++) fact[i] = (fact[i - 1] * i) % MODN; int sum = 0; for (int i = 0; i <= min(k, n - 1); i++) { sum += C(n, i) * C(n - 1, i); sum %= MODN; } cout << sum << endl; return 0; }
replace
4
5
4
5
0
p02769
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // def #define debug(x) cout << #x << ": " << x << endl #define out(x) cout << x << endl #define repeat(i, a, b) for (int i = (a); i < (b); i++) #define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define revrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(x) (x).begin(), (x).end() #define CYES cout << "Yes" << endl #define CNO cout << "No" << endl #define SPC(x) cout << fixed << setprecision(x) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<ll> vl; typedef vector<vector<ll>> vll; typedef pair<int, int> P; typedef complex<ld> Point; const int MOD = 1e9 + 7; const int INF = 1e9; const int MAX_V = 1e5 + 5; const int MAX_N = 200005; const double PI = acos(-1); struct mint { // Preparation: MOD is already defined. ll value; mint(ll value = 0) : value((value % MOD + MOD) % MOD) {} mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint pow(mint m) const { return pow(m.value); } mint inv() const { ll a = value, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= MOD; return u; } mint &operator+=(const mint a) { if ((value += a.value) >= MOD) value -= MOD; return *this; } mint &operator-=(const mint a) { if ((value += MOD - a.value) >= MOD) value -= MOD; return *this; } mint &operator*=(const mint a) { (value *= a.value) %= MOD; return *this; } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; long long fac[MAX_N], finv[MAX_N], inv[MAX_N]; // テーブルを作る前処理 from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX_N; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // factorial long long fact(int n) { if (n == 1) return fac[n] = 1; if (fac[n]) return fac[n]; return fac[n] = (fact(n - 1) * n) % MOD; } long long modpow(long long m, long long p) { if (p == 0) return 1; if (p % 2) return m * modpow(m, p - 1) % MOD; else { long res = modpow(m, p / 2); return res * res % MOD; } } int main() { ll n, k; cin >> n >> k; COMinit(); mint ans(0); if (n - k <= 1) { ans += COM(2 * n - 1, n); } else { ans += COM(2 * (n - k - 1) - 1, n - k - 1); } out(ans.value); return 0; }
#include <bits/stdc++.h> using namespace std; // def #define debug(x) cout << #x << ": " << x << endl #define out(x) cout << x << endl #define repeat(i, a, b) for (int i = (a); i < (b); i++) #define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define revrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(x) (x).begin(), (x).end() #define CYES cout << "Yes" << endl #define CNO cout << "No" << endl #define SPC(x) cout << fixed << setprecision(x) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<ll> vl; typedef vector<vector<ll>> vll; typedef pair<int, int> P; typedef complex<ld> Point; const int MOD = 1e9 + 7; const int INF = 1e9; const int MAX_V = 1e5 + 5; const int MAX_N = 200005; const double PI = acos(-1); struct mint { // Preparation: MOD is already defined. ll value; mint(ll value = 0) : value((value % MOD + MOD) % MOD) {} mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint pow(mint m) const { return pow(m.value); } mint inv() const { ll a = value, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= MOD; return u; } mint &operator+=(const mint a) { if ((value += a.value) >= MOD) value -= MOD; return *this; } mint &operator-=(const mint a) { if ((value += MOD - a.value) >= MOD) value -= MOD; return *this; } mint &operator*=(const mint a) { (value *= a.value) %= MOD; return *this; } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; long long fac[MAX_N], finv[MAX_N], inv[MAX_N]; // テーブルを作る前処理 from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX_N; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // factorial long long fact(int n) { if (n == 1) return fac[n] = 1; if (fac[n]) return fac[n]; return fac[n] = (fact(n - 1) * n) % MOD; } long long modpow(long long m, long long p) { if (p == 0) return 1; if (p % 2) return m * modpow(m, p - 1) % MOD; else { long res = modpow(m, p / 2); return res * res % MOD; } } int main() { ll n, k; cin >> n >> k; COMinit(); mint ans(0); ll max_empty_room_num = min(n - 1, k); rep(i, max_empty_room_num + 1) { ans += COM(n, i) * COM(n - 1, i); } out(ans.value); return 0; }
replace
139
144
139
141
0
p02769
C++
Runtime Error
/******* DFS TREE ************** * https://codeforces.com/contest/1276/problem/B */ /* ID: vqt LANG: C++14 PROB: namenum */ // #pragma GCC optimize ("O2") #pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <unistd.h> using namespace std; using namespace __gnu_pbds; // template <typename T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, // tree_order_statistics_node_update>; #define ordered_set \ tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, \ tree_order_statistics_node_update> // defines #define int long long typedef long long ll; #define double long double #define vec vector #define vi vector<int> #define vvi vector<vector<int>> #define p_q priority_queue #define min_p_q priority_queue<int, vt<int>, greater<int>> #define ii pair<int, int> #define vii vector<ii> #define F first #define S second #define MP make_pair #define PB push_back #define ALL(x) begin(x), end(x) #define SZ(x) ((int)(x).size()) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORE(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) // #define UNI(x) (x).resize(unique((x).begin(), (x).end()) - (x).end()); #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), (x)) - c.begin()) #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define RESET(X, y) memset(X, y, sizeof(X)) #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) template <class T> inline void out(T t) { cout << t << "\n"; } template <class T, class... Ts> inline void out(T t, Ts... ts) { cout << t << " "; out(ts...); } // Universal DEBUG: https://codeforces.com/blog/entry/68809 void __print(int x) { cout << x; } void __print(long x) { cout << x; } // void __print(long long x) {cout << x;} //invalid if #define int long long void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } // void __print(long double x) {cout << x;} void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } void __print(bool x) { cout << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cout << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif /* To debug, just type: debug(x, y, z...). It requires C++ 11 or above. It can work with: Primitive data types: bool, int, long long, float, ...; pair, string; Collection types: std::vector, std::map, std::set, ...; Expressions */ // permanent constants const long long INF64 = 1e18; const int INF32 = 1e9; const int BIG = (int)(1e9 + 239); const int MOD = 1000000007; // (int)1e9+7; //998244353; const ll MOD2 = (ll)MOD * (ll)MOD; const double PI = 2.0 * acos(0.0); // acos(-1.0L); const double EPS = static_cast<double>(1e-10); const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; // random mt19937 rnd( 239); //(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef vector<vector<int>> matrix; // matrix Z(n, vector<LL>(n)); /*GRAPH: vector<vector<int>> dist; // ma tran dist giua cac dinh dist.assign(N, vector<int>(N, INF)); // Khoi tao ma tran dist bang INF Cach khac: vector<int> p; vector<vector<int>> g; // khai bao p = vector<int>(n); // thay cho resize g = vector<vector<int>>(n); // // thay cho resize */ // Sort w Lambda Function: sort(begin(v), end(v), [] (int a, int b) { return a > // b; }); // How to use "accumulate": // https://www.fluentcpp.com/2017/10/17/stdaccumulate-your-knowledge-on-algorithms/ // array a: tinh XOR sum tu l den r: #define XORsum(a, l, r) \ accumulate(a + l - 1, a + r, 0, [](int a, int b) { return a ^ b; }) void FILEIO() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } // void FILEIO() { freopen("berries.in", "r", stdin); freopen("berries.out", // "w", stdout); } Tricks: #define odd(x) ((x)&1) #define even(x) !((x)&1) int mostSignDigit(int n) { double k = log10(n); return pow(10, k - floor(k)); } int numOfDigits(int n) { return floor(log10(n)) + 1; } bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); } // first x is for the case x=0 bool allPositive(vector<int> &a) { return all_of(begin(a), end(a), [](int x) { return x > 0; }); } // are all of the elements positive? bool anyPositive(vector<int> &a) { return any_of(begin(a), end(a), [](int x) { return x > 0; }); } // is there at least one positive element? bool nonePositive(vector<int> &a) { return none_of(begin(a), end(a), [](int x) { return x > 0; }); } // are none of the elements positive? //****************** //************ MODULAR ARITHMETIC LIB *************************** template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { // dinh nghia Fp(v) = (v % MOD) if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } // get MOD constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } // phep toan "-" constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } // phep toan "+=" constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } // phep toan "-=" constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } // phep toan "*=" constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } // phep toan "/=" constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=( const Fp &r) noexcept { // dinh nghia phep chia, dung thuat toan inverse long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; template <class T> struct BiCoef { // tinh C(k, n) vector<T> fact_, inv_, finv_; constexpr BiCoef() {} constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) { init(n); } constexpr void init(int n) noexcept { fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1); int MOD = fact_[0].getmod(); for (int i = 2; i < n; i++) { fact_[i] = fact_[i - 1] * i; // i! inv_[i] = -inv_[MOD % i] * (MOD / i); // inverse cua so i finv_[i] = finv_[i - 1] * inv_[i]; // factorial inverse } } constexpr T com(int n, int k) const noexcept { // tinh C(k, n) if (n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[k] * finv_[n - k]; } constexpr T fact(int n) const noexcept { if (n < 0) return 0; return fact_[n]; } constexpr T inv(int n) const noexcept { if (n < 0) return 0; return inv_[n]; } constexpr T finv(int n) const noexcept { if (n < 0) return 0; return finv_[n]; } }; /* VI DU: const int MOD = 1000000007; using mint = Fp<MOD>; // mint = modular int BiCoef<mint> bc; // tao class de tinh C(k, n) bc.init(500050); // precompute tat ca C(k,n) voi n = 500050, k = 1, n */ int n, k; void solve() { cin >> n >> k; // if(k > n) { // cout << C(n, 2*n-1) << endl; return; // C(k, n+k-1): xep k bong vao //n ro // } using mint = Fp<MOD>; // mint = modular int BiCoef<mint> bc; // tao class de tinh C(k, n) bc.init(200050); // precompute tat ca C(k,n) voi n = 200050, k = 1, n mint ans = 0; FORE(i, 0, min(k, n)) { // co i phong khong nguoi mint way = bc.com(n, i); // so cach chon i phong khong nguoi = C(i, n) // int m = n - i = so phong phai co nguoi >=1, tong so nguoi = n => sau khi // bo di m // nguoi thi phai xep n-m nguoi nay vao n-i phong => C(n-m, n-m+n-i-1) = // C(i, n-1) C(i, n-1) = ( C(i, n)/n ) * (n-i) suy ra; // int conguoi = ( ( ( CN[i] * (n-i) )%MOD ) * modInverse(n) ) % //MOD; mint conguoi = bc.com(n - 1, i); ans += way * conguoi; } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(); FILEIO(); // auto beginProgram = chrono::steady_clock::now(); // int t; cin >> t; // FOR(i, 0, t) { // cout << "Case #" << i+1 << ": " << solve() << endl; solve(); } // auto endProgram = chrono::steady_clock::now(); // cout << chrono::duration_cast<chrono::milliseconds>(endProgram - // beginProgram).count() << " ms" << endl; return 0; } //*******************END TEST **************************/
/******* DFS TREE ************** * https://codeforces.com/contest/1276/problem/B */ /* ID: vqt LANG: C++14 PROB: namenum */ // #pragma GCC optimize ("O2") #pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <unistd.h> using namespace std; using namespace __gnu_pbds; // template <typename T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, // tree_order_statistics_node_update>; #define ordered_set \ tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, \ tree_order_statistics_node_update> // defines #define int long long typedef long long ll; #define double long double #define vec vector #define vi vector<int> #define vvi vector<vector<int>> #define p_q priority_queue #define min_p_q priority_queue<int, vt<int>, greater<int>> #define ii pair<int, int> #define vii vector<ii> #define F first #define S second #define MP make_pair #define PB push_back #define ALL(x) begin(x), end(x) #define SZ(x) ((int)(x).size()) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORE(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) // #define UNI(x) (x).resize(unique((x).begin(), (x).end()) - (x).end()); #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), (x)) - c.begin()) #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define RESET(X, y) memset(X, y, sizeof(X)) #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) template <class T> inline void out(T t) { cout << t << "\n"; } template <class T, class... Ts> inline void out(T t, Ts... ts) { cout << t << " "; out(ts...); } // Universal DEBUG: https://codeforces.com/blog/entry/68809 void __print(int x) { cout << x; } void __print(long x) { cout << x; } // void __print(long long x) {cout << x;} //invalid if #define int long long void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } // void __print(long double x) {cout << x;} void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } void __print(bool x) { cout << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cout << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif /* To debug, just type: debug(x, y, z...). It requires C++ 11 or above. It can work with: Primitive data types: bool, int, long long, float, ...; pair, string; Collection types: std::vector, std::map, std::set, ...; Expressions */ // permanent constants const long long INF64 = 1e18; const int INF32 = 1e9; const int BIG = (int)(1e9 + 239); const int MOD = 1000000007; // (int)1e9+7; //998244353; const ll MOD2 = (ll)MOD * (ll)MOD; const double PI = 2.0 * acos(0.0); // acos(-1.0L); const double EPS = static_cast<double>(1e-10); const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; // random mt19937 rnd( 239); //(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef vector<vector<int>> matrix; // matrix Z(n, vector<LL>(n)); /*GRAPH: vector<vector<int>> dist; // ma tran dist giua cac dinh dist.assign(N, vector<int>(N, INF)); // Khoi tao ma tran dist bang INF Cach khac: vector<int> p; vector<vector<int>> g; // khai bao p = vector<int>(n); // thay cho resize g = vector<vector<int>>(n); // // thay cho resize */ // Sort w Lambda Function: sort(begin(v), end(v), [] (int a, int b) { return a > // b; }); // How to use "accumulate": // https://www.fluentcpp.com/2017/10/17/stdaccumulate-your-knowledge-on-algorithms/ // array a: tinh XOR sum tu l den r: #define XORsum(a, l, r) \ accumulate(a + l - 1, a + r, 0, [](int a, int b) { return a ^ b; }) void FILEIO() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } // void FILEIO() { freopen("berries.in", "r", stdin); freopen("berries.out", // "w", stdout); } Tricks: #define odd(x) ((x)&1) #define even(x) !((x)&1) int mostSignDigit(int n) { double k = log10(n); return pow(10, k - floor(k)); } int numOfDigits(int n) { return floor(log10(n)) + 1; } bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); } // first x is for the case x=0 bool allPositive(vector<int> &a) { return all_of(begin(a), end(a), [](int x) { return x > 0; }); } // are all of the elements positive? bool anyPositive(vector<int> &a) { return any_of(begin(a), end(a), [](int x) { return x > 0; }); } // is there at least one positive element? bool nonePositive(vector<int> &a) { return none_of(begin(a), end(a), [](int x) { return x > 0; }); } // are none of the elements positive? //****************** //************ MODULAR ARITHMETIC LIB *************************** template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { // dinh nghia Fp(v) = (v % MOD) if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } // get MOD constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } // phep toan "-" constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } // phep toan "+=" constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } // phep toan "-=" constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } // phep toan "*=" constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } // phep toan "/=" constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=( const Fp &r) noexcept { // dinh nghia phep chia, dung thuat toan inverse long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; template <class T> struct BiCoef { // tinh C(k, n) vector<T> fact_, inv_, finv_; constexpr BiCoef() {} constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) { init(n); } constexpr void init(int n) noexcept { fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1); int MOD = fact_[0].getmod(); for (int i = 2; i < n; i++) { fact_[i] = fact_[i - 1] * i; // i! inv_[i] = -inv_[MOD % i] * (MOD / i); // inverse cua so i finv_[i] = finv_[i - 1] * inv_[i]; // factorial inverse } } constexpr T com(int n, int k) const noexcept { // tinh C(k, n) if (n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[k] * finv_[n - k]; } constexpr T fact(int n) const noexcept { if (n < 0) return 0; return fact_[n]; } constexpr T inv(int n) const noexcept { if (n < 0) return 0; return inv_[n]; } constexpr T finv(int n) const noexcept { if (n < 0) return 0; return finv_[n]; } }; /* VI DU: const int MOD = 1000000007; using mint = Fp<MOD>; // mint = modular int BiCoef<mint> bc; // tao class de tinh C(k, n) bc.init(500050); // precompute tat ca C(k,n) voi n = 500050, k = 1, n */ int n, k; void solve() { cin >> n >> k; // if(k > n) { // cout << C(n, 2*n-1) << endl; return; // C(k, n+k-1): xep k bong vao //n ro // } using mint = Fp<MOD>; // mint = modular int BiCoef<mint> bc; // tao class de tinh C(k, n) bc.init(200050); // precompute tat ca C(k,n) voi n = 200050, k = 1, n mint ans = 0; FORE(i, 0, min(k, n)) { // co i phong khong nguoi mint way = bc.com(n, i); // so cach chon i phong khong nguoi = C(i, n) // int m = n - i = so phong phai co nguoi >=1, tong so nguoi = n => sau khi // bo di m // nguoi thi phai xep n-m nguoi nay vao n-i phong => C(n-m, n-m+n-i-1) = // C(i, n-1) C(i, n-1) = ( C(i, n)/n ) * (n-i) suy ra; // int conguoi = ( ( ( CN[i] * (n-i) )%MOD ) * modInverse(n) ) % //MOD; mint conguoi = bc.com(n - 1, i); ans += way * conguoi; } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(); // FILEIO(); // auto beginProgram = chrono::steady_clock::now(); // int t; cin >> t; // FOR(i, 0, t) { // cout << "Case #" << i+1 << ": " << solve() << endl; solve(); } // auto endProgram = chrono::steady_clock::now(); // cout << chrono::duration_cast<chrono::milliseconds>(endProgram - // beginProgram).count() << " ms" << endl; return 0; } //*******************END TEST **************************/
replace
326
327
326
327
0
p02769
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } class ModInt { static int MOD; long long x; public: static void mod(int m) { MOD = m; } ModInt(long long v = 0) : x(v % MOD) { if (x < 0) x += MOD; } ModInt &operator+=(const ModInt &r) { x += r.x; if (x >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt &r) { x -= r.x; if (x < 0) x += MOD; return *this; } ModInt &operator*=(const ModInt &r) { x = (x * r.x) % MOD; return *this; } ModInt &operator/=(const ModInt &r) { *this *= r.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &r) const { return ModInt(*this) += r; } ModInt operator-(const ModInt &r) const { return ModInt(*this) -= r; } ModInt operator*(const ModInt &r) const { return ModInt(*this) *= r; } ModInt operator/(const ModInt &r) const { return ModInt(*this) /= r; } bool operator==(const ModInt &r) const { return x == r.x; } bool operator!=(const ModInt &r) const { return x != r.x; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(long long n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &x) { return os << x.x; } friend istream &operator>>(istream &is, ModInt &x) { return is >> x.x; } int getMod() { return MOD; } long long val() { return x; } }; int ModInt::MOD = 1000000007; template <typename T> class Combination { vector<T> fact, ifact; public: Combination(int nMax) : fact(nMax + 1), ifact(nMax + 1) { fact[0] = 1; for (int i = 0; i < nMax; ++i) fact[i + 1] = fact[i] * (i + 1); for (int i = 0; i < nMax + 1; ++i) ifact[i] = fact[i].inverse(); } T factorial(int n) const { return fact[n]; } T inverseFactorial(int n) const { return ifact[n]; } T P(int n, int k) const { if (n < 0 || k < 0 || n < k) return 0; return factorial(n) * inverseFactorial(n - k); } T C(int n, int k) const { if (n < 0 || k < 0 || n < k) return 0; return factorial(n) * inverseFactorial(n - k) * inverseFactorial(k); } T H(int n, int k) const { if (n < 0 || k < 0) return 0; return k == 0 ? 1 : C(n + k - 1, k); } }; int main() { int n, k; cin >> n >> k; Combination<ModInt> comb(n); ModInt ans = 0; for (int i = 0; i <= k; ++i) { ans += comb.C(n, i) * comb.C(n - 1, i); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } class ModInt { static int MOD; long long x; public: static void mod(int m) { MOD = m; } ModInt(long long v = 0) : x(v % MOD) { if (x < 0) x += MOD; } ModInt &operator+=(const ModInt &r) { x += r.x; if (x >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt &r) { x -= r.x; if (x < 0) x += MOD; return *this; } ModInt &operator*=(const ModInt &r) { x = (x * r.x) % MOD; return *this; } ModInt &operator/=(const ModInt &r) { *this *= r.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &r) const { return ModInt(*this) += r; } ModInt operator-(const ModInt &r) const { return ModInt(*this) -= r; } ModInt operator*(const ModInt &r) const { return ModInt(*this) *= r; } ModInt operator/(const ModInt &r) const { return ModInt(*this) /= r; } bool operator==(const ModInt &r) const { return x == r.x; } bool operator!=(const ModInt &r) const { return x != r.x; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(long long n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &x) { return os << x.x; } friend istream &operator>>(istream &is, ModInt &x) { return is >> x.x; } int getMod() { return MOD; } long long val() { return x; } }; int ModInt::MOD = 1000000007; template <typename T> class Combination { vector<T> fact, ifact; public: Combination(int nMax) : fact(nMax + 1), ifact(nMax + 1) { fact[0] = 1; for (int i = 0; i < nMax; ++i) fact[i + 1] = fact[i] * (i + 1); for (int i = 0; i < nMax + 1; ++i) ifact[i] = fact[i].inverse(); } T factorial(int n) const { return fact[n]; } T inverseFactorial(int n) const { return ifact[n]; } T P(int n, int k) const { if (n < 0 || k < 0 || n < k) return 0; return factorial(n) * inverseFactorial(n - k); } T C(int n, int k) const { if (n < 0 || k < 0 || n < k) return 0; return factorial(n) * inverseFactorial(n - k) * inverseFactorial(k); } T H(int n, int k) const { if (n < 0 || k < 0) return 0; return k == 0 ? 1 : C(n + k - 1, k); } }; int main() { int n, k; cin >> n >> k; Combination<ModInt> comb(n); ModInt ans = 0; for (int i = 0; i <= min(k, n - 1); ++i) { ans += comb.C(n, i) * comb.C(n - 1, i); } cout << ans << endl; return 0; }
replace
131
132
131
132
TLE
p02769
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cassert> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; using edge = struct { ll to; ll cost; }; using point = struct { ll x; ll y; }; typedef string str; typedef std::pair<ll, ll> pl; typedef std::pair<ll, pl> pl3; typedef std::map<string, ll> msl; typedef std::map<char, ll> mcl; typedef std::map<ll, ll> mll; typedef std::vector<ll> vl; typedef std::vector<pl> vpl; typedef std::vector<point> vxy; typedef std::vector<pl3> vpl3; typedef std::priority_queue<ll> pq; typedef std::priority_queue<ll, vl, greater<ll>> pql; // priority queue taking from the lower value. typedef std::vector<edge> gr; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll INF = MOD * MOD; const long double EPS = 1e-9; const long double PI = 3.14159265358979323846; #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define revrep(i, n) for (ll(i) = n - 1; (i) >= 0; (i)--) #define For(i, a, b) for (ll(i) = (a); (i) < (b); (i)++) #define revFor(i, b, a) for (ll(i) = (b)-1; (i) >= (a); (i)--) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define isUpper(c) ('a' - c > 0) #define toLower(c) char((c) + 0x20) #define toUpper(c) char((c)-0x20) #define pb push_back #define mp make_pair #define pr(a) cout << (a) #define prl(a) cout << (a) << endl #define prl2(a, b) cout << (a) << " " << (b) << endl #define prl3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define prl4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define prs(a) cout << (a) << " " #define yn(condition) \ if ((condition)) \ prl("Yes"); \ else \ prl("No"); #define YN(condition) \ if ((condition)) \ prl("YES"); \ else \ prl("NO"); #define in1(a) cin >> (a) #define in2(a, b) cin >> (a) >> (b) #define in3(a, b, c) cin >> (a) >> (b) >> (c) #define in4(a, b, c, d) cin >> (a) >> (b) >> (c) >> (d) #define e1 first #define e2 second #define ctol(c) ll((c)) - ll('0') #define ltos(n) to_string((n)) #define items(kv, v) for (auto &(kv) : (v)) #define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)])) #define rsort(a, n) sort(a, a + n, greater<>()) #define Forchar(c, a, z) for (char(c) = (a); (c) <= (z); (c)++) #define cntchar(s, c) count(all((s)), c) #define substring(s, start, end) s.substr((start), (end) - (start) + 1) #define prl_nd(num, digits) \ cout << fixed << setprecision(digits) << (num) << endl; #define XOR(a, b) (a) ^ (b) #define prl_time(s) \ prl3("Elapsed Time:", 1000.0 * (clock() - s) / CLOCKS_PER_SEC, "[ms]"); #define char_to_str(c) string(1, (c)) #define bin_expression(n, dig) bitset<(dig)>(n) #define DEBUG(x) cerr << #x << ": " << (x) << endl #define DEBUG_VEC(v) \ cerr << #v << ": "; \ rep(__i, (v).size()) cerr << ((v)[__i]) << ", "; \ cerr << endl class UnionFind { vl parents, set_size; public: UnionFind() {} UnionFind(ll n) { parents = set_size = vl(n); rep(i, n) { parents[i] = i; set_size[i] = 1LL; } } ll root_find(ll x) { if (parents[x] == x) return x; return parents[x] = root_find(parents[x]); } void unite(ll x, ll y) { x = root_find(x); y = root_find(y); if (x == y) return; if (set_size[x] < set_size[y]) { parents[y] = x; set_size[x] += set_size[y]; } else { parents[x] = y; set_size[y] += set_size[x]; } } bool is_same(ll x, ll y) { // connected or not return root_find(x) == root_find(y); } ll size(ll x) { return set_size[root_find(x)]; } }; /* class LCA{ public: ll N, logN; vl depth, len; gr tree[200005]; // global declaration later. vector<vl> parents; LCA(ll n){ N = n; logN = 0; while (N > (1LL << logN)) logN++; depth = vl(N); len = vl(N); parents = vector<vl>(logN, vl(N)); init(0, -1, 0, 0); build(); } void init(ll source, ll parent, ll d, ll l){ depth[source] = d; parents[0][source] = parent; len[source] = l; rep(i, tree[source].size()){ ll target = tree[source][i].to; ll cost = tree[source][i].cost; if (target == parent) continue; init(target, source, d + 1, cost + l); } } void build(){ rep(k, logN - 1) rep(n, N){ // if there is no parent, -1. // otherwise, the parent of the parent is the parent. if (parents[k][n] < 0) parents[k + 1][n] = -1; else parents[k + 1][n] = parents[k][parents[k][n]]; } } ll query(ll u, ll v){ if (depth[u] > depth[v]) swap(u, v); rep(k, logN) if ((depth[v] - depth[u]) >> k & 1) v = parents[k][v]; if (u == v) return u; revrep(k, logN){ if (parents[k][u] != parents[k][v]){ u = parents[k][u]; v = parents[k][v]; } } return parents[0][u]; } ll distance(ll u, ll v){ ll w = query(u, v); return len[u] + len[v] - 2 * len[w]; } }; */ struct BIT { ll n; vl dat; BIT(ll n) : dat(n + 1), n(n){}; // x: 1001 1010 1100 1011 1101 1111 // x & - x: 0001 0010 0100 0001 0001 0001 // ->: 1010 1100 10000 1100 1100 10000 ll sum(ll i) { ll s = 0; while (i > 0) { s += dat[i]; i -= i & -i; } return s; } ll sum(ll i, ll j) { return sum(j - 1) - sum(i - 1); } void add(ll i, ll x) { while (i <= n) { dat[i] += x; i += i & -i; } } }; ll gcd(ll m, ll n) { ll a = max(m, n); ll b = min(m, n); while (b != 1 && b != 0) { a %= b; swap(a, b); } return b == 1 ? 1 : a; } ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } ll power_mod(ll a, ll power, ll mod) { ll value = 1; while (power != 0) { if (power & 1) value = (value * a) % mod; a = (a * a) % mod; power = power >> 1; } return value % mod; } ll modinv(ll a, ll mod) { return power_mod(a, mod - 2, mod); } ll power_normal(ll a, ll power) { ll value = 1; while (power != 0) { if (power & 1) value = value * a; a = a * a; power = power >> 1; } return value; } ll comb_memo[55][55]; ll pascal_triangle(ll n) { comb_memo[0][0] = 1; For(i, 1, n + 1) rep(j, i + 1) { comb_memo[i][j] += comb_memo[i - 1][j]; if (j > 0) comb_memo[i][j] += comb_memo[i - 1][j - 1]; } } ll combination(ll n, ll r, ll mod) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { (numerator *= ll(n - i)) %= mod; (denomenator *= modinv(i + 1, mod)) %= mod; } return (numerator * denomenator) % mod; } ll combination_no_mod(ll n, ll r) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { numerator *= n - i; denomenator *= i + 1; ll g = gcd(numerator, denomenator); numerator /= g; denomenator /= g; } return numerator; } ld log_combination(ll n, ll r) { if (n == r && n == 0) return 0; else if (n <= 0 || r < 0 || r > n) return -INF; ld val = 0; for (ll i = 0; i < r; i++) { val += log(n - i); val -= log(i + 1); } return val; } ll bin_search(ll key, ll A[], ll left, ll right) { // return the index idx where A[idx] = key. // A[left] is start and A[right] is end.. // In other words, A[right], not A[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (A[mid] == key) return mid; else if (A[mid] > key) right = mid - 1; else if (A[mid] < key) left = mid + 1; } return -1; } /* ll bin_search_temp(ll left, ll right, callable judge){ while(right > left){ // when seeking lower bound ll mid = (right + left) / 2; if (judge(mid)) right = mid; else left = mid + 1; // when seeking upper bound ll mid = (right + left + 1) / 2; if (judge(mid)) left = mid; else right = mid - 1; } return right; } */ ll lower_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] >= key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] < key && key <= A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] < key && key <= A[mid]) return mid; else if (A[mid - 1] >= key) right = mid - 1; else if (A[mid] < key) left = mid; } return -1; // all the elements < key } ll inf_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] > key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] <= key && key < A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] <= key && key < A[mid]) return mid; else if (A[mid - 1] > key) right = mid - 1; else if (A[mid] <= key) left = mid; } return -1; // all the elements <= key } ll upper_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] <= key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] <= key && key < A[right]) return right - 1; else return -1; } if (A[mid] <= key && key < A[mid + 1]) return mid; else if (A[mid] > key) right = mid; else if (A[mid + 1] <= key) left = mid + 1; } return -1; // all the elements > key } ll sup_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] < key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] < key && key <= A[right]) return right - 1; else return -1; } if (A[mid] < key && key <= A[mid + 1]) return mid; else if (A[mid] >= key) right = mid; else if (A[mid + 1] < key) left = mid + 1; } return -1; // all the elements >= key } ll bin_search_vector(ll key, vl v, ll left, ll right) { // return the index idx where v[idx] = key. // v[left] is start and v[right] is end.. // In other words, v[right], not v[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (v[mid] == key) return mid; else if (v[mid] > key) right = mid - 1; else if (v[mid] < key) left = mid + 1; } return -1; } ll lower_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] < key <= v[N] // N == -1 if all the elements < key return lower_bound(all(v), key) - v.begin(); } ll inf_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] <= key < v[N] <= key + 1 // N == -1 if all the elements <= key return lower_bound(all(v), key + 1) - v.begin(); } ll upper_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key < v[N + 1] // N == -1 if all the elements > key return upper_bound(all(v), key) - v.begin() - 1; } ll sup_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key - 1 < key <= v[N + 1] // N == -1 if all the elements >= key return upper_bound(all(v), key - 1) - v.begin() - 1; } ll fact(ll n) { if (n == 0) return 1; return n * fact(n - 1); } bool is_prime(ll n) { if (n <= 1) return false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } ll bool_sum(ll a1, ll a2) { if (a1 == 1 || a2 == 1) return 1; return 0; } mll prime_decomposition(ll n) { ll i = 2; mll table; while (i * i <= n) { while (n % i == 0) { table[i]++; n /= i; } i++; } if (n > 1) table[n] = 1; return table; } ll char_to_idx(char c) { ll idx = 0; Forchar(cc, 'a', 'z') { if (c == cc) return idx; else idx++; } } bool is_cross(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4) { ll val1 = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3); ll val2 = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4); ll val3 = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1); ll val4 = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2); return val1 * val2 < 0 && val3 * val4 < 0; } ll next_combination(ll sub) { /* ll n, k; ll bit = (1 << k) - 1; for (; bit < (1 << n); bit = next_combination(bit)){ bool ith = bit & (1 << i); procedures... } */ ll x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } vl z_algorithm(str s) { ll n = s.length(); vl res(n); res[0] = n; ll i1 = 1, i2 = 0; while (i1 < n) { while (i1 + i2 < n && s[i2] == s[i1 + i2]) ++i2; res[i1] = i2; if (i2 == 0) { ++i1; continue; } ll i3 = 1; while (i1 + i3 < n && i3 + res[i3] < i2) { res[i1 + i3] = res[i3]; ++i3; } i1 += i3, i2 -= i3; } return res; } /* const ll N_VERTEX = 310; ll a, b, t; ll dist[N_VERTEX][N_VERTEX]; void warshall_floyd(ll n){ // rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(k, n) rep(i, n) rep(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } int main(void){ in2(n, m); rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(i, m){ in3(a, b, t); a--; b--; dist[a][b] = t; dist[b][a] = t; } warshall_floyd(n); } const ll N_VERTEX = 310; gr graph[N_VERTEX]; ll dist[N_VERTEX], a, b, t, n, m; void dijkstra(ll start, ll n) { priority_queue<pl, vector<pl>, greater<pl>> edge_costs; fill(dist, dist + n, INF); dist[start] = 0; edge_costs.push(pl(0, start)); while (!edge_costs.empty()) { pl edge_cost = edge_costs.top(); edge_costs.pop(); ll idx = edge_cost.second; ll cost = edge_cost.first; if (dist[idx] < cost) continue; rep(i, graph[idx].size()){ edge e = graph[idx][i]; if (dist[e.to] > dist[idx] + e.cost){ dist[e.to] = dist[idx] + e.cost; edge_costs.push(pl(dist[e.to], e.to)); } } } } int main(void){ in2(n, m); rep(i, m){ in3(a, b, t); a--; b--; G[a].pb({b, t}); G[b].pb({a, t}); } dijkstra(0, n); } # ABC061D bool bellman_ford(ll start, ll n, ll goal){ // if there is a closed circuit, it returns false. (when goal == -1) // if the distance to goal cannot be obtained, it returns false (when goal != -1) fill(dist, dist + n, INF); dist[start] = 0; rep(i, n) rep(v, n) rep(k, graph[v].size()){ edge e = graph[v][k]; if (dist[e.to] > dist[v] + e.cost){ dist[e.to] = dist[v] + e.cost; if (i == n - 1 && (e.to == goal || goal == -1)) return false; } } return true; } */ /* # 1. The usage of map pair map<pl, ll> cnt; cnt[{i, j}] = 0; items(kv, cnt){ prl2(kv.first, kv.second); } # 2. The usage of next_permutation and combination (factorial search) ll a[8]; rep(i, 8) a[i] = i; sort(a, a + 8); do{ }while(next_permutation(a, a+n)); // here, combination ll n, r; ll i1, i2, ..., ir; For(i1, n - r, n) For(i2, n - r - 1, i1) ... For(ir, n - 2 * r + 1, irr){ process;} # 3. bit search ll n; in1(n); const ll base = 3; ll upper = power_normal(base, n); rep(i, upper){ ll tmp = i; rep(j, n){ rep(k, base) if (tmp % base == k) prl(k); tmp /= base; } } # 4. imos method // used when we would like to count the number which // shows how many times the numbers between l and r belongs to smt. // This method is composed of three process. ll n, m, s[MAX_M], l, r; in2(n, m); rep(i, m) s[i] = 0; // 1st step rep(i, n){ in3(l, r, c); l--; r--; // if l starts from 1. s[l] += c; s[r + 1] -= c; } // 2nd step rep(i, m - 1) s[i + 1] += s[i]; // 3rd step: judgement... #5. shakutori method (syakutori) // 1. strech right side while the condition is met. // 2. renew the answer // 3. increments left side // 4. Back to 1. (l <= r must be satisfied all the time.) ll l = 0; ll r = 0; while (l < n){ r = max(r, l); if (l == r) r++; while(r < n && cond) r++; answer += r - l; l++; } prl(answer); #6. priority queue pq q; ll answer = 0; ll v; rep(i, n) q.push(a[i]); rep(i, m){ v = q.top(); q.pop(); // get the top value and dump the value from queue v /= 2; q.push(v); // add the new value } while(!q.empty()){ answer += q.top(); q.pop(); } #7. The shortest path between the k-th edge and another edge (Tree) ll depth[MAX_N]; gr tree[MAX_N]; void path(ll source, ll parent, ll all_cost){ depth[source] = all_cost; items(e, tree[source]){ if (e.to == parent) continue; dfs(e.to, source, all_cost + e.cost); } } ll n, k, a, b, c; in2(n, k); rep(i, n - 1){ in3(a, b, c); a--; b--; tree[a].pb({b, c}); tree[b].pb({a, c}); } k--; dfs(k, -1, 0); #10. Visiting Subtree using recurrent function (ABC138D) gr tree[MAX_N]; ll c[MAX_N]; bool visited[MAX_N]; void dfs(ll source, ll parent, ll val){ visited[source] = true; c[source] += val; rep(i, tree[source].size()){ rep(i, m){ll res = n % match[i].e1;} ll vertex = tree[source][i].to; if (vertex == parent) continue; dfs(vertex, source, c[source]); } } #11. bfs ABC146D, ABC007C 1. first create a tree. 2. start searching from a node. 3. do some processes and push nodes connected with a given target node in BFS. 4. repeat a series of procedure until queue is empty. queue<pl> q; void bfs(ll source, ll parents){ ll n_edge = G[source].size(); if (parents != -1) dist[source] = min(dist[source], dist[parents] + 1); if (visited[source]) return; visited[source] = true; rep(idx, n_edge){ ll target = G[source][idx].to; if (target == parents) continue; q.push(mp(target, source)); } } q.push(mp(sg.e1, -1)); while(!q.empty()){ pl source = q.front(); q.pop(); bfs(source.e1, source.e2); } #12. grid to distance matrix (dx, dy) ll w, h; ll pos_to_idx(ll x, ll y){ return y * w + x; } pl idx_to_pos(ll idx){ return mp(idx % w, idx / w); } int main(void){ in2(h, w); rep(y, h){ in1(s); rep(x, w){ if (s[x] == '#') wall[x][y] = true; else wall[x][y] = false; } } rep(i1, h * w)rep(i2, h * w) dist[i1][i2] = INF * (i1 != i2); rep(x, w)rep(y, h){ ll idx1 = pos_to_idx(x, y); ll idx2; if (wall[x][y]) continue; if (x != 0 && !wall[x - 1][y]){ idx2 = pos_to_idx(x - 1, y); // if warshall floyd dist[idx1][idx2] = 1; // if dijkstra // graph[idx1].pb({idx2, 1}); } if (x != w - 1 && !wall[x + 1][y]){ idx2 = pos_to_idx(x + 1, y); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != 0 && !wall[x][y - 1]){ idx2 = pos_to_idx(x, y - 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != h - 1 && !wall[x][y + 1]){ idx2 = pos_to_idx(x, y + 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } } } */ /* # the operators regarding bit & (AND), | (OR), ^ (XOR) - (REVERSE), >> (SMALLER SHIFT) << (BIGGER SHIFT) x1: 0000 0001 0010 0101 0110 0111 x2: xxxx 0001 0011 0100 0101 1000 x1 & x2: 0000 0001 0010 0100 0100 0000 x: 1001 1010 1100 1011 1101 1111 x & - x: 0001 0010 0100 0001 0001 0001 sum: 1010 1100 10000 1100 1100 10000 x << y is x * 2 ** y x >> y is rep(i, y) x = x // 2 Let S be a bit sequence and i be a non-negative integer S & (1 << i) -> if true, i in S S | (1 << i) -> S union {i} S & -(1 << i) -> S - {i} __builtin_popcount(S) -> the number of elements in S S = 0 -> S is an empty set S = (1 << n) - 1 -> S includes all the elements up to the n-th #Conditional Operator condition ? true : false; #iterator type declaration: auto value reference: *itr increment: itr++ decrement: itr-- substitution of value: *itr = smt */ const ll MAX_N = 100005; bool okay = false; ll answer = 0; ll n, k; ll memo[2][MAX_N]; ll combination_memo(ll n, ll r, ll pre, ll mod) { // pre = nCr-1 // return nCr if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = ll(n - r + 1) % mod; ll denomenator = modinv(r, mod) % mod; ll val = (numerator * denomenator) % mod; val *= pre; return val % mod; } void solve() { if (k >= n - 1) answer = combination(2 * n - 1, n, MOD); else { memo[0][0] = memo[1][0] = 1; rep(i, k) { memo[0][i + 1] = combination_memo(n, i + 1, memo[0][i], MOD); memo[1][i + 1] = combination_memo(n - 1, i + 1, memo[1][i], MOD); answer += (memo[0][i + 1] * memo[1][i + 1]) % MOD; answer %= MOD; } answer++; } prl(answer); // check negative MOD // check index flow // check overwrite of the input variables } int main(void) { in2(n, k); // assert(n <= 30); solve(); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cassert> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; using edge = struct { ll to; ll cost; }; using point = struct { ll x; ll y; }; typedef string str; typedef std::pair<ll, ll> pl; typedef std::pair<ll, pl> pl3; typedef std::map<string, ll> msl; typedef std::map<char, ll> mcl; typedef std::map<ll, ll> mll; typedef std::vector<ll> vl; typedef std::vector<pl> vpl; typedef std::vector<point> vxy; typedef std::vector<pl3> vpl3; typedef std::priority_queue<ll> pq; typedef std::priority_queue<ll, vl, greater<ll>> pql; // priority queue taking from the lower value. typedef std::vector<edge> gr; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll INF = MOD * MOD; const long double EPS = 1e-9; const long double PI = 3.14159265358979323846; #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define revrep(i, n) for (ll(i) = n - 1; (i) >= 0; (i)--) #define For(i, a, b) for (ll(i) = (a); (i) < (b); (i)++) #define revFor(i, b, a) for (ll(i) = (b)-1; (i) >= (a); (i)--) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define isUpper(c) ('a' - c > 0) #define toLower(c) char((c) + 0x20) #define toUpper(c) char((c)-0x20) #define pb push_back #define mp make_pair #define pr(a) cout << (a) #define prl(a) cout << (a) << endl #define prl2(a, b) cout << (a) << " " << (b) << endl #define prl3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define prl4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define prs(a) cout << (a) << " " #define yn(condition) \ if ((condition)) \ prl("Yes"); \ else \ prl("No"); #define YN(condition) \ if ((condition)) \ prl("YES"); \ else \ prl("NO"); #define in1(a) cin >> (a) #define in2(a, b) cin >> (a) >> (b) #define in3(a, b, c) cin >> (a) >> (b) >> (c) #define in4(a, b, c, d) cin >> (a) >> (b) >> (c) >> (d) #define e1 first #define e2 second #define ctol(c) ll((c)) - ll('0') #define ltos(n) to_string((n)) #define items(kv, v) for (auto &(kv) : (v)) #define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)])) #define rsort(a, n) sort(a, a + n, greater<>()) #define Forchar(c, a, z) for (char(c) = (a); (c) <= (z); (c)++) #define cntchar(s, c) count(all((s)), c) #define substring(s, start, end) s.substr((start), (end) - (start) + 1) #define prl_nd(num, digits) \ cout << fixed << setprecision(digits) << (num) << endl; #define XOR(a, b) (a) ^ (b) #define prl_time(s) \ prl3("Elapsed Time:", 1000.0 * (clock() - s) / CLOCKS_PER_SEC, "[ms]"); #define char_to_str(c) string(1, (c)) #define bin_expression(n, dig) bitset<(dig)>(n) #define DEBUG(x) cerr << #x << ": " << (x) << endl #define DEBUG_VEC(v) \ cerr << #v << ": "; \ rep(__i, (v).size()) cerr << ((v)[__i]) << ", "; \ cerr << endl class UnionFind { vl parents, set_size; public: UnionFind() {} UnionFind(ll n) { parents = set_size = vl(n); rep(i, n) { parents[i] = i; set_size[i] = 1LL; } } ll root_find(ll x) { if (parents[x] == x) return x; return parents[x] = root_find(parents[x]); } void unite(ll x, ll y) { x = root_find(x); y = root_find(y); if (x == y) return; if (set_size[x] < set_size[y]) { parents[y] = x; set_size[x] += set_size[y]; } else { parents[x] = y; set_size[y] += set_size[x]; } } bool is_same(ll x, ll y) { // connected or not return root_find(x) == root_find(y); } ll size(ll x) { return set_size[root_find(x)]; } }; /* class LCA{ public: ll N, logN; vl depth, len; gr tree[200005]; // global declaration later. vector<vl> parents; LCA(ll n){ N = n; logN = 0; while (N > (1LL << logN)) logN++; depth = vl(N); len = vl(N); parents = vector<vl>(logN, vl(N)); init(0, -1, 0, 0); build(); } void init(ll source, ll parent, ll d, ll l){ depth[source] = d; parents[0][source] = parent; len[source] = l; rep(i, tree[source].size()){ ll target = tree[source][i].to; ll cost = tree[source][i].cost; if (target == parent) continue; init(target, source, d + 1, cost + l); } } void build(){ rep(k, logN - 1) rep(n, N){ // if there is no parent, -1. // otherwise, the parent of the parent is the parent. if (parents[k][n] < 0) parents[k + 1][n] = -1; else parents[k + 1][n] = parents[k][parents[k][n]]; } } ll query(ll u, ll v){ if (depth[u] > depth[v]) swap(u, v); rep(k, logN) if ((depth[v] - depth[u]) >> k & 1) v = parents[k][v]; if (u == v) return u; revrep(k, logN){ if (parents[k][u] != parents[k][v]){ u = parents[k][u]; v = parents[k][v]; } } return parents[0][u]; } ll distance(ll u, ll v){ ll w = query(u, v); return len[u] + len[v] - 2 * len[w]; } }; */ struct BIT { ll n; vl dat; BIT(ll n) : dat(n + 1), n(n){}; // x: 1001 1010 1100 1011 1101 1111 // x & - x: 0001 0010 0100 0001 0001 0001 // ->: 1010 1100 10000 1100 1100 10000 ll sum(ll i) { ll s = 0; while (i > 0) { s += dat[i]; i -= i & -i; } return s; } ll sum(ll i, ll j) { return sum(j - 1) - sum(i - 1); } void add(ll i, ll x) { while (i <= n) { dat[i] += x; i += i & -i; } } }; ll gcd(ll m, ll n) { ll a = max(m, n); ll b = min(m, n); while (b != 1 && b != 0) { a %= b; swap(a, b); } return b == 1 ? 1 : a; } ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } ll power_mod(ll a, ll power, ll mod) { ll value = 1; while (power != 0) { if (power & 1) value = (value * a) % mod; a = (a * a) % mod; power = power >> 1; } return value % mod; } ll modinv(ll a, ll mod) { return power_mod(a, mod - 2, mod); } ll power_normal(ll a, ll power) { ll value = 1; while (power != 0) { if (power & 1) value = value * a; a = a * a; power = power >> 1; } return value; } ll comb_memo[55][55]; ll pascal_triangle(ll n) { comb_memo[0][0] = 1; For(i, 1, n + 1) rep(j, i + 1) { comb_memo[i][j] += comb_memo[i - 1][j]; if (j > 0) comb_memo[i][j] += comb_memo[i - 1][j - 1]; } } ll combination(ll n, ll r, ll mod) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { (numerator *= ll(n - i)) %= mod; (denomenator *= modinv(i + 1, mod)) %= mod; } return (numerator * denomenator) % mod; } ll combination_no_mod(ll n, ll r) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { numerator *= n - i; denomenator *= i + 1; ll g = gcd(numerator, denomenator); numerator /= g; denomenator /= g; } return numerator; } ld log_combination(ll n, ll r) { if (n == r && n == 0) return 0; else if (n <= 0 || r < 0 || r > n) return -INF; ld val = 0; for (ll i = 0; i < r; i++) { val += log(n - i); val -= log(i + 1); } return val; } ll bin_search(ll key, ll A[], ll left, ll right) { // return the index idx where A[idx] = key. // A[left] is start and A[right] is end.. // In other words, A[right], not A[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (A[mid] == key) return mid; else if (A[mid] > key) right = mid - 1; else if (A[mid] < key) left = mid + 1; } return -1; } /* ll bin_search_temp(ll left, ll right, callable judge){ while(right > left){ // when seeking lower bound ll mid = (right + left) / 2; if (judge(mid)) right = mid; else left = mid + 1; // when seeking upper bound ll mid = (right + left + 1) / 2; if (judge(mid)) left = mid; else right = mid - 1; } return right; } */ ll lower_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] >= key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] < key && key <= A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] < key && key <= A[mid]) return mid; else if (A[mid - 1] >= key) right = mid - 1; else if (A[mid] < key) left = mid; } return -1; // all the elements < key } ll inf_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] > key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] <= key && key < A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] <= key && key < A[mid]) return mid; else if (A[mid - 1] > key) right = mid - 1; else if (A[mid] <= key) left = mid; } return -1; // all the elements <= key } ll upper_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] <= key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] <= key && key < A[right]) return right - 1; else return -1; } if (A[mid] <= key && key < A[mid + 1]) return mid; else if (A[mid] > key) right = mid; else if (A[mid + 1] <= key) left = mid + 1; } return -1; // all the elements > key } ll sup_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] < key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] < key && key <= A[right]) return right - 1; else return -1; } if (A[mid] < key && key <= A[mid + 1]) return mid; else if (A[mid] >= key) right = mid; else if (A[mid + 1] < key) left = mid + 1; } return -1; // all the elements >= key } ll bin_search_vector(ll key, vl v, ll left, ll right) { // return the index idx where v[idx] = key. // v[left] is start and v[right] is end.. // In other words, v[right], not v[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (v[mid] == key) return mid; else if (v[mid] > key) right = mid - 1; else if (v[mid] < key) left = mid + 1; } return -1; } ll lower_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] < key <= v[N] // N == -1 if all the elements < key return lower_bound(all(v), key) - v.begin(); } ll inf_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] <= key < v[N] <= key + 1 // N == -1 if all the elements <= key return lower_bound(all(v), key + 1) - v.begin(); } ll upper_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key < v[N + 1] // N == -1 if all the elements > key return upper_bound(all(v), key) - v.begin() - 1; } ll sup_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key - 1 < key <= v[N + 1] // N == -1 if all the elements >= key return upper_bound(all(v), key - 1) - v.begin() - 1; } ll fact(ll n) { if (n == 0) return 1; return n * fact(n - 1); } bool is_prime(ll n) { if (n <= 1) return false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } ll bool_sum(ll a1, ll a2) { if (a1 == 1 || a2 == 1) return 1; return 0; } mll prime_decomposition(ll n) { ll i = 2; mll table; while (i * i <= n) { while (n % i == 0) { table[i]++; n /= i; } i++; } if (n > 1) table[n] = 1; return table; } ll char_to_idx(char c) { ll idx = 0; Forchar(cc, 'a', 'z') { if (c == cc) return idx; else idx++; } } bool is_cross(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4) { ll val1 = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3); ll val2 = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4); ll val3 = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1); ll val4 = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2); return val1 * val2 < 0 && val3 * val4 < 0; } ll next_combination(ll sub) { /* ll n, k; ll bit = (1 << k) - 1; for (; bit < (1 << n); bit = next_combination(bit)){ bool ith = bit & (1 << i); procedures... } */ ll x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } vl z_algorithm(str s) { ll n = s.length(); vl res(n); res[0] = n; ll i1 = 1, i2 = 0; while (i1 < n) { while (i1 + i2 < n && s[i2] == s[i1 + i2]) ++i2; res[i1] = i2; if (i2 == 0) { ++i1; continue; } ll i3 = 1; while (i1 + i3 < n && i3 + res[i3] < i2) { res[i1 + i3] = res[i3]; ++i3; } i1 += i3, i2 -= i3; } return res; } /* const ll N_VERTEX = 310; ll a, b, t; ll dist[N_VERTEX][N_VERTEX]; void warshall_floyd(ll n){ // rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(k, n) rep(i, n) rep(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } int main(void){ in2(n, m); rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(i, m){ in3(a, b, t); a--; b--; dist[a][b] = t; dist[b][a] = t; } warshall_floyd(n); } const ll N_VERTEX = 310; gr graph[N_VERTEX]; ll dist[N_VERTEX], a, b, t, n, m; void dijkstra(ll start, ll n) { priority_queue<pl, vector<pl>, greater<pl>> edge_costs; fill(dist, dist + n, INF); dist[start] = 0; edge_costs.push(pl(0, start)); while (!edge_costs.empty()) { pl edge_cost = edge_costs.top(); edge_costs.pop(); ll idx = edge_cost.second; ll cost = edge_cost.first; if (dist[idx] < cost) continue; rep(i, graph[idx].size()){ edge e = graph[idx][i]; if (dist[e.to] > dist[idx] + e.cost){ dist[e.to] = dist[idx] + e.cost; edge_costs.push(pl(dist[e.to], e.to)); } } } } int main(void){ in2(n, m); rep(i, m){ in3(a, b, t); a--; b--; G[a].pb({b, t}); G[b].pb({a, t}); } dijkstra(0, n); } # ABC061D bool bellman_ford(ll start, ll n, ll goal){ // if there is a closed circuit, it returns false. (when goal == -1) // if the distance to goal cannot be obtained, it returns false (when goal != -1) fill(dist, dist + n, INF); dist[start] = 0; rep(i, n) rep(v, n) rep(k, graph[v].size()){ edge e = graph[v][k]; if (dist[e.to] > dist[v] + e.cost){ dist[e.to] = dist[v] + e.cost; if (i == n - 1 && (e.to == goal || goal == -1)) return false; } } return true; } */ /* # 1. The usage of map pair map<pl, ll> cnt; cnt[{i, j}] = 0; items(kv, cnt){ prl2(kv.first, kv.second); } # 2. The usage of next_permutation and combination (factorial search) ll a[8]; rep(i, 8) a[i] = i; sort(a, a + 8); do{ }while(next_permutation(a, a+n)); // here, combination ll n, r; ll i1, i2, ..., ir; For(i1, n - r, n) For(i2, n - r - 1, i1) ... For(ir, n - 2 * r + 1, irr){ process;} # 3. bit search ll n; in1(n); const ll base = 3; ll upper = power_normal(base, n); rep(i, upper){ ll tmp = i; rep(j, n){ rep(k, base) if (tmp % base == k) prl(k); tmp /= base; } } # 4. imos method // used when we would like to count the number which // shows how many times the numbers between l and r belongs to smt. // This method is composed of three process. ll n, m, s[MAX_M], l, r; in2(n, m); rep(i, m) s[i] = 0; // 1st step rep(i, n){ in3(l, r, c); l--; r--; // if l starts from 1. s[l] += c; s[r + 1] -= c; } // 2nd step rep(i, m - 1) s[i + 1] += s[i]; // 3rd step: judgement... #5. shakutori method (syakutori) // 1. strech right side while the condition is met. // 2. renew the answer // 3. increments left side // 4. Back to 1. (l <= r must be satisfied all the time.) ll l = 0; ll r = 0; while (l < n){ r = max(r, l); if (l == r) r++; while(r < n && cond) r++; answer += r - l; l++; } prl(answer); #6. priority queue pq q; ll answer = 0; ll v; rep(i, n) q.push(a[i]); rep(i, m){ v = q.top(); q.pop(); // get the top value and dump the value from queue v /= 2; q.push(v); // add the new value } while(!q.empty()){ answer += q.top(); q.pop(); } #7. The shortest path between the k-th edge and another edge (Tree) ll depth[MAX_N]; gr tree[MAX_N]; void path(ll source, ll parent, ll all_cost){ depth[source] = all_cost; items(e, tree[source]){ if (e.to == parent) continue; dfs(e.to, source, all_cost + e.cost); } } ll n, k, a, b, c; in2(n, k); rep(i, n - 1){ in3(a, b, c); a--; b--; tree[a].pb({b, c}); tree[b].pb({a, c}); } k--; dfs(k, -1, 0); #10. Visiting Subtree using recurrent function (ABC138D) gr tree[MAX_N]; ll c[MAX_N]; bool visited[MAX_N]; void dfs(ll source, ll parent, ll val){ visited[source] = true; c[source] += val; rep(i, tree[source].size()){ rep(i, m){ll res = n % match[i].e1;} ll vertex = tree[source][i].to; if (vertex == parent) continue; dfs(vertex, source, c[source]); } } #11. bfs ABC146D, ABC007C 1. first create a tree. 2. start searching from a node. 3. do some processes and push nodes connected with a given target node in BFS. 4. repeat a series of procedure until queue is empty. queue<pl> q; void bfs(ll source, ll parents){ ll n_edge = G[source].size(); if (parents != -1) dist[source] = min(dist[source], dist[parents] + 1); if (visited[source]) return; visited[source] = true; rep(idx, n_edge){ ll target = G[source][idx].to; if (target == parents) continue; q.push(mp(target, source)); } } q.push(mp(sg.e1, -1)); while(!q.empty()){ pl source = q.front(); q.pop(); bfs(source.e1, source.e2); } #12. grid to distance matrix (dx, dy) ll w, h; ll pos_to_idx(ll x, ll y){ return y * w + x; } pl idx_to_pos(ll idx){ return mp(idx % w, idx / w); } int main(void){ in2(h, w); rep(y, h){ in1(s); rep(x, w){ if (s[x] == '#') wall[x][y] = true; else wall[x][y] = false; } } rep(i1, h * w)rep(i2, h * w) dist[i1][i2] = INF * (i1 != i2); rep(x, w)rep(y, h){ ll idx1 = pos_to_idx(x, y); ll idx2; if (wall[x][y]) continue; if (x != 0 && !wall[x - 1][y]){ idx2 = pos_to_idx(x - 1, y); // if warshall floyd dist[idx1][idx2] = 1; // if dijkstra // graph[idx1].pb({idx2, 1}); } if (x != w - 1 && !wall[x + 1][y]){ idx2 = pos_to_idx(x + 1, y); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != 0 && !wall[x][y - 1]){ idx2 = pos_to_idx(x, y - 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != h - 1 && !wall[x][y + 1]){ idx2 = pos_to_idx(x, y + 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } } } */ /* # the operators regarding bit & (AND), | (OR), ^ (XOR) - (REVERSE), >> (SMALLER SHIFT) << (BIGGER SHIFT) x1: 0000 0001 0010 0101 0110 0111 x2: xxxx 0001 0011 0100 0101 1000 x1 & x2: 0000 0001 0010 0100 0100 0000 x: 1001 1010 1100 1011 1101 1111 x & - x: 0001 0010 0100 0001 0001 0001 sum: 1010 1100 10000 1100 1100 10000 x << y is x * 2 ** y x >> y is rep(i, y) x = x // 2 Let S be a bit sequence and i be a non-negative integer S & (1 << i) -> if true, i in S S | (1 << i) -> S union {i} S & -(1 << i) -> S - {i} __builtin_popcount(S) -> the number of elements in S S = 0 -> S is an empty set S = (1 << n) - 1 -> S includes all the elements up to the n-th #Conditional Operator condition ? true : false; #iterator type declaration: auto value reference: *itr increment: itr++ decrement: itr-- substitution of value: *itr = smt */ const ll MAX_N = 200005; bool okay = false; ll answer = 0; ll n, k; ll memo[2][MAX_N]; ll combination_memo(ll n, ll r, ll pre, ll mod) { // pre = nCr-1 // return nCr if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = ll(n - r + 1) % mod; ll denomenator = modinv(r, mod) % mod; ll val = (numerator * denomenator) % mod; val *= pre; return val % mod; } void solve() { if (k >= n - 1) answer = combination(2 * n - 1, n, MOD); else { memo[0][0] = memo[1][0] = 1; rep(i, k) { memo[0][i + 1] = combination_memo(n, i + 1, memo[0][i], MOD); memo[1][i + 1] = combination_memo(n - 1, i + 1, memo[1][i], MOD); answer += (memo[0][i + 1] * memo[1][i + 1]) % MOD; answer %= MOD; } answer++; } prl(answer); // check negative MOD // check index flow // check overwrite of the input variables } int main(void) { in2(n, k); // assert(n <= 30); solve(); return 0; }
replace
925
926
925
926
0
p02769
Python
Runtime Error
import sys sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def input(): return sys.stdin.readline().strip() class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9 + 7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): if n < r: return 0 return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n + 1): fac.append(fac[i - 1] * i % self.mod) facinv.append(facinv[i - 1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n + 1) modinv[1] = 1 for i in range(2, n + 1): modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod return modinv def main(): N, K = map(int, input().split()) comb = Combination(n_max=10**5 * 2 + 10) if N <= K: ans = comb(2 * N - 1, N) else: if K == 1: ans = comb(N, 1) * comb(N - 1, 1) else: ans = 0 # mはゼロとなる数 for m in range(K + 1): ans += comb(N, m) * comb(N - 1, m) ans %= MOD print(ans) if __name__ == "__main__": main()
import sys sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def input(): return sys.stdin.readline().strip() class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9 + 7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): if n < r: return 0 return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n + 1): fac.append(fac[i - 1] * i % self.mod) facinv.append(facinv[i - 1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n + 1) modinv[1] = 1 for i in range(2, n + 1): modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod return modinv def main(): N, K = map(int, input().split()) comb = Combination(n_max=10**5 * 4 + 10) if N <= K: ans = comb(2 * N - 1, N) else: if K == 1: ans = comb(N, 1) * comb(N - 1, 1) else: ans = 0 # mはゼロとなる数 for m in range(K + 1): ans += comb(N, m) * comb(N - 1, m) ans %= MOD print(ans) if __name__ == "__main__": main()
replace
51
52
51
52
0
p02769
Python
Runtime Error
from functools import lru_cache CHECK = False N, K = list(map(int, input().split())) MOD = 10**9 + 7 @lru_cache(maxsize=None) def modInverse(a, p): # Fermat's little theorem, a**(p-1) = 1 mod p return pow(a, p - 2, p) if CHECK: fact = [1] for i in range(1, 2 * N + 1): fact.append((fact[-1] * i) % MOD) def nCr(n, r, p=MOD): # Modulo binomial coefficients return (fact[n] * modInverse(fact[r], p) * modInverse(fact[n - r], p)) % p if N - 1 <= K: # Any combo is achievable so this is stars and bars # N people into N rooms, which means N - 1 dividers stars = N bars = N - 1 print(nCr(stars + bars, bars)) else: # Group by number of empty rooms # With K moves there can only be at most K empty rooms # Max of N - 1 empty rooms in general assert K + 1 < N tot = 0 comb1 = 1 comb2 = 1 for numEmpty in range(K + 1): way3 = comb1 * comb2 if CHECK: numNonEmpty = N - numEmpty stars = numEmpty # Everyone moving into an occupied room bars = numNonEmpty - 1 # Number of dividers way1 = nCr(stars + bars, bars) * nCr(N, numEmpty) way2 = nCr(N, numEmpty) * nCr(N - 1, numEmpty) assert way1 % MOD == way2 % MOD == way3 % MOD tot += way3 j = numEmpty + 1 invJ = modInverse(j, MOD) comb1 = (N + 1 - j) * comb1 * invJ % MOD comb2 = (N - j) * comb2 * invJ % MOD print(tot % MOD)
from functools import lru_cache CHECK = False N, K = list(map(int, input().split())) MOD = 10**9 + 7 @lru_cache(maxsize=None) def modInverse(a, p): # Fermat's little theorem, a**(p-1) = 1 mod p return pow(a, p - 2, p) if N - 1 <= K or CHECK: fact = [1] for i in range(1, 2 * N + 1): fact.append((fact[-1] * i) % MOD) def nCr(n, r, p=MOD): # Modulo binomial coefficients return (fact[n] * modInverse(fact[r], p) * modInverse(fact[n - r], p)) % p if N - 1 <= K: # Any combo is achievable so this is stars and bars # N people into N rooms, which means N - 1 dividers stars = N bars = N - 1 print(nCr(stars + bars, bars)) else: # Group by number of empty rooms # With K moves there can only be at most K empty rooms # Max of N - 1 empty rooms in general assert K + 1 < N tot = 0 comb1 = 1 comb2 = 1 for numEmpty in range(K + 1): way3 = comb1 * comb2 if CHECK: numNonEmpty = N - numEmpty stars = numEmpty # Everyone moving into an occupied room bars = numNonEmpty - 1 # Number of dividers way1 = nCr(stars + bars, bars) * nCr(N, numEmpty) way2 = nCr(N, numEmpty) * nCr(N - 1, numEmpty) assert way1 % MOD == way2 % MOD == way3 % MOD tot += way3 j = numEmpty + 1 invJ = modInverse(j, MOD) comb1 = (N + 1 - j) * comb1 * invJ % MOD comb2 = (N - j) * comb2 * invJ % MOD print(tot % MOD)
replace
16
17
16
17
NameError: name 'nCr' is not defined
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02769/Python/s497531236.py", line 32, in <module> print(nCr(stars + bars, bars)) NameError: name 'nCr' is not defined
p02769
C++
Runtime Error
#include <bits/stdc++.h> #define fup(i, a, b) for (int i = a; i <= b; ++i) #define fdw(i, a, b) for (int i = a; i >= b; --i) #define sync \ ios::sync_with_stdio(false); \ cin.tie(0) #define cl(a) memset(a, 0, sizeof(a)) #define gcd __gcd #define fi first #define se second #define pb push_back #pragma GCC optimize(2) using namespace std; typedef long long ll; // ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll ksm(ll a, ll b, ll mod) { ll ans = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } // ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ // res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;} bool // MRT(ll x){if(x==2)return true;fup(i,1,50){ll // now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;} void // shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int // j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数" const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double eps = 1e-7; const int N = 2e5 + 10; ll fac[N], inv[N]; ll C(ll n, ll m) { return fac[n] * inv[n - m] % mod * inv[m] % mod; } ll work(ll n, ll m) { return C(n + m - 1, m - 1); } int main() { freopen("D:\\untitled3\\in", "r", stdin); sync; ll n, k; ll ans = 1; fac[0] = fac[1] = inv[0] = inv[1] = 1; fup(i, 2, N - 1) { fac[i] = fac[i - 1] * i % mod; inv[i] = -inv[mod % i] * (mod / i) % mod; while (inv[i] < 0) inv[i] += mod; } fup(i, 2, N - 1) inv[i] = inv[i] * inv[i - 1] % mod; cin >> n >> k; k = min(k, n); fup(i, 1, n - 1) { if (i > k) break; ans += C(n, i) * work(i, n - i); ans %= mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fup(i, a, b) for (int i = a; i <= b; ++i) #define fdw(i, a, b) for (int i = a; i >= b; --i) #define sync \ ios::sync_with_stdio(false); \ cin.tie(0) #define cl(a) memset(a, 0, sizeof(a)) #define gcd __gcd #define fi first #define se second #define pb push_back #pragma GCC optimize(2) using namespace std; typedef long long ll; // ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll ksm(ll a, ll b, ll mod) { ll ans = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } // ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ // res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;} bool // MRT(ll x){if(x==2)return true;fup(i,1,50){ll // now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;} void // shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int // j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数" const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double eps = 1e-7; const int N = 2e5 + 10; ll fac[N], inv[N]; ll C(ll n, ll m) { return fac[n] * inv[n - m] % mod * inv[m] % mod; } ll work(ll n, ll m) { return C(n + m - 1, m - 1); } int main() { sync; ll n, k; ll ans = 1; fac[0] = fac[1] = inv[0] = inv[1] = 1; fup(i, 2, N - 1) { fac[i] = fac[i - 1] * i % mod; inv[i] = -inv[mod % i] * (mod / i) % mod; while (inv[i] < 0) inv[i] += mod; } fup(i, 2, N - 1) inv[i] = inv[i] * inv[i - 1] % mod; cin >> n >> k; k = min(k, n); fup(i, 1, n - 1) { if (i > k) break; ans += C(n, i) * work(i, n - i); ans %= mod; } cout << ans << endl; return 0; }
delete
39
40
39
39
-11
p02769
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define INF 9e18 #define HELL (int)(1e9 + 7) #define int long long #define double long double #define uint unsigned long long #define deb(x) cerr << #x << " => " << x << "\n" #define deba(x) \ cerr << #x << "\n"; \ for (auto a : x) \ cerr << a << " "; \ cerr << "\n"; #define debm(x) \ cerr << #x << "\n"; \ for (auto a : x) { \ for (auto b : a) \ cerr << b << " "; \ cerr << "\n"; \ } #define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int>(m, val)) #define fastio \ ios_base ::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define pout cout << fixed << setprecision(10) int fastpow(int a, int b, int m) { int res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } int now() { return std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch()) .count(); } vector<int> fact(2e5 + 5); int nck(int n, int k) { return ((fastpow(fact[n - k], HELL - 2, HELL)) * ((fact[n] * fastpow(fact[k], HELL - 2, HELL)) % HELL)) % HELL; } int32_t main() { fastio; time_t start = now(); int n, k; cin >> n >> k; fact[0] = 1; for (int i = 1; i < fact.size(); i++) { fact[i] = (i * fact[i - 1]) % HELL; } int res = nck(2 * n - 1, n - 1); for (int i = k + 1; i < n; i++) { res = (res - (nck(n, i) * nck(n - 1, n - i - 1)) % HELL + HELL) % HELL; } cout << res << endl; cerr << "TIME => " << now() - start << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define INF 9e18 #define HELL (int)(1e9 + 7) #define int long long #define double long double #define uint unsigned long long #define deb(x) cerr << #x << " => " << x << "\n" #define deba(x) \ cerr << #x << "\n"; \ for (auto a : x) \ cerr << a << " "; \ cerr << "\n"; #define debm(x) \ cerr << #x << "\n"; \ for (auto a : x) { \ for (auto b : a) \ cerr << b << " "; \ cerr << "\n"; \ } #define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int>(m, val)) #define fastio \ ios_base ::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define pout cout << fixed << setprecision(10) int fastpow(int a, int b, int m) { int res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } int now() { return std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch()) .count(); } vector<int> fact(5e5 + 5); int nck(int n, int k) { return ((fastpow(fact[n - k], HELL - 2, HELL)) * ((fact[n] * fastpow(fact[k], HELL - 2, HELL)) % HELL)) % HELL; } int32_t main() { fastio; time_t start = now(); int n, k; cin >> n >> k; fact[0] = 1; for (int i = 1; i < fact.size(); i++) { fact[i] = (i * fact[i - 1]) % HELL; } int res = nck(2 * n - 1, n - 1); for (int i = k + 1; i < n; i++) { res = (res - (nck(n, i) * nck(n - 1, n - i - 1)) % HELL + HELL) % HELL; } cout << res << endl; cerr << "TIME => " << now() - start << endl; return 0; }
replace
47
48
47
48
0
TIME => 4
p02770
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } const int mod = 1000000007; ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (auto &vi : vec) os << vi << " "; return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { int K, q; cin >> K >> q; vector<int> d(K); rep(i, K) cin >> d[i]; while (q--) { int n, x, m; cin >> n >> x >> m; int k = K; if (k >= n - 1) { vector<int> a(n); a[0] = x % m; rep3(i, 1, n) a[i] = (a[i - 1] + d[i - 1]) % m; int cnt = 0; rep(i, n - 1) if (a[i] < a[i + 1]) cnt++; cout << cnt << endl; continue; } vector<int> d2 = d; rep(i, k) d2[i] %= m; // ">" を計算 // a は単調増加数列だから普通 "<" // ">" となるのは, d2 < m に注意して, 商が 1 大きくなったとき ll a0 = x; ll an_1 = a0; ll sum = 0; rep(i, k) sum += d2[i]; an_1 += n / k * sum; if (n % k == 0) { an_1 -= d2[n - 1]; } else { rep(i, n % k - 1) { an_1 += d2[i]; } } ll ans = an_1 / m - a0 / m; // cout << endl << ans << endl; // "=" を計算 sum = 0; rep(i, k) if (d2[i] == 0) sum++; ans += n / k * sum; if (n % k == 0) { if (d2[k - 1] == 0) ans--; } else { rep(i, n % k - 1) { if (d2[i] == 0) ans++; } } ans = n - 1 - ans; // "<" = 全体 - "=" - ">" cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } const int mod = 1000000007; ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (auto &vi : vec) os << vi << " "; return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { int K, q; cin >> K >> q; vector<int> d(K); rep(i, K) cin >> d[i]; while (q--) { int n, x, m; cin >> n >> x >> m; int k = K; if (k >= n - 1) { vector<int> a(n); a[0] = x % m; rep3(i, 1, n) a[i] = (a[i - 1] + d[i - 1]) % m; int cnt = 0; rep(i, n - 1) if (a[i] < a[i + 1]) cnt++; cout << cnt << endl; continue; } vector<int> d2 = d; rep(i, k) d2[i] %= m; // ">" を計算 // a は単調増加数列だから普通 "<" // ">" となるのは, d2 < m に注意して, 商が 1 大きくなったとき ll a0 = x; ll an_1 = a0; ll sum = 0; rep(i, k) sum += d2[i]; an_1 += n / k * sum; if (n % k == 0) { an_1 -= d2[k - 1]; // debuged } else { rep(i, n % k - 1) { an_1 += d2[i]; } } ll ans = an_1 / m - a0 / m; // cout << endl << ans << endl; // "=" を計算 sum = 0; rep(i, k) if (d2[i] == 0) sum++; ans += n / k * sum; if (n % k == 0) { if (d2[k - 1] == 0) ans--; } else { rep(i, n % k - 1) { if (d2[i] == 0) ans++; } } ans = n - 1 - ans; // "<" = 全体 - "=" - ">" cout << ans << endl; } }
replace
111
112
111
112
0
p02770
C++
Runtime Error
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int, int>; using pll = pair<ll, ll>; using vvi = vector<vector<int>>; using vvll = vector<vector<ll>>; const ll inf = 1LL << 60; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); // cout << fixed << setprecision(15); ll k, q; cin >> k >> q; vector<ll> d(k); REP(i, k) { cin >> d[i]; } vector<ll> ans(q); REP(i, q) { ll n, x, m; cin >> n >> x >> m; x %= m; vector<ll> dmod(k), ruiseki(k + 1, 0), zeros(k, 0); // ll ruiseki = 0; // ll zeros = 0; REP(j, k) { dmod[j] = d[j] % m; // cout << dmod[j] << " "; ruiseki[j + 1] = ruiseki[j] + dmod[j]; if (ruiseki[j + 1] == ruiseki[j]) { zeros[j + 1] = zeros[j] + 1; // a1 = a0 + d0 で、d0 = 0 の場合 } else zeros[j + 1] = zeros[j]; } // cout << endl; ll shou = (n - 1) / k; ll amari = (n - 1) % k; ll sum = 0; ll zero = 0; sum = x + shou * ruiseki[k] + ruiseki[amari]; zero = zeros[k] * shou + zeros[amari]; ans[i] = (n - 1) - sum / m - zero; } REP(i, q) { cout << ans[i] << endl; } }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int, int>; using pll = pair<ll, ll>; using vvi = vector<vector<int>>; using vvll = vector<vector<ll>>; const ll inf = 1LL << 60; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); // cout << fixed << setprecision(15); ll k, q; cin >> k >> q; vector<ll> d(k); REP(i, k) { cin >> d[i]; } vector<ll> ans(q); REP(i, q) { ll n, x, m; cin >> n >> x >> m; x %= m; vector<ll> dmod(k), ruiseki(k + 1, 0), zeros(k + 1, 0); // ll ruiseki = 0; // ll zeros = 0; REP(j, k) { dmod[j] = d[j] % m; // cout << dmod[j] << " "; ruiseki[j + 1] = ruiseki[j] + dmod[j]; if (ruiseki[j + 1] == ruiseki[j]) { zeros[j + 1] = zeros[j] + 1; // a1 = a0 + d0 で、d0 = 0 の場合 } else zeros[j + 1] = zeros[j]; } // cout << endl; ll shou = (n - 1) / k; ll amari = (n - 1) % k; ll sum = 0; ll zero = 0; sum = x + shou * ruiseki[k] + ruiseki[amari]; zero = zeros[k] * shou + zeros[amari]; ans[i] = (n - 1) - sum / m - zero; } REP(i, q) { cout << ans[i] << endl; } }
replace
37
38
37
38
0
p02770
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <tuple> #include <utility> #include <vector> #define int long long #define endl '\n' #define INF 1000000000000000000 #define all(a) a.begin(), a.end() #define rep(i, n) for (int i = 0; i < (n); i++) #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> PP; template <class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; } ll gcd(ll n, ll m) { return (m ? gcd(m, n % m) : n); } ll lcm(ll n, ll m) { return n / gcd(n, m) * m; } ll mod = 1000000007; ll modsize = 400010; ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } ll modpow(ll a, ll b) { ll ans = 1; a %= mod; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } vector<ll> fac(modsize + 5); vector<ll> inv(modsize + 5); vector<ll> facinv(modsize + 5); void modcalc() { fac[0] = fac[1] = 1; inv[1] = 1; facinv[0] = facinv[1] = 1; for (int i = 2; i < modsize; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; facinv[i] = facinv[i - 1] * inv[i] % mod; } } ll modcomb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[k] % mod * facinv[n - k] % mod; } ll modperm(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[n - k] % mod; } ll modhom(ll n, ll k) { if (n < 0 || k < 0) return 0; if (n == 0 && k == 0) return 1; return modcomb(n + k - 1, k); } template <class T> class segtree { int n; vector<T> data; T def; function<T(T, T)> operation; function<T(T, T)> update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } public: segtree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); modcalc(); int k, q; cin >> k >> q; vector<int> d(k); for (int i = 0; i < k; i++) cin >> d[i]; int len, start, modulo; for (int i = 0; i < q; i++) { cin >> len >> start >> modulo; int ans = len - 1; for (int j = 0; j < k; j++) { if (d[i]) ans += (d[j] - 1) / modulo * ((len + k - j - 2) / k); else ans -= (len + k - j - 2) / k; } ans += start / modulo; for (int j = 0; j < k; j++) { start += d[j] * ((len + k - j - 2) / k); } ans -= start / modulo; cout << ans << endl; } }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <tuple> #include <utility> #include <vector> #define int long long #define endl '\n' #define INF 1000000000000000000 #define all(a) a.begin(), a.end() #define rep(i, n) for (int i = 0; i < (n); i++) #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> PP; template <class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; } ll gcd(ll n, ll m) { return (m ? gcd(m, n % m) : n); } ll lcm(ll n, ll m) { return n / gcd(n, m) * m; } ll mod = 1000000007; ll modsize = 400010; ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } ll modpow(ll a, ll b) { ll ans = 1; a %= mod; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } vector<ll> fac(modsize + 5); vector<ll> inv(modsize + 5); vector<ll> facinv(modsize + 5); void modcalc() { fac[0] = fac[1] = 1; inv[1] = 1; facinv[0] = facinv[1] = 1; for (int i = 2; i < modsize; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; facinv[i] = facinv[i - 1] * inv[i] % mod; } } ll modcomb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[k] % mod * facinv[n - k] % mod; } ll modperm(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * facinv[n - k] % mod; } ll modhom(ll n, ll k) { if (n < 0 || k < 0) return 0; if (n == 0 && k == 0) return 1; return modcomb(n + k - 1, k); } template <class T> class segtree { int n; vector<T> data; T def; function<T(T, T)> operation; function<T(T, T)> update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } public: segtree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); modcalc(); int k, q; cin >> k >> q; vector<int> d(k); for (int i = 0; i < k; i++) cin >> d[i]; int len, start, modulo; for (int i = 0; i < q; i++) { cin >> len >> start >> modulo; int ans = len - 1; for (int j = 0; j < k; j++) { if (d[j]) ans += (d[j] - 1) / modulo * ((len + k - j - 2) / k); else ans -= (len + k - j - 2) / k; } ans += start / modulo; for (int j = 0; j < k; j++) { start += d[j] * ((len + k - j - 2) / k); } ans -= start / modulo; cout << ans << endl; } }
replace
163
164
163
164
0
p02770
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define NDEBUG #include <cassert> typedef long long ll; typedef long double Double; typedef unsigned long long ull; typedef pair<int, int> ii; typedef pair<ll, ll> llll; typedef pair<double, double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<llll> vllll; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<double> vd; typedef vector<long double> vD; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define FOR(var, from, to) for (int var = (from); var <= (to); ++var) #define rep(var, n) for (int var = 0; var < (n); ++var) #define rep1(var, n) for (int var = 1; var <= (n); ++var) #define repC2(vari, varj, n) \ for (int vari = 0; vari < (n)-1; ++vari) \ for (int varj = vari + 1; varj < (n); ++varj) #define repC3(vari, varj, vark, n) \ for (int vari = 0; vari < (n)-2; ++vari) \ for (int varj = vari + 1; varj < (n)-1; ++varj) \ for (int vark = varj + 1; vark < (n); ++vark) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define mset(arr, val) memset(arr, val, sizeof(arr)) #define mid(x, y) ((x) + ((y) - (x)) / 2) #define IN(x, a, b) ((a) <= (x) && (x) <= (b)) #define cons make_pair #define clamp(v, lo, hi) min(max(v, lo), hi) template <typename T> inline bool found(set<T> &s, T elem) { return s.find(elem) != s.end(); } template <typename T> inline bool found(unordered_set<T> &s, T elem) { return s.find(elem) != s.end(); } template <typename T, typename U> inline bool found(map<T, U> &s, U elem) { return s.find(elem) != s.end(); } template <typename T, typename U> inline bool found(unordered_map<T, U> &s, U elem) { return s.find(elem) != s.end(); } template <typename T> inline bool found(vector<T> &s, T elem) { return find(s.begin(), s.end(), elem) != s.end(); } inline int found(string &s, string t) { return (int)s.find(t); } inline int found(string &s, int c) { return (int)s.find(c); } template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) { if (a < b) a = b; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } inline ll square(ll x) { return x * x; } inline ll gcd(ll a, ll b) { while (a) swap(a, b %= a); return b; } template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; } template <typename T> int find_left(vector<T> &v, T elem) { return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1; } template <typename T> int find_right(vector<T> &v, T elem) { return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin()); } const ll MOD = 1000000007LL; ll ADD(ll x, ll y) { return (x + y) % MOD; } ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } ll MUL(ll x, ll y) { return x * y % MOD; } ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD - 2)); } #define INTSPACE 12 char _buf[INTSPACE * 1000000 + 3]; int loadint() { if (fgets(_buf, INTSPACE + 3, stdin) == NULL) return 0; return atoi(_buf); } int loadvec(vector<int> &v, int N = -1) { if (N == 0) { v.clear(); return 0; } if (N == -1) { N = loadint(); if (N == 0) return 0; } int bufsize = INTSPACE * N + 3; if (fgets(_buf, bufsize, stdin) == NULL) return 0; v.resize(N); int i = 0; bool last = false; for (char *p = &_buf[0];;) { char *q = p; while (*q > ' ') ++q; if (*q == 0x0D || *q == 0x0A) last = true; *q = 0; v[i++] = atoi(p); if (last || i == N) break; p = q + 1; } return i; } void read_cr() { fgets(_buf, 256, stdin); } template <typename T1, typename T2> vector<T2> accum(vector<T1> &a, T2 init) { int L = a.size(); vector<T2> acc(L + 1); acc[0] = init; for (int i = 0; i < L; ++i) acc[i + 1] = acc[i] + a[i]; return move(acc); } template <typename T> T accumed(vector<T> &acc, int from, int to) { int M = acc.size() - 1; return acc[min(M, to)] - acc[max(0, from)]; } int k, q, w, wt; vi d(5000); vll dac(10001); void solve(int n, ll x, ll m) { vi z(w, 0); dac[0] = 0; rep(i, w) { dac[i + 1] = dac[i] + d[i % k] % m; if (d[i % k] % m == 0) z[i] = 1; } vi zac = accum(z, 0); int cnt = n - 1; ll a0 = x % m; for (int i = 0; i < n - 1; i += w) { ll lo = a0, hi; if (i + w <= n) { cnt -= zac[w]; hi = a0 + dac[w]; } else { int rem = (n - 1) % w; cnt -= zac[rem]; hi = a0 + dac[rem]; } ll loQ = lo / m, hiQ = hi / m; cnt -= (hiQ - loQ); a0 = hi; } printf("%d\n", cnt); } int main() { scanf("%d %d%*c", &k, &q); loadvec(d, k); w = 0; while (w < 5000) w += k; wt = w / k; rep(i, q) { int n, x, m; scanf("%d %d %d%*c", &n, &x, &m); solve(n, x, m); } return 0; }
#include <bits/stdc++.h> using namespace std; #define NDEBUG #include <cassert> typedef long long ll; typedef long double Double; typedef unsigned long long ull; typedef pair<int, int> ii; typedef pair<ll, ll> llll; typedef pair<double, double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<llll> vllll; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<double> vd; typedef vector<long double> vD; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define FOR(var, from, to) for (int var = (from); var <= (to); ++var) #define rep(var, n) for (int var = 0; var < (n); ++var) #define rep1(var, n) for (int var = 1; var <= (n); ++var) #define repC2(vari, varj, n) \ for (int vari = 0; vari < (n)-1; ++vari) \ for (int varj = vari + 1; varj < (n); ++varj) #define repC3(vari, varj, vark, n) \ for (int vari = 0; vari < (n)-2; ++vari) \ for (int varj = vari + 1; varj < (n)-1; ++varj) \ for (int vark = varj + 1; vark < (n); ++vark) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define mset(arr, val) memset(arr, val, sizeof(arr)) #define mid(x, y) ((x) + ((y) - (x)) / 2) #define IN(x, a, b) ((a) <= (x) && (x) <= (b)) #define cons make_pair #define clamp(v, lo, hi) min(max(v, lo), hi) template <typename T> inline bool found(set<T> &s, T elem) { return s.find(elem) != s.end(); } template <typename T> inline bool found(unordered_set<T> &s, T elem) { return s.find(elem) != s.end(); } template <typename T, typename U> inline bool found(map<T, U> &s, U elem) { return s.find(elem) != s.end(); } template <typename T, typename U> inline bool found(unordered_map<T, U> &s, U elem) { return s.find(elem) != s.end(); } template <typename T> inline bool found(vector<T> &s, T elem) { return find(s.begin(), s.end(), elem) != s.end(); } inline int found(string &s, string t) { return (int)s.find(t); } inline int found(string &s, int c) { return (int)s.find(c); } template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) { if (a < b) a = b; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } inline ll square(ll x) { return x * x; } inline ll gcd(ll a, ll b) { while (a) swap(a, b %= a); return b; } template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; } template <typename T> int find_left(vector<T> &v, T elem) { return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1; } template <typename T> int find_right(vector<T> &v, T elem) { return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin()); } const ll MOD = 1000000007LL; ll ADD(ll x, ll y) { return (x + y) % MOD; } ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } ll MUL(ll x, ll y) { return x * y % MOD; } ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD - 2)); } #define INTSPACE 12 char _buf[INTSPACE * 1000000 + 3]; int loadint() { if (fgets(_buf, INTSPACE + 3, stdin) == NULL) return 0; return atoi(_buf); } int loadvec(vector<int> &v, int N = -1) { if (N == 0) { v.clear(); return 0; } if (N == -1) { N = loadint(); if (N == 0) return 0; } int bufsize = INTSPACE * N + 3; if (fgets(_buf, bufsize, stdin) == NULL) return 0; v.resize(N); int i = 0; bool last = false; for (char *p = &_buf[0];;) { char *q = p; while (*q > ' ') ++q; if (*q == 0x0D || *q == 0x0A) last = true; *q = 0; v[i++] = atoi(p); if (last || i == N) break; p = q + 1; } return i; } void read_cr() { fgets(_buf, 256, stdin); } template <typename T1, typename T2> vector<T2> accum(vector<T1> &a, T2 init) { int L = a.size(); vector<T2> acc(L + 1); acc[0] = init; for (int i = 0; i < L; ++i) acc[i + 1] = acc[i] + a[i]; return move(acc); } template <typename T> T accumed(vector<T> &acc, int from, int to) { int M = acc.size() - 1; return acc[min(M, to)] - acc[max(0, from)]; } int k, q, w, wt; vi d(5000); vll dac(10001); void solve(int n, ll x, ll m) { vi z(w, 0); dac[0] = 0; rep(i, w) { dac[i + 1] = dac[i] + d[i % k] % m; if (d[i % k] % m == 0) z[i] = 1; } vi zac = accum(z, 0); int cnt = n - 1; ll a0 = x % m; int Q = (n - 1) / w, R = (n - 1) % w; ll lo = a0, hi = a0 + dac[w] * Q + dac[R]; ll loQ = lo / m, hiQ = hi / m; cnt -= (hiQ - loQ); int zr = zac[w] * Q + zac[R]; cnt -= zr; printf("%d\n", cnt); } int main() { scanf("%d %d%*c", &k, &q); loadvec(d, k); w = 0; while (w < 5000) w += k; wt = w / k; rep(i, q) { int n, x, m; scanf("%d %d %d%*c", &n, &x, &m); solve(n, x, m); } return 0; }
replace
188
202
188
195
TLE
p02770
C++
Runtime Error
// #i#include "pch.h" #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> typedef long long ll; typedef std::pair<int, int> Pii; typedef std::pair<long long, long long> Pll; typedef std::pair<double, double> Pdd; #define rip(i, n, s) for (int i = (s); i < (int)(n); i++) #define mapa make_pair #define all(a) a.begin(), a.end() #define MM << " " << template <typename T> using MaxHeap = std::priority_queue<T>; template <typename T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); } template <typename T> void vdeb(std::vector<T> &da) { for (int i = 0; i < da.size(); i++) { if (i == da.size() - 1) std::cout << da[i]; else std::cout << da[i] << ' '; } std::cout << std::endl; } template <typename T> void vdeb(std::vector<std::vector<T>> &da) { for (int i = 0; i < da.size(); i++) vdeb(da[i]); std::cout << std::endl; } long long pow(long long n, long long p, long long k) { // n^k(mod p) if (!k) return 1; long long a = pow(n, p, k >> 1); a = a * a % p; if (k & 1) a = a * n % p; return a; } void euclid(long long &a, long long &b, long long p) { // a>=b A*b+B*(a-a/b*b)=1 if (a == 1) { a = 1; } else { long long A = b, B = a % b; euclid(A, B, p); b = (A - (p + a / b) % p * B % p + p) % p; a = B; } } long long rev(long long n, long long p) { // nの逆元 n*x-p*y=1 // long long q = p; // euclid(p, n, p); // return n % q; return pow(n, p, p - 2); } long long bino(long long n, long long m, long long p) { // nCm(mod p) long long ans = 1, div = 1; for (int i = 0; i < m; i++) { ans = (n - i) * ans % p; div = div * (i + 1) % p; } return ans * rev(div, p) % p; } struct modint { long long num; long long p; modint() { num = 0; p = 1000000007; } modint(int x) { p = 1000000007; num = (long long)x % p; } modint(long long x) { p = 1000000007; num = x % p; } modint operator+(const modint &other) { modint ret; ret.p = p; ret.num = (num + other.num) % p; return ret; } modint operator+(const long long &other) { modint ret; ret.p = p; ret.num = (num + (other % p)) % p; return ret; } modint operator-(const modint &other) { modint ret; ret.p = p; ret.num = (num - other.num + p) % p; return ret; } modint operator-(const long long &other) { modint ret; ret.p = p; ret.num = (num - (other % p) + p) % p; return ret; } modint operator*(const modint &other) { modint ret; ret.p = p; ret.num = (num * other.num) % p; return ret; } modint operator*(const long long &other) { modint ret; ret.p = p; ret.num = (num * (other % p)) % p; return ret; } modint operator/(const modint &other) { modint ret; ret.p = p; ret.num = (num * rev(other.num, p)) % p; return ret; } modint operator/(const long long &other) { modint ret; ret.p = p; ret.num = (num * rev(other % p, p)) % p; return ret; } void operator+=(const long long &other) { num = (num + other) % p; } void operator+=(const modint &other) { num = (num + other.num) % p; } void operator-=(const long long &other) { num = (num - other + p) % p; } void operator-=(const modint &other) { num = (num - other.num + p) % p; } void operator*=(const long long &other) { num = (num * other) % p; } void operator*=(const modint &other) { num = (num * other.num) % p; } }; std::ostream &operator<<(std::ostream &os, const modint &x) { std::cout << x.num; return os; } using namespace std; int k, q; const int S = 10; vector<ll> daa(S), eq(S), su(S); int query(vector<ll> &da) { ll n, x, m; cin >> n >> x >> m; int ret = n - 1; rip(i, k, 0) daa[i] = da[i] % m; eq[0] = 0; su[0] = 0; rip(i, k, 0) { su[i + 1] = su[i] + daa[i]; eq[i + 1] = eq[i] + max((ll)0, 1 - daa[i]); } // vdeb(eq); n--; x %= m; ll alsu = su[k] * (n / k) + su[n % k]; ret -= eq[k] * (n / k) + eq[n % k]; ret -= (x + alsu) / m; return ret; } int main() { ; cin >> k >> q; vector<ll> da(k); rip(i, k, 0) cin >> da[i]; vector<ll> ans(q); rip(i, q, 0) { ans[i] = query(da); } rip(i, q, 0) printf("%lld\n", ans[i]); }
// #i#include "pch.h" #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> typedef long long ll; typedef std::pair<int, int> Pii; typedef std::pair<long long, long long> Pll; typedef std::pair<double, double> Pdd; #define rip(i, n, s) for (int i = (s); i < (int)(n); i++) #define mapa make_pair #define all(a) a.begin(), a.end() #define MM << " " << template <typename T> using MaxHeap = std::priority_queue<T>; template <typename T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); } template <typename T> void vdeb(std::vector<T> &da) { for (int i = 0; i < da.size(); i++) { if (i == da.size() - 1) std::cout << da[i]; else std::cout << da[i] << ' '; } std::cout << std::endl; } template <typename T> void vdeb(std::vector<std::vector<T>> &da) { for (int i = 0; i < da.size(); i++) vdeb(da[i]); std::cout << std::endl; } long long pow(long long n, long long p, long long k) { // n^k(mod p) if (!k) return 1; long long a = pow(n, p, k >> 1); a = a * a % p; if (k & 1) a = a * n % p; return a; } void euclid(long long &a, long long &b, long long p) { // a>=b A*b+B*(a-a/b*b)=1 if (a == 1) { a = 1; } else { long long A = b, B = a % b; euclid(A, B, p); b = (A - (p + a / b) % p * B % p + p) % p; a = B; } } long long rev(long long n, long long p) { // nの逆元 n*x-p*y=1 // long long q = p; // euclid(p, n, p); // return n % q; return pow(n, p, p - 2); } long long bino(long long n, long long m, long long p) { // nCm(mod p) long long ans = 1, div = 1; for (int i = 0; i < m; i++) { ans = (n - i) * ans % p; div = div * (i + 1) % p; } return ans * rev(div, p) % p; } struct modint { long long num; long long p; modint() { num = 0; p = 1000000007; } modint(int x) { p = 1000000007; num = (long long)x % p; } modint(long long x) { p = 1000000007; num = x % p; } modint operator+(const modint &other) { modint ret; ret.p = p; ret.num = (num + other.num) % p; return ret; } modint operator+(const long long &other) { modint ret; ret.p = p; ret.num = (num + (other % p)) % p; return ret; } modint operator-(const modint &other) { modint ret; ret.p = p; ret.num = (num - other.num + p) % p; return ret; } modint operator-(const long long &other) { modint ret; ret.p = p; ret.num = (num - (other % p) + p) % p; return ret; } modint operator*(const modint &other) { modint ret; ret.p = p; ret.num = (num * other.num) % p; return ret; } modint operator*(const long long &other) { modint ret; ret.p = p; ret.num = (num * (other % p)) % p; return ret; } modint operator/(const modint &other) { modint ret; ret.p = p; ret.num = (num * rev(other.num, p)) % p; return ret; } modint operator/(const long long &other) { modint ret; ret.p = p; ret.num = (num * rev(other % p, p)) % p; return ret; } void operator+=(const long long &other) { num = (num + other) % p; } void operator+=(const modint &other) { num = (num + other.num) % p; } void operator-=(const long long &other) { num = (num - other + p) % p; } void operator-=(const modint &other) { num = (num - other.num + p) % p; } void operator*=(const long long &other) { num = (num * other) % p; } void operator*=(const modint &other) { num = (num * other.num) % p; } }; std::ostream &operator<<(std::ostream &os, const modint &x) { std::cout << x.num; return os; } using namespace std; int k, q; const int S = 5000; vector<ll> daa(S), eq(S), su(S); int query(vector<ll> &da) { ll n, x, m; cin >> n >> x >> m; int ret = n - 1; rip(i, k, 0) daa[i] = da[i] % m; eq[0] = 0; su[0] = 0; rip(i, k, 0) { su[i + 1] = su[i] + daa[i]; eq[i + 1] = eq[i] + max((ll)0, 1 - daa[i]); } // vdeb(eq); n--; x %= m; ll alsu = su[k] * (n / k) + su[n % k]; ret -= eq[k] * (n / k) + eq[n % k]; ret -= (x + alsu) / m; return ret; } int main() { ; cin >> k >> q; vector<ll> da(k); rip(i, k, 0) cin >> da[i]; vector<ll> ans(q); rip(i, q, 0) { ans[i] = query(da); } rip(i, q, 0) printf("%lld\n", ans[i]); }
replace
173
174
173
174
0
p02771
C++
Runtime Error
#include <stdio.h> int main() { int a, b, c; scanf("%d %d %d", a, b, c); if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a)) printf("Yes"); else printf("No"); return 0; }
#include <stdio.h> int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a)) printf("Yes"); else printf("No"); return 0; }
replace
3
4
3
4
-11
p02771
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define inf 100000000000000000 #define ll long long int #define pb push_back #define f first #define s second #define mod 1000000007 #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) void mahakal() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } int main() { mahakal(); fast; ll arr[3]; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); if ((arr[0] == arr[1] && arr[1] != arr[2]) || (arr[1] == arr[2] && arr[1] != arr[0])) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define inf 100000000000000000 #define ll long long int #define pb push_back #define f first #define s second #define mod 1000000007 #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) void mahakal() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } int main() { // mahakal(); fast; ll arr[3]; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); if ((arr[0] == arr[1] && arr[1] != arr[2]) || (arr[1] == arr[2] && arr[1] != arr[0])) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
replace
18
19
18
19
0
p02771
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long const int N = 2e3 + 5; vector<int> v(3); int32_t main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // code cin >> v[0] >> v[1] >> v[2]; sort(v.begin(), v.end()); if ((v[0] == v[1] && v[1] != v[2]) || (v[0] != v[1] && v[1] == v[2])) cout << "Yes" << endl; else cout << "No" << endl; // code return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long const int N = 2e3 + 5; vector<int> v(3); int32_t main() { IOS; // code cin >> v[0] >> v[1] >> v[2]; sort(v.begin(), v.end()); if ((v[0] == v[1] && v[1] != v[2]) || (v[0] != v[1] && v[1] == v[2])) cout << "Yes" << endl; else cout << "No" << endl; // code return 0; }
replace
12
16
12
13
0
p02771
Python
Runtime Error
a, b, c = list(map(int, input().split())) if len(set(a, b, c)) == 2: print("Yes") else: print("No")
a = list(map(int, input().split())) if len(set(a)) == 2: print("Yes") else: print("No")
replace
0
2
0
2
TypeError: set expected at most 1 argument, got 3
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02771/Python/s500632696.py", line 2, in <module> if len(set(a, b, c)) == 2: TypeError: set expected at most 1 argument, got 3
p02771
C++
Runtime Error
#include <iostream> #include <stdio.h> using namespace std; int main() { int d[10]; for (int i = 0; i < 3; i++) scanf("%d", d[i]); bool chk = true; int v = d[0]; if (v != d[1]) { if (v != d[2]) { if (d[1] == d[2]) chk = true; else chk = false; } else { chk = true; } } else { if (d[1] == d[2]) chk = false; else chk = true; } if (chk) { printf("Yes"); } else { printf("No"); } return 0; }
#include <iostream> #include <stdio.h> using namespace std; int main() { int d[10]; for (int i = 0; i < 3; i++) scanf("%d", &d[i]); bool chk = true; int v = d[0]; if (v != d[1]) { if (v != d[2]) { if (d[1] == d[2]) chk = true; else chk = false; } else { chk = true; } } else { if (d[1] == d[2]) chk = false; else chk = true; } if (chk) { printf("Yes"); } else { printf("No"); } return 0; }
replace
7
8
7
8
-11
p02771
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define all(x) x.begin(), x.end() #define fi first #define se second #define pb push_back #define umax(x, y) x = max(x, (y)) #define umin(x, y) x = min(x, (y)) #define set multiset #define null NULL #define ort (b + s) / 2 using namespace std; typedef long long Lint; typedef long double db; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef pair<db, db> dd; typedef pair<int, string> is; const int maxn = 600020; const int K = 320; const int MOd = 1e9 + 7; int ar[maxn]; void solve() { scanf("%d %d %d", ar[1], ar[2], ar[3]); sort(ar + 1, ar + 1 + 3); if (ar[1] == ar[2] && ar[2] != ar[3]) { printf("Yes\n"); return; } if (ar[1] != ar[2] && ar[2] == ar[3]) { printf("Yes\n"); return; } printf("No\n"); } int main() { int n = 1; // scanf("%d",&n); while (n--) solve(); return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define all(x) x.begin(), x.end() #define fi first #define se second #define pb push_back #define umax(x, y) x = max(x, (y)) #define umin(x, y) x = min(x, (y)) #define set multiset #define null NULL #define ort (b + s) / 2 using namespace std; typedef long long Lint; typedef long double db; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef pair<db, db> dd; typedef pair<int, string> is; const int maxn = 600020; const int K = 320; const int MOd = 1e9 + 7; int ar[maxn]; void solve() { scanf("%d %d %d", &ar[1], &ar[2], &ar[3]); sort(ar + 1, ar + 1 + 3); if (ar[1] == ar[2] && ar[2] != ar[3]) { printf("Yes\n"); return; } if (ar[1] != ar[2] && ar[2] == ar[3]) { printf("Yes\n"); return; } printf("No\n"); } int main() { int n = 1; // scanf("%d",&n); while (n--) solve(); return 0; }
replace
40
41
40
41
-11
p02771
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ms(a, b) memset(a, b, sizeof(a)) const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int maxn = 1e6 + 10; const int mod = 1e9 + 7; const int maxm = 1e3 + 10; using namespace std; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); srand((unsigned int)time(NULL)); #endif ios::sync_with_stdio(false); cin.tie(0); int a[4]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if ((a[0] != a[1] && a[0] != a[2] && a[1] != a[2]) || (a[0] == a[1] && a[0] == a[2])) cout << "No" << endl; else cout << "Yes" << endl; #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ms(a, b) memset(a, b, sizeof(a)) const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int maxn = 1e6 + 10; const int mod = 1e9 + 7; const int maxm = 1e3 + 10; using namespace std; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); srand((unsigned int)time(NULL)); #endif ios::sync_with_stdio(false); cin.tie(0); int a[4]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if ((a[0] != a[1] && a[0] != a[2] && a[1] != a[2]) || (a[0] == a[1] && a[0] == a[2])) cout << "No" << endl; else cout << "Yes" << endl; #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
replace
12
14
12
14
0
Time elapsed: 0.029698 s.
p02771
C++
Runtime Error
#include <iostream> #include <stdio.h> int main() { int a, b, c; scanf("%d%d%d", a, b, c); if ((a != b && b != c && c != a) || (a == b && a == c)) { printf("No\n"); } else { printf("Yes\n"); } }
#include <iostream> #include <stdio.h> int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); if ((a != b && b != c && c != a) || (a == b && a == c)) { printf("No\n"); } else { printf("Yes\n"); } }
replace
4
5
4
5
-11
p02771
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define pb push_back #define f(i, n) for (i = 0; i < n; i++) #define F(i, a, b) for (i = a; a <= b; i++) #define arr(a, n) \ for (i = 0; i < n; i++) \ cin >> a[i]; #define fi first #define se second #define mp make_pair #define mod 1000000007 #define YES cout << "YES" << endl; #define Yes cout << "Yes" << endl; #define NO cout << "NO" << endl; #define No cout << "No" << endl; #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define vi vector<ll> #define ed end() #define bg begin() #define sz size() #define ln length() #define s() sort(a, a + n); #define sr() sort(a, a + n, greater<ll>()); #define v() sort(v.begin(), v.end()); #define vr() sort(v.begin(), v.end(), greater<ll>()); #define mod 1000000007 #define fast() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll power(ll x, ll y, ll p) { ll res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif /* Ofcourse it's Hard. It's supposed to be Hard. If it's easy everyone would do it. HARD IS WHAT MAKES IT GREAT YESTERDAY U SAID TOMORROW SLOWLY BECOMING THE PERSON I SHOULD HAVE BEEN A LONG TIME AGO SAME TASK CAN'T BE FOUND DIFFICULT TWICE BTBHWSITW SPRH TU KAB P CP IS ALL ABOUT THINKING YOU HAVE MUCH MORE POTENTIAL THAN U THINK AJIT SHIDDAT 10 UR DAILY ROUTINE */ fast(); // ll t;cin>>t;while(t--) { ll a, b, c; cin >> a >> b >> c; if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a)) Yes else No } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define pb push_back #define f(i, n) for (i = 0; i < n; i++) #define F(i, a, b) for (i = a; a <= b; i++) #define arr(a, n) \ for (i = 0; i < n; i++) \ cin >> a[i]; #define fi first #define se second #define mp make_pair #define mod 1000000007 #define YES cout << "YES" << endl; #define Yes cout << "Yes" << endl; #define NO cout << "NO" << endl; #define No cout << "No" << endl; #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define vi vector<ll> #define ed end() #define bg begin() #define sz size() #define ln length() #define s() sort(a, a + n); #define sr() sort(a, a + n, greater<ll>()); #define v() sort(v.begin(), v.end()); #define vr() sort(v.begin(), v.end(), greater<ll>()); #define mod 1000000007 #define fast() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll power(ll x, ll y, ll p) { ll res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { /*#ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif*/ /* Ofcourse it's Hard. It's supposed to be Hard. If it's easy everyone would do it. HARD IS WHAT MAKES IT GREAT YESTERDAY U SAID TOMORROW SLOWLY BECOMING THE PERSON I SHOULD HAVE BEEN A LONG TIME AGO SAME TASK CAN'T BE FOUND DIFFICULT TWICE BTBHWSITW SPRH TU KAB P CP IS ALL ABOUT THINKING YOU HAVE MUCH MORE POTENTIAL THAN U THINK AJIT SHIDDAT 10 UR DAILY ROUTINE */ fast(); // ll t;cin>>t;while(t--) { ll a, b, c; cin >> a >> b >> c; if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a)) Yes else No } return 0; }
replace
51
57
51
57
0
p02771
Python
Runtime Error
A, B, C = map(int, input().split()) list = [A, B, C] ans = list(set(list)) if len(ans) == 2: print("Yes") else: print("No")
A, B, C = map(int, input().split()) l = [A, B, C] ans = list(set(l)) if len(ans) == 2: print("Yes") else: print("No")
replace
1
3
1
3
TypeError: 'list' object is not callable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02771/Python/s516174339.py", line 3, in <module> ans = list(set(list)) TypeError: 'list' object is not callable
p02771
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define inf 0x3f3f3f3f typedef long long ll; typedef unsigned long long ull; typedef double db; int mo[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1}; // int mo[8][2] = { -1,0,1,0,-1,-1,1,1,0,-1,0,1,1,-1,-1,1 }; const int maxn = 1e5 + 10; int n, m, is, t, ans, p[maxn]; int main() { #ifdef ONLINE_JUDGE #else freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cout << fixed << setprecision(2); set<int> q; int a; for (int i = 0; i < 3; i++) cin >> a, q.insert(a); if (q.size() == 2) cout << "Yes" << "\n"; else cout << "No" << "\n"; return 0; // good job! } /* author: keke Update log: 2020/2/20 2:46:17 A bug is found... */
#include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define inf 0x3f3f3f3f typedef long long ll; typedef unsigned long long ull; typedef double db; int mo[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1}; // int mo[8][2] = { -1,0,1,0,-1,-1,1,1,0,-1,0,1,1,-1,-1,1 }; const int maxn = 1e5 + 10; int n, m, is, t, ans, p[maxn]; int main() { #ifdef ONLINE_JUDGE #else // freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cout << fixed << setprecision(2); set<int> q; int a; for (int i = 0; i < 3; i++) cin >> a, q.insert(a); if (q.size() == 2) cout << "Yes" << "\n"; else cout << "No" << "\n"; return 0; // good job! } /* author: keke Update log: 2020/2/20 2:46:17 A bug is found... */
replace
14
15
14
15
0
p02771
Python
Runtime Error
nums = list(map(int, input.split(" "))) if len(set(nums)) == 2: print("Yes") else: print("No")
nums = list(map(int, input().split(" "))) if len(set(nums)) == 2: print("Yes") else: print("No")
replace
0
1
0
1
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02771/Python/s880754388.py", line 1, in <module> nums = list(map(int, input.split(" "))) AttributeError: 'builtin_function_or_method' object has no attribute 'split'
p02771
Python
Runtime Error
li = list(map(int, input().split())) if (set(len(li))) == 2: print("Yes") else: print("No")
li = list(map(int, input().split())) if (len(set(li))) == 2: print("Yes") else: print("No")
replace
1
2
1
2
TypeError: 'int' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02771/Python/s620789941.py", line 2, in <module> if (set(len(li))) == 2: TypeError: 'int' object is not iterable
p02771
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long int; int main() { ll a, b, c; cin >> a >> b >> c; map<ll, int> mp; mp[a]++; mp[b]++; mp[c]++; auto it = mp.begin(); while (it != mp.end()) { if (it->second == 2) { cout << "Yes\n"; return 0; } } cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; int main() { ll a, b, c; cin >> a >> b >> c; map<ll, int> mp; mp[a]++; mp[b]++; mp[c]++; auto it = mp.begin(); while (it != mp.end()) { if (it->second == 2) { cout << "Yes\n"; return 0; } it++; } cout << "No\n"; return 0; }
insert
16
16
16
17
TLE
p02772
C++
Runtime Error
#include <bits/stdc++.h> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #define endl "\n" #define ll long long int #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define pii pair<int, int> #define pll pair<long long, long long> #define mod 1000000007 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define mp(x, y) make_pair(x, y) #define mem(a, val) memset(a, val, sizeof(a)) #define eb emplace_back #define f first #define s second using namespace std; int main() { std::ios::sync_with_stdio(false); ll arr[3], N, flag = 0; cin >> N; for (ll i = 0; i < N; ++i) cin >> arr[i]; for (int i = 0; i < N; ++i) { if (arr[i] % 2 == 0) { if (arr[i] % 3 == 0 or arr[i] % 5 == 0) continue; else { flag = 1; break; } } } if (flag) cout << "DENIED"; else cout << "APPROVED"; return 0; }
#include <bits/stdc++.h> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #define endl "\n" #define ll long long int #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define pii pair<int, int> #define pll pair<long long, long long> #define mod 1000000007 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define mp(x, y) make_pair(x, y) #define mem(a, val) memset(a, val, sizeof(a)) #define eb emplace_back #define f first #define s second using namespace std; int main() { std::ios::sync_with_stdio(false); ll arr[1000000], N, flag = 0; cin >> N; for (ll i = 0; i < N; ++i) cin >> arr[i]; for (int i = 0; i < N; ++i) { if (arr[i] % 2 == 0) { if (arr[i] % 3 == 0 or arr[i] % 5 == 0) continue; else { flag = 1; break; } } } if (flag) cout << "DENIED"; else cout << "APPROVED"; return 0; }
replace
25
26
25
26
-6
*** stack smashing detected ***: terminated
p02772
Python
Runtime Error
n = int(input()) arr = [input() for _ in range(n)] dic = {} for i in range(n): if arr[i] not in dic: dic[arr[i]] = 1 else: dic[arr[i]] += 1 largest = max(dic.values()) ans = [] for keys in dic.keys(): if dic[keys] == largest: ans.append(keys) ans = sorted(ans) for words in ans: print(words)
N = int(input()) A = list(map(int, input().split())) for a in A: if a % 2 == 1: continue if a % 3 == 0 or a % 5 == 0: continue print("DENIED") exit() print("APPROVED")
replace
0
16
0
11
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02772/Python/s663457315.py", line 2, in <module> arr = [input() for _ in range(n)] File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02772/Python/s663457315.py", line 2, in <listcomp> arr = [input() for _ in range(n)] EOFError: EOF when reading a line
p02772
Python
Runtime Error
N = int(input()) Ai = input() Ai = Ai.split(" ") ans = "APPROVED" for moji in Ai: if moji % 2 != 0: pass else: if (moji % 3 == 0) or (moji % 5 == 0): pass else: ans = "DENIED" break print(ans)
N = int(input()) Ai = input() Ai = Ai.split(" ") ans = "APPROVED" for moji in Ai: moji = int(moji) if moji % 2 != 0: pass else: if (moji % 3 == 0) or (moji % 5 == 0): pass else: ans = "DENIED" break print(ans)
insert
5
5
5
6
TypeError: not all arguments converted during string formatting
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02772/Python/s507255714.py", line 6, in <module> if moji % 2 != 0: TypeError: not all arguments converted during string formatting
p02772
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } vector<int> b; for (int i = 0; i < N; i++) { if (a.at(i) % 2 == 0) { b.push_back(a.at(i)); } } for (int i = 0; i < N; i++) { if (b.at(i) % 3 != 0 && b.at(i) % 5 != 0) { cout << "DENIED" << endl; return 0; } } cout << "APPROVED" << endl; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } vector<int> b; for (int i = 0; i < N; i++) { if (a.at(i) % 2 == 0) { b.push_back(a.at(i)); } } for (int i = 0; i < b.size(); i++) { if (b.at(i) % 3 != 0 && b.at(i) % 5 != 0) { cout << "DENIED" << endl; return 0; } } cout << "APPROVED" << endl; return 0; }
replace
18
19
18
19
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02772
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define ull unsigned long long int // ranges from (0 - twice of long long int) #define rep(i, a, n) for (ll i = a; i < n; i++) #define per(i, a, n) for (ll i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define vll vector<ll> #define mod 1000000007LL #define llpair pair<ll, ll> #define INF 1000000000000000000ll #define np next_permutation // ALWAYS USE ll DATA TYPE FOR INTEGER(FASTER THAN INTEGER AS WELL AS SOMETIMES // WITHOUT USE LONG UR ANSWER WILL NOT ACCEPTED) && DOUBLE FOR DECIMAL VALUE template <typename T> // for removing front element from the vector void pop_front(std::vector<T> &v) { if (v.size() > 0) { v.erase(v.begin()); } } template < typename R> // for removing back element from the vector or can directly void pop_back(std::vector<R> &v) // use vec.pop_back() function... { if (v.size() > 0) { v.erase(v.begin() + v.size() - 1); } } bool isprime(ll n) // IN O(sqrt(n)) { if (n <= 1) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } vector<ll> factors(ll n) { // IN O(sqrt(n)) vll v; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { v.pb(i); if ((n / i) != i) v.pb(n / i); } } return v; } ll power(ll a, ll n) // using Binary Exponential in TC O(logn) { // Self Written By </ME> :) ll res = 1; while (1) { if (n % 2) { res = res * a; n--; } if (n == 0) break; a = a * a; n /= 2; } return res; } int main() { fio; #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif ll t = 1; // cin>>t; while (t--) { ll n; cin >> n; ll arr[n]; rep(i, 0, n) cin >> arr[i]; int flag = 1; rep(i, 0, n) { if (arr[i] % 2 == 0) { if (arr[i] % 3 != 0 && arr[i] % 5 != 0) { flag = 0; break; } } } if (flag == 0) cout << "DENIED" << "\n"; else cout << "APPROVED" << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define ull unsigned long long int // ranges from (0 - twice of long long int) #define rep(i, a, n) for (ll i = a; i < n; i++) #define per(i, a, n) for (ll i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define vll vector<ll> #define mod 1000000007LL #define llpair pair<ll, ll> #define INF 1000000000000000000ll #define np next_permutation // ALWAYS USE ll DATA TYPE FOR INTEGER(FASTER THAN INTEGER AS WELL AS SOMETIMES // WITHOUT USE LONG UR ANSWER WILL NOT ACCEPTED) && DOUBLE FOR DECIMAL VALUE template <typename T> // for removing front element from the vector void pop_front(std::vector<T> &v) { if (v.size() > 0) { v.erase(v.begin()); } } template < typename R> // for removing back element from the vector or can directly void pop_back(std::vector<R> &v) // use vec.pop_back() function... { if (v.size() > 0) { v.erase(v.begin() + v.size() - 1); } } bool isprime(ll n) // IN O(sqrt(n)) { if (n <= 1) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } vector<ll> factors(ll n) { // IN O(sqrt(n)) vll v; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { v.pb(i); if ((n / i) != i) v.pb(n / i); } } return v; } ll power(ll a, ll n) // using Binary Exponential in TC O(logn) { // Self Written By </ME> :) ll res = 1; while (1) { if (n % 2) { res = res * a; n--; } if (n == 0) break; a = a * a; n /= 2; } return res; } int main() { fio; ll t = 1; // cin>>t; while (t--) { ll n; cin >> n; ll arr[n]; rep(i, 0, n) cin >> arr[i]; int flag = 1; rep(i, 0, n) { if (arr[i] % 2 == 0) { if (arr[i] % 3 != 0 && arr[i] % 5 != 0) { flag = 0; break; } } } if (flag == 0) cout << "DENIED" << "\n"; else cout << "APPROVED" << "\n"; } return 0; }
delete
79
85
79
79
-11
p02772
C++
Runtime Error
#include "bits/stdc++.h" #define lim 1000000007 #define MAX 10001 #define uomap unordered_map #define uoset unordered_set #define pb push_back #define vec vector #define mkp make_pair #define fir first #define sec second #define LOG(fmt, args...) fprintf(stdout, fmt, ##args); using namespace std; typedef long long int ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; const ld pi = 4.0 * atanl(1.0); const int iinf = 1e9 + 10; const ll inf = 1e18 + 10; using namespace std; static int max_points = 200; ll dis(ll a, ll b, ll c, ll d) { return abs(a - c) + abs(b - d); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; bool flag = false; for (int i = 0; i < n; i++) { ll temp; cin >> temp; if (temp % 2 == 0 && temp % 3 != 0 && temp % 5 != 0) { flag = true; } } if (flag) { cout << "DENIED" << endl; } else { cout << "APPROVED" << endl; } return 0; } /* * akina.cpp * Copyright 2019 Karan Kanojia <karankanojia@Karans-MacBook-Air.local> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */
#include "bits/stdc++.h" #define lim 1000000007 #define MAX 10001 #define uomap unordered_map #define uoset unordered_set #define pb push_back #define vec vector #define mkp make_pair #define fir first #define sec second #define LOG(fmt, args...) fprintf(stdout, fmt, ##args); using namespace std; typedef long long int ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; const ld pi = 4.0 * atanl(1.0); const int iinf = 1e9 + 10; const ll inf = 1e18 + 10; using namespace std; static int max_points = 200; ll dis(ll a, ll b, ll c, ll d) { return abs(a - c) + abs(b - d); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; bool flag = false; for (int i = 0; i < n; i++) { ll temp; cin >> temp; if (temp % 2 == 0 && temp % 3 != 0 && temp % 5 != 0) { flag = true; } } if (flag) { cout << "DENIED" << endl; } else { cout << "APPROVED" << endl; } return 0; } /* * akina.cpp * Copyright 2019 Karan Kanojia <karankanojia@Karans-MacBook-Air.local> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */
delete
25
29
25
25
TLE
p02772
C++
Runtime Error
#include <bits/stdc++.h> #define N 5000005 #define sag (root + root + 1) #define sol (root + root) #define ort ((bas + son) / 2) #define mod 1000000007 using namespace std; typedef long long ll; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { if (arr[i] % 2 == 0) { if (!(arr[i] % 3 == 0 or arr[i] % 5 == 0)) { cout << "DENIED" << endl; cout << arr[i]; exit(1); } } } cout << "APPROVED"; return 0; }
#include <bits/stdc++.h> #define N 5000005 #define sag (root + root + 1) #define sol (root + root) #define ort ((bas + son) / 2) #define mod 1000000007 using namespace std; typedef long long ll; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { if (arr[i] % 2 == 0) { if (!(arr[i] % 3 == 0 or arr[i] % 5 == 0)) { cout << "DENIED" << endl; // cout << arr[i]; return 0; } } } cout << "APPROVED"; return 0; }
replace
20
22
20
22
0
p02772
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> a(n); cin >> n; for (int i = 0; i < n; i++) { cin >> a.at(i); } int c = 0; for (int i = 0; i < n; i++) { if (a.at(i) % 2 == 0) { if (a.at(i) % 3 == 0 || a.at(i) % 5 == 0) { c++; } } else { c++; } } if (c == n) cout << "APPROVED" << endl; else cout << "DENIED" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> a(100); cin >> n; for (int i = 0; i < n; i++) { cin >> a.at(i); } int c = 0; for (int i = 0; i < n; i++) { if (a.at(i) % 2 == 0) { if (a.at(i) % 3 == 0 || a.at(i) % 5 == 0) { c++; } } else { c++; } } if (c == n) cout << "APPROVED" << endl; else cout << "DENIED" << endl; }
replace
5
6
5
6
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p02772
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main(void) { int n; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 == 0 && !(a[i] % 3 == 0 || a[i] % 5 == 0)) { cout << "DENIED" << endl; return 0; } } cout << "APPROVED" << endl; }
#include <iostream> #include <vector> using namespace std; int main(void) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 == 0 && !(a[i] % 3 == 0 || a[i] % 5 == 0)) { cout << "DENIED" << endl; return 0; } } cout << "APPROVED" << endl; }
replace
6
7
6
7
-11
p02772
C++
Runtime Error
#include <bits/stdc++.h> // #include<boost/multiprecision/cpp_int.hpp> #define fl(i, a, n) for (int i = a; i <= n; i++) #define pb push_back #define pob pop_back #define int long long int #define ff first #define ss second #define pi 3.1415926535898 #define vi vector<int> #define mi map<int, int> #define umi unordered_map<int, int> #define endl "\n" #define w(x) \ int x; \ cin >> x; \ while (x--) #define db(x) cout << (#x) << " " << (x) << "\n"; #define ios \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; // using namespace boost::multiprecision; int mod = 1000000007; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } int lcm(int a, int b) { return (a * b) / gcd(a, b); } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { ios c_p_c(); // w(t) { int n; cin >> n; fl(i, 0, n - 1) { int d; cin >> d; if (d % 2 == 0) { if (d % 3 == 0 or d % 5 == 0) { continue; } else { cout << "DENIED\n"; return 0; } } } cout << "APPROVED\n"; } return 0; }
#include <bits/stdc++.h> // #include<boost/multiprecision/cpp_int.hpp> #define fl(i, a, n) for (int i = a; i <= n; i++) #define pb push_back #define pob pop_back #define int long long int #define ff first #define ss second #define pi 3.1415926535898 #define vi vector<int> #define mi map<int, int> #define umi unordered_map<int, int> #define endl "\n" #define w(x) \ int x; \ cin >> x; \ while (x--) #define db(x) cout << (#x) << " " << (x) << "\n"; #define ios \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; // using namespace boost::multiprecision; int mod = 1000000007; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } int lcm(int a, int b) { return (a * b) / gcd(a, b); } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { ios // c_p_c(); // w(t) { int n; cin >> n; fl(i, 0, n - 1) { int d; cin >> d; if (d % 2 == 0) { if (d % 3 == 0 or d % 5 == 0) { continue; } else { cout << "DENIED\n"; return 0; } } } cout << "APPROVED\n"; } return 0; }
replace
38
39
38
40
0
p02772
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define It set<node>::iterator #define endl '\n' #define fastio \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; typedef long long ll; typedef pair<int, int> pii; int n; int arr[1000]; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> arr[i]; for (int i = 1; i <= n; ++i) { if (arr[i] % 2 == 0) { if (arr[i] % 3 != 0 && arr[i] % 5 != 0) return puts("DENIED"); } } puts("APPROVED"); return 0; }
#include <bits/stdc++.h> #define pb push_back #define It set<node>::iterator #define endl '\n' #define fastio \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; typedef long long ll; typedef pair<int, int> pii; int n; int arr[1000]; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> arr[i]; for (int i = 1; i <= n; ++i) { if (arr[i] % 2 == 0) { if (arr[i] % 3 != 0 && arr[i] % 5 != 0) return puts("DENIED"), 0; } } puts("APPROVED"); return 0; }
replace
22
23
22
23
0
p02772
C++
Runtime Error
#include <bits/stdc++.h> #include <iomanip> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> vec{n}; for (int i = 0; i < n; i++) { cin >> vec.at(i); } bool H = 1; for (int i = 0; i < n; i++) { if (vec.at(i) % 2 == 0) { if (vec.at(i) % 3 == 0 || vec.at(i) % 5 == 0) { H = 1; } else { H = 0; break; } } } if (H) { cout << "APPROVED" << endl; } else { cout << "DENIED" << endl; } }
#include <bits/stdc++.h> #include <iomanip> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec.at(i); } bool H = 1; for (int i = 0; i < n; i++) { if (vec.at(i) % 2 == 0) { if (vec.at(i) % 3 == 0 || vec.at(i) % 5 == 0) { H = 1; } else { H = 0; break; } } } if (H) { cout << "APPROVED" << endl; } else { cout << "DENIED" << endl; } }
replace
8
9
8
9
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 1) >= this->size() (which is 1)
p02772
C++
Runtime Error
#include <stdio.h> #include <stdlib.h> #include <fstream> #include <iomanip> #include <iostream> #include <sstream> #include <stdint.h> #include <string.h> // #define _USE_MATH_DEFINES // #include <math.h> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <algorithm> #include <bitset> #include <chrono> #include <functional> #include <random> #define sqr(x) (x) * (x) typedef unsigned int u32; typedef int i32; typedef unsigned long long int u64; typedef int i64; typedef uint16_t u16; typedef int16_t i16; typedef uint8_t u8; typedef int8_t i8; using namespace std; using namespace std::chrono; const i64 mod = 1000000007ll; const i64 smod = 998244353ll; const i64 inf = 1000000007; // 10000000000000007ll; const double eps = 1e-8; const i64 MAXN = 52; const i64 MAXM = 20004; i64 n; i64 a[MAXN]; int main(int argc, char *argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cin >> n; for (i64 i = 0; i < n; i++) { cin >> a[i]; } for (i64 i = 0; i < n; i++) { if (a[i] % 2 == 0) { if (a[i] % 3 != 0 && a[i] % 5 != 0) { cout << "DENIED" << endl; return 0; } } } cout << "APPROVED" << endl; return 0; }
#include <stdio.h> #include <stdlib.h> #include <fstream> #include <iomanip> #include <iostream> #include <sstream> #include <stdint.h> #include <string.h> // #define _USE_MATH_DEFINES // #include <math.h> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <algorithm> #include <bitset> #include <chrono> #include <functional> #include <random> #define sqr(x) (x) * (x) typedef unsigned int u32; typedef int i32; typedef unsigned long long int u64; typedef int i64; typedef uint16_t u16; typedef int16_t i16; typedef uint8_t u8; typedef int8_t i8; using namespace std; using namespace std::chrono; const i64 mod = 1000000007ll; const i64 smod = 998244353ll; const i64 inf = 1000000007; // 10000000000000007ll; const double eps = 1e-8; const i64 MAXN = 52; const i64 MAXM = 20004; i64 n; i64 a[MAXN]; int main(int argc, char *argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cin >> n; for (i64 i = 0; i < n; i++) { i64 t; cin >> t; if (t % 2 == 0) { if (t % 3 != 0 && t % 5 != 0) { cout << "DENIED" << endl; return 0; } } } cout << "APPROVED" << endl; return 0; }
replace
64
70
64
68
0
p02772
C++
Runtime Error
#include <bits/stdc++.h> #define all(vec) vec.begin(), vec.end() #define rall(vec) vec.rbegin(), vec.rend() #define sz(r) r.size() #define rem1(v, i) (v.erase(v.begin() + i)) #define rem2(v, i, j) (v.erase(v.begin() + i, v.begin() + j + 1)) #define rev(v, i, j) (reverse(v.begin() + i, v.begin() + j + 1)) #define digits(i) (int)((log(i) / log(10)) + 1) #define dround(num) \ (int)floor(num + 0.5) // Rounds num to int (int)num+(<.5 to 0, > .5 to 1) #define first_bit_index(num) __builtin_ctz(num) // count trailing zeros #define last_bit_index(num) __builtin_clz(num) // count leading zeros #define UNDEFINED_BIT 32 #define test_bit(num, bit) ((num & 1 << bit) != 0) #define num_bits(num) __builtin_popcount(num) #define pb push_back #define pf push_front #define ins insert #define inf INT_MAX #define mn_inf INT_MIN #define endl '\n' using namespace std; #define init \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); typedef long long ll; int main() { init #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { int x; cin >> x; if (x % 2 == 0 && (x % 3 != 0 && x % 5 != 0)) { cout << "DENIED" << "\n"; return 0; } } cout << "APPROVED" << "\n"; return 0; }
#include <bits/stdc++.h> #define all(vec) vec.begin(), vec.end() #define rall(vec) vec.rbegin(), vec.rend() #define sz(r) r.size() #define rem1(v, i) (v.erase(v.begin() + i)) #define rem2(v, i, j) (v.erase(v.begin() + i, v.begin() + j + 1)) #define rev(v, i, j) (reverse(v.begin() + i, v.begin() + j + 1)) #define digits(i) (int)((log(i) / log(10)) + 1) #define dround(num) \ (int)floor(num + 0.5) // Rounds num to int (int)num+(<.5 to 0, > .5 to 1) #define first_bit_index(num) __builtin_ctz(num) // count trailing zeros #define last_bit_index(num) __builtin_clz(num) // count leading zeros #define UNDEFINED_BIT 32 #define test_bit(num, bit) ((num & 1 << bit) != 0) #define num_bits(num) __builtin_popcount(num) #define pb push_back #define pf push_front #define ins insert #define inf INT_MAX #define mn_inf INT_MIN #define endl '\n' using namespace std; #define init \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); typedef long long ll; int main() { init // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // // freopen("output.txt", "w", stdout); // #endif int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { int x; cin >> x; if (x % 2 == 0 && (x % 3 != 0 && x % 5 != 0)) { cout << "DENIED" << "\n"; return 0; } } cout << "APPROVED" << "\n"; return 0; }
replace
31
36
31
36
0
p02772
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, a[n], i, flag = 0; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (a[i] % 2 == 0) { if (a[i] % 3 != 0 && a[i] % 5 != 0) { flag = 1; break; } } } if (flag == 0) cout << "APPROVED"; else cout << "DENIED"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, a[n], i, flag = 0; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (a[i] % 2 == 0) { if (a[i] % 3 != 0 && a[i] % 5 != 0) { flag = 1; break; } } } if (flag == 0) cout << "APPROVED"; else cout << "DENIED"; return 0; }
replace
3
4
3
4
0
p02772
C++
Runtime Error
#include <bits/stdc++.h> #define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__) #define itn int #define gI gi using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<int, PII> PIII; inline int gi() { int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } inline LL gl() { LL f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } int n, m, x, y, z, a[5]; int main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); cin >> n; for (int i = 1; i <= n; i += 1) cin >> a[i]; bool fl = true; for (int i = 1; i <= n; i += 1) if (a[i] % 2 == 0) { if (a[i] % 3 != 0 && a[i] % 5 != 0) fl = false; } if (fl) puts("APPROVED"); else puts("DENIED"); return 0; }
#include <bits/stdc++.h> #define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__) #define itn int #define gI gi using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<int, PII> PIII; inline int gi() { int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } inline LL gl() { LL f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } int n, m, x, y, z, a[303]; int main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); cin >> n; for (int i = 1; i <= n; i += 1) cin >> a[i]; bool fl = true; for (int i = 1; i <= n; i += 1) if (a[i] % 2 == 0) { if (a[i] % 3 != 0 && a[i] % 5 != 0) fl = false; } if (fl) puts("APPROVED"); else puts("DENIED"); return 0; }
replace
37
38
37
38
0
p02772
C++
Runtime Error
/* *********************************************** Author :taciturnity Created Time :2020/2/3 22:02:32 File Name :main.cpp ************************************************ */ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> #define ll long long #define INF 1e9 #define bug puts("--------------") const ll N = 2e5 + 10; const ll mod = 1e9 + 7; const int Max_n = 1e6 + 10; using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int a; cin >> a; if ((a & 1)) continue; if (a % 3 == 0 || a % 5 == 0) { } else return puts("DENIED"); } puts("APPROVED"); }
/* *********************************************** Author :taciturnity Created Time :2020/2/3 22:02:32 File Name :main.cpp ************************************************ */ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> #define ll long long #define INF 1e9 #define bug puts("--------------") const ll N = 2e5 + 10; const ll mod = 1e9 + 7; const int Max_n = 1e6 + 10; using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int a; cin >> a; if ((a & 1)) continue; if (a % 3 == 0 || a % 5 == 0) { } else return puts("DENIED"), 0; } puts("APPROVED"); }
replace
35
36
35
36
0
p02772
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int i = 0; i < N; i++) { if (A.at(i) % 2 != 0) A.at(i) = 1; else { if (A.at(i) % 3 == 0 || A.at(i) % 5 == 0) A.at(i) = 1; else A.at(i) = 0; } } int ans = 1; for (int i = 0; i < N; i++) { ans *= A.at(1); } if (ans == 1) cout << "APPROVED" << endl; else cout << "DENIED" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int i = 0; i < N; i++) { if (A.at(i) % 2 != 0) A.at(i) = 1; else { if (A.at(i) % 3 == 0 || A.at(i) % 5 == 0) A.at(i) = 1; else A.at(i) = 0; } } int ans = 1; for (int i = 0; i < N; i++) { // cout << "A.at(" << i << ")" << A.at(i) << ", "; ans *= A.at(i); // cout << "ans(" << i << ")" << ans << ", "; } if (ans == 1) cout << "APPROVED" << endl; else cout << "DENIED" << endl; }
replace
27
28
27
30
0