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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02989 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v;
int n;
int m;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> m;
v.push_back(m);
}
int up = 0;
int down = 0;
int c = 0;
for (int i = 1; i < v[distance(v.begin(), max_element(v.begin(), v.end()))];
i++) {
for (int j = 0; j < n; j++) {
if (v[j] <= i) {
up++;
} else {
down++;
}
}
if (up == down) {
c++;
}
up = 0;
down = 0;
}
cout << c << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v;
int n;
int m;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> m;
v.push_back(m);
}
sort(v.begin(), v.end());
int s = n / 2;
cout << v[s] - v[s - 1] << endl;
return 0;
}
| replace | 15 | 34 | 15 | 21 | TLE | |
p02989 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repll(i, n) for (long long int i = 0; i < n; i++)
#define fin(ans) cout << (ans) << endl
#define P 1000000007
#define STI(s) atoi(s.c_str()) // string to int
#define mp(p, q) make_pair(p, q)
#define Sort(a) sort(a.begin(), a.end())
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;
}
const int INF = INT_MAX;
const long long LLINF = 1LL << 60;
template <typename T_char> char ToUpper(char cX) { return toupper(cX); }
// g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a) {
ll count = 0;
for (ll i = 0; i < a; i++) {
if (a == 0) {
break;
} else {
a = a / 10;
count++;
}
}
return count;
}
#include <cstdint>
uintmax_t comb(unsigned int n, unsigned int r) {
if (r * 2 > n)
r = n - r;
uintmax_t dividend = 1;
uintmax_t divisor = 1;
for (unsigned int i = 1; i <= r; ++i) {
dividend *= (n - i + 1);
divisor *= i;
}
return dividend / divisor;
}
// 桁数のカウント
// pow(x,n) == x^n
// sum = accumulate(v.begin(),v.end(),0);
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 main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
/////////////////////////////////////////////////////
ll n, count = 0;
cin >> n;
vi d(n);
rep(i, n) cin >> d[i];
Sort(d);
for (int k = d[0]; k <= d[n - 1]; k++) {
ll arc = 0, abc = 0;
rep(i, n) {
if (d[i] >= k)
arc++;
else
abc++;
}
if (arc == abc)
count++;
}
cout << count << endl;
//////////////////////////////////////////////////////
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repll(i, n) for (long long int i = 0; i < n; i++)
#define fin(ans) cout << (ans) << endl
#define P 1000000007
#define STI(s) atoi(s.c_str()) // string to int
#define mp(p, q) make_pair(p, q)
#define Sort(a) sort(a.begin(), a.end())
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;
}
const int INF = INT_MAX;
const long long LLINF = 1LL << 60;
template <typename T_char> char ToUpper(char cX) { return toupper(cX); }
// g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a) {
ll count = 0;
for (ll i = 0; i < a; i++) {
if (a == 0) {
break;
} else {
a = a / 10;
count++;
}
}
return count;
}
#include <cstdint>
uintmax_t comb(unsigned int n, unsigned int r) {
if (r * 2 > n)
r = n - r;
uintmax_t dividend = 1;
uintmax_t divisor = 1;
for (unsigned int i = 1; i <= r; ++i) {
dividend *= (n - i + 1);
divisor *= i;
}
return dividend / divisor;
}
// 桁数のカウント
// pow(x,n) == x^n
// sum = accumulate(v.begin(),v.end(),0);
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 main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
/////////////////////////////////////////////////////
ll n, count = 0;
cin >> n;
vi d(n);
rep(i, n) cin >> d[i];
Sort(d);
cout << d[n / 2] - d[n / 2 - 1] << endl;
//////////////////////////////////////////////////////
return 0;
}
| replace | 96 | 108 | 96 | 98 | TLE | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a;
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
sort(a.begin(), a.end());
cout << a.at(n / 2) - a.at(n / 2 - 1) << 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);
}
sort(a.begin(), a.end());
cout << a.at(n / 2) - a.at(n / 2 - 1) << endl;
} | replace | 6 | 7 | 6 | 7 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, p[25], ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
sort(p, p + n);
ans = p[n / 2] - p[(n / 2) - 1];
if (ans <= 0) {
ans = 0;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int n, p[500000], ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
sort(p, p + n);
ans = p[n / 2] - p[(n / 2) - 1];
if (ans <= 0) {
ans = 0;
}
cout << ans << endl;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) \
for (int i = 0; i < n; i++) \
;
using ll = long long;
int main() {
int N;
cin >> N;
int a = N / 2;
vector<int> d(N);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
int s = 0;
int answer = 0;
for (int i = d.at(a - 1) + 1; i <= d.at(a); i++) {
if (s != d.at(i)) {
answer++;
s = i;
}
}
cout << answer << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) \
for (int i = 0; i < n; i++) \
;
using ll = long long;
int main() {
int N;
cin >> N;
int a = N / 2;
vector<int> d(N);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
int s = 0;
int answer = 0;
for (int i = d.at(a - 1) + 1; i <= d.at(a); i++) {
if (s != i) {
answer++;
s = i;
}
}
cout << answer << endl;
}
| 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 6) >= this->size() (which is 6)
|
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
cout << d.at(n / 2 + 1) - d.at(n / 2) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
cout << d.at(n / 2) - d.at((n / 2) - 1) << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02989 | C++ | Runtime Error | #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define pb push_back
#define mp make_pair
#define test \
int t; \
cin >> t; \
while (t--)
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pii;
typedef unordered_map<int, int> mp;
const int mod = 1e9 + 7;
const int inf = 1e18;
int32_t main() {
FAST;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
if (n & 1) {
cout << 0 << endl;
return 0;
}
int a[n];
for (int x = 0; x < n; x++) {
cin >> a[x];
}
sort(a, a + n);
int se = a[n / 2], fi = a[n / 2 - 1];
cout << (se - fi) << '\n';
return 0;
}
| #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define pb push_back
#define mp make_pair
#define test \
int t; \
cin >> t; \
while (t--)
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pii;
typedef unordered_map<int, int> mp;
const int mod = 1e9 + 7;
const int inf = 1e18;
int32_t main() {
FAST;
int n;
cin >> n;
if (n & 1) {
cout << 0 << endl;
return 0;
}
int a[n];
for (int x = 0; x < n; x++) {
cin >> a[x];
}
sort(a, a + n);
int se = a[n / 2], fi = a[n / 2 - 1];
cout << (se - fi) << '\n';
return 0;
}
| delete | 34 | 39 | 34 | 34 | -11 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define TEST_CASES
using ll = long long;
#define ff first
#define ss second
const int N = 1e5 + 10;
int n;
int a[N];
void solve() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int p = 0;
int ans = 0;
for (int i = 0; i < N; i++) {
while (a[p] < i)
p++;
if (n - p == p)
ans++;
if (p > n - p)
break;
}
cout << ans << endl;
}
int main() {
int t = 1;
#ifdef TEST_CASES
cin >> t;
#endif
while (t--) {
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
// #define TEST_CASES
using ll = long long;
#define ff first
#define ss second
const int N = 1e5 + 10;
int n;
int a[N];
void solve() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int p = 0;
int ans = 0;
for (int i = 0; p < n and i < N; i++) {
while (p < n and a[p] < i)
p++;
if (n - p == p)
ans++;
if (p > n - p)
break;
}
cout << ans << endl;
}
int main() {
int t = 1;
#ifdef TEST_CASES
cin >> t;
#endif
while (t--) {
solve();
}
}
| replace | 19 | 21 | 19 | 21 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
ll n, a[50000] = {};
cin >> n;
rep(i, n) { cin >> a[i]; }
sort(a, a + n);
n /= 2;
cout << (a[n] - a[n - 1]) << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
ll n, a[100000] = {};
cin >> n;
rep(i, n) { cin >> a[i]; }
sort(a, a + n);
n /= 2;
cout << (a[n] - a[n - 1]) << "\n";
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
#include <algorithm>
int main() {
int N;
cin >> N;
int d[N];
for (int i = 0; i < N; ++i) {
cin >> d[i];
}
sort(d, d + N);
int res = 0;
int num_ARC = 0;
int num_ABC = 0;
int K_max = d[N - 1];
for (int i = 0; i < K_max; ++i) {
for (int j = 0; j < N; ++j) {
if (i >= d[j]) {
++num_ARC;
} else {
++num_ABC;
}
if (num_ARC + num_ABC == N) {
if (num_ARC == num_ABC) {
++res;
num_ARC = 0;
num_ABC = 0;
continue;
} else {
num_ARC = 0;
num_ABC = 0;
continue;
}
}
}
}
cout << res;
} | #include <iostream>
using namespace std;
#include <algorithm>
int main() {
int N;
cin >> N;
int d[N];
for (int i = 0; i < N; ++i) {
cin >> d[i];
}
sort(d, d + N);
int res = 0;
int num_ABC = d[N / 2 - 1];
int num_ARC = d[N / 2];
res = num_ARC - num_ABC;
cout << res;
} | replace | 14 | 38 | 14 | 17 | TLE | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
vector<int> d(N);
int D = 0;
for (int i = 0; i < N; i++)
cin >> d[i];
sort(d.begin(), d.end());
int ans;
int diff = d[N / 2] - d[N / 2 - 1];
if (diff == 0)
ans = 0;
else
ans = diff;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
int D = 0;
for (int i = 0; i < N; i++)
cin >> d[i];
sort(d.begin(), d.end());
int ans;
int diff = d[N / 2] - d[N / 2 - 1];
if (diff == 0)
ans = 0;
else
ans = diff;
cout << ans << endl;
return 0;
} | insert | 12 | 12 | 12 | 13 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, i, ans = 0;
cin >> N;
bool a = true;
vector<int> d(N);
for (i = 0; i < N; i++) {
cin >> d[i];
}
sort(d.begin(), d.end());
for (int K = d.at(0); K < d[N / 2] + 1; K++) {
i = 0;
while (d[i] < K) {
i++;
if (i > N / 2) {
a = false;
break;
}
}
if (i == N / 2)
ans++;
if (!a)
break;
}
cout << ans;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, i, ans = 0;
cin >> N;
bool a = true;
vector<int> d(N);
for (i = 0; i < N; i++) {
cin >> d[i];
}
sort(d.begin(), d.end());
if (d.at(N / 2 - 1) != d.at(N / 2))
ans = d.at(N / 2) - d.at(N / 2 - 1);
cout << ans;
} | replace | 18 | 32 | 18 | 20 | TLE | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
int k = 0;
for (int i = d.at(n / 2); i <= d.at(i + 1); i++)
k++;
cout << k << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
} | replace | 12 | 18 | 12 | 13 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 7) >= this->size() (which is 6)
|
p02989 | C++ | Time Limit Exceeded | #include <stdio.h>
int main(void) {
long long int n, i, j;
scanf("%lld", &n);
long long int d[n];
for (i = 0; i < n; i++) {
scanf("%lld", &d[i]);
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (d[i] > d[j]) {
long long int tmp = d[i];
d[i] = d[j];
d[j] = tmp;
}
}
}
printf("%lld", d[n / 2] - d[n / 2 - 1]);
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
cout << a[n / 2] - a[n / 2 - 1];
} | replace | 0 | 18 | 0 | 10 | TLE | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, d[10001], ans;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> d[i];
}
sort(d, d + N);
ans = d[N / 2] - d[N / 2 - 1];
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, d[100000], ans;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> d[i];
}
sort(d, d + N);
ans = d[N / 2] - d[N / 2 - 1];
cout << ans << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
int mid_1st = d.at(0.5 * N - 1);
int mid_2nd = d.at(0.5 * N);
int res = 0;
if (mid_1st != mid_2nd) {
res = mid_2nd - mid_1st;
if (mid_2nd == d.at(0.5 * N + 1)) {
res -= 1;
}
}
cout << res << endl;
}
| #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
int mid_1st = d.at(0.5 * N - 1);
int mid_2nd = d.at(0.5 * N);
int res = 0;
if (mid_1st != mid_2nd) {
res = mid_2nd - mid_1st;
}
cout << res << endl;
}
| delete | 22 | 25 | 22 | 22 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
int ans = 0;
for (int i = 0; i < d.size(); i++) {
cin >> d.at(i);
}
for (int K = 0; K <= 100000; K++) {
int sumR = 0;
int sumB = 0;
for (int i = 0; i < d.size(); i++) {
if (d.at(i) >= K) {
sumR++;
} else {
sumB++;
}
}
if (sumR == sumB) {
ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
int ans = 0;
for (int i = 0; i < d.size(); i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
cout << d.at(N / 2) - d.at(N / 2 - 1) << endl;
} | replace | 11 | 27 | 11 | 13 | TLE | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, d[20];
cin >> N;
for (int i = 0; i < N; ++i)
cin >> d[i];
sort(d, d + N);
cout << d[N / 2] - d[N / 2 - 1] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, d[100000], count = 0;
cin >> N;
for (int i = 0; i < N; ++i)
cin >> d[i];
sort(d, d + N);
cout << d[N / 2] - d[N / 2 - 1] << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
int ans = 0;
for (int i = 0; i < N; i++) {
cin >> d[i];
}
sort(d.begin(), d.end());
for (int i = d[N / 2] - 1; i <= d[i]; i++) {
ans++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
int ans = 0;
for (int i = 0; i < N; i++) {
cin >> d[i];
}
sort(d.begin(), d.end());
for (int i = d[(N / 2) - 1] + 1; i <= d[N / 2]; i++) {
ans++;
}
cout << ans << endl;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02989 | 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;
using P = pair<int, int>;
int main() {
int n, ans = 0;
cin >> n;
vector<int> d(n);
rep(i, n) cin >> d[i];
sort(d.begin(), d.end());
rep(i, 100000) {
int cnt = 0;
rep(j, n) {
if (i < d[j])
cnt++;
else if (cnt > n / 2)
break;
}
if (cnt == n / 2)
ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, ans = 0;
cin >> n;
vector<int> d(n);
rep(i, n) cin >> d[i];
sort(d.begin(), d.end());
cout << d[n / 2] - d[n / 2 - 1] << endl;
return 0;
}
| replace | 12 | 24 | 12 | 13 | TLE | |
p02989 | 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);
}
sort(a.begin(), a.end());
int med = n / 2;
int ans = a.at(med + 1) - a.at(med);
cout << ans << 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);
}
sort(a.begin(), a.end());
int med = n / 2;
int ans = a.at(med) - a.at(med - 1);
cout << ans << endl;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
long n;
int d[100000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (d[i] > d[j]) {
int tmp = d[i];
d[i] = d[j];
d[j] = tmp;
}
}
}
if (d[n / 2] == d[n / 2 - 1]) {
cout << 0 << endl;
} else {
cout << d[n / 2] - d[n / 2 - 1] << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
long n;
int d[100000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
sort(d, d + n);
if (d[n / 2] == d[n / 2 - 1]) {
cout << 0 << endl;
} else {
cout << d[n / 2] - d[n / 2 - 1] << endl;
}
return 0;
} | replace | 13 | 22 | 13 | 14 | TLE | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int cnt = 0, a[10001] = {0}, n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
cout << a[n / 2 + 1] - a[n / 2];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int cnt = 0, a[100001] = {0}, n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
cout << a[n / 2 + 1] - a[n / 2];
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02989 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void swp(int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
}
void quicksort(int a[], int lower, int upper) {
int bound = a[lower], l = lower, u = upper;
do {
while (a[l] < bound)
l++;
while (a[u] > bound)
u--;
if (l <= u) {
swp(a[l], a[u]);
l++;
u--;
}
} while (l < u);
if (lower < u)
quicksort(a, lower, u);
if (l < upper)
quicksort(a, l, upper);
}
int main() {
int p[20], num;
cin >> num;
for (int i = 0; i < num; i++) {
cin >> p[i];
}
quicksort(p, 0, num - 1);
cout << p[num / 2] - p[num / 2 - 1] << endl;
return 0;
} | #include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void swp(int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
}
void quicksort(int a[], int lower, int upper) {
int bound = a[lower], l = lower, u = upper;
do {
while (a[l] < bound)
l++;
while (a[u] > bound)
u--;
if (l <= u) {
swp(a[l], a[u]);
l++;
u--;
}
} while (l < u);
if (lower < u)
quicksort(a, lower, u);
if (l < upper)
quicksort(a, l, upper);
}
int main() {
int p[100000], num;
cin >> num;
for (int i = 0; i < num; i++) {
cin >> p[i];
}
quicksort(p, 0, num - 1);
cout << p[num / 2] - p[num / 2 - 1] << endl;
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
int counter = 0;
for (int K = d.at(0); K <= d.at(N - 1); K++) {
int ARC = 0;
for (int i = 0; i < N; i++) {
if (ARC > N / 2)
break;
if (K <= d.at(i))
ARC++;
}
if (ARC == N / 2)
counter++;
}
cout << counter << endl;
} | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
cout << d.at(N / 2) - d.at((N / 2) - 1) << endl;
} | replace | 14 | 27 | 14 | 15 | TLE | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int d[10000];
cin >> n;
for (int i = 0; i < n; i++)
cin >> d[i];
sort(d, d + n);
cout << d[n / 2] - d[n / 2 - 1] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int d[100000];
cin >> n;
for (int i = 0; i < n; i++)
cin >> d[i];
sort(d, d + n);
cout << d[n / 2] - d[n / 2 - 1] << endl;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
int n, d[10100];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
sort(d, d + n);
cout << d[n / 2] - d[n / 2 - 1] << endl;
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
int n, d[101000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
sort(d, d + n);
cout << d[n / 2] - d[n / 2 - 1] << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(10001);
for (int i = 0; i < n; i++)
cin >> d[i];
sort(d.begin(), d.begin() + n);
cout << d[n / 2] - d[n / 2 - 1] << "\n";
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(100001);
for (int i = 0; i < n; i++)
cin >> d[i];
sort(d.begin(), d.begin() + n);
cout << d[n / 2] - d[n / 2 - 1] << "\n";
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
vector<int> l(n);
for (int i = 0; i < n; i++) {
cin >> d.at(i);
l.at(i) = d.at(i);
}
sort(l.begin(), l.end());
int cnt = 0;
for (int k = l.at(0); k <= l.at(n - 1); k++) {
int ARC = 0;
int ABC = 0;
for (int j = 0; j < n; j++) {
if (d.at(j) >= k) {
ARC++;
} else {
ABC++;
}
}
if (ARC == ABC) {
cnt++;
}
}
cout << cnt << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++)
cin >> d[i];
sort(d.begin(), d.end());
int ans = d[n / 2] - d[n / 2 - 1];
cout << ans << endl;
return 0;
} | replace | 7 | 29 | 7 | 13 | TLE | |
p02989 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
int MIN = 1000040, MAX = -1;
rep(i, n) {
cin >> d[i];
MIN = min(MIN, d[i]);
MAX = max(MAX, d[i]);
}
int cnt = 0;
for (int i = MIN; i <= MAX; i++) {
int arc = 0, abc = 0;
rep(j, n) {
if (d[j] >= i)
arc++;
else
abc++;
}
if (arc == abc)
cnt++;
}
cout << cnt << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
rep(i, n) { cin >> d[i]; }
sort(d.begin(), d.end());
ll right = d[n / 2];
ll left = d[n / 2 - 1];
cout << right - left << endl;
} | replace | 10 | 29 | 10 | 15 | TLE | |
p02989 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, mass, count;
cin >> N;
mass = 0;
count = 0;
vector<int> diff(N);
for (int i = 0; i < N; i++) {
cin >> diff.at(i);
}
for (int K = 1; K < 100001; K++) {
for (int i = 0; i < N; i++) {
if (K >= diff.at(i)) {
mass++;
} else {
mass--;
}
}
if (mass == 0) {
count++;
} else if (mass == N) {
break;
}
mass = 0;
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, mass, count;
cin >> N;
mass = 0;
count = 0;
vector<int> diff(N);
for (int i = 0; i < N; i++) {
cin >> diff.at(i);
}
sort(diff.begin(), diff.end());
count = diff.at(N / 2) - diff.at(N / 2 - 1);
cout << count << endl;
}
| replace | 13 | 28 | 13 | 17 | TLE | |
p02989 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p.at(i);
sort(p.begin(), p.end());
int abc = 0;
int pat = 0;
for (int i = p.at(0); i <= p.at(n - 1); i++) {
for (int j = 0; j < n; j++) {
if (i > p.at(j))
abc++;
else
break;
}
if (abc == n / 2)
pat++;
abc = 0;
}
cout << pat << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p.at(i);
sort(p.begin(), p.end());
int ans = 0;
ans = p.at(n / 2) - p.at(n / 2 - 1);
cout << ans << endl;
} | replace | 10 | 24 | 10 | 14 | TLE | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
int d1 = d.at(n / 2), d2 = d.at((n / 2) + 1), k = d2 - d1;
cout << k << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
int d1 = d.at((n / 2) - 1), d2 = d.at(n / 2), k = d2 - d1;
cout << k << endl;
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define DEBUG 1
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
#endif
int n;
cin >> n;
vi a(n);
for (int &x : a)
cin >> x;
sort(a.begin(), a.end());
if (a[n / 2] == a[n / 2 - 1])
cout << "0\n";
else
cout << a[n / 2] - a[n / 2 - 1] << '\n';
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define DEBUG 1
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(0);
#endif
int n;
cin >> n;
vi a(n);
for (int &x : a)
cin >> x;
sort(a.begin(), a.end());
if (a[n / 2] == a[n / 2 - 1])
cout << "0\n";
else
cout << a[n / 2] - a[n / 2 - 1] << '\n';
return 0;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p02989 | C++ | Time Limit Exceeded | // Divide the Problems
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / __gcd(a, b) * b
#define range(a) (a).begin(), (a).end()
const int inf = 2147483647;
int o = 0;
bool isMin(int d) { return d > o; }
int main() {
int N, Ans = 0;
cin >> N;
vector<int> d(N);
rep(i, 0, N) cin >> d[i];
sort(range(d));
for (o = 0; o < d[N - 1] + 1; o++) {
if (count_if(range(d), isMin) == N / 2)
Ans++;
}
cout << Ans << endl;
return 0;
} | // Divide the Problems
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / __gcd(a, b) * b
#define range(a) (a).begin(), (a).end()
const int inf = 2147483647;
int o = 0;
bool isMin(int d) { return d > o; }
int main() {
int N, Ans = 0;
cin >> N;
vector<int> d(N);
rep(i, 0, N) cin >> d[i];
sort(range(d));
cout << d[N / 2] - d[N / 2 - 1] << endl;
return 0;
} | replace | 21 | 26 | 21 | 22 | TLE | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int a = vec.at(n / 2 - 1);
int b = vec.at(n / 2);
cout << b - a << endl;
} | #include <algorithm>
#include <iostream>
#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);
}
sort(vec.begin(), vec.end());
int a = vec.at(n / 2 - 1);
int b = vec.at(n / 2);
cout << b - a << endl;
} | insert | 7 | 7 | 7 | 8 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[25];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 0;
sort(a, a + n);
cout << a[n / 2] - a[n / 2 - 1] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 0;
sort(a, a + n);
cout << a[n / 2] - a[n / 2 - 1] << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
vector<int> D(N);
for (int i = 0; i < N; i++)
cin >> D.at(i);
sort(D.begin(), D.end());
int ans = D.at(N / 2) - D.at(N / 2 - 1);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> D(N);
for (int i = 0; i < N; i++)
cin >> D.at(i);
sort(D.begin(), D.end());
int ans = D.at(N / 2) - D.at(N / 2 - 1);
cout << ans << endl;
} | insert | 5 | 5 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
vector<int> d(N);
for (int i = 0; i < N; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
int ans = d.at(N / 2) - d.at(N / 2 - 1);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++)
cin >> d.at(i);
sort(d.begin(), d.end());
int ans = d.at(N / 2) - d.at(N / 2 - 1);
cout << ans << endl;
} | insert | 5 | 5 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int b[10000];
int a;
cin >> a;
int x = a / 2;
int y = x - 1;
for (int i = 0; i < a; i++) {
cin >> b[i];
}
sort(b, b + a);
cout << (b[x] - b[y]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int b[100000];
int a;
cin >> a;
int x = a / 2;
int y = x - 1;
for (int i = 0; i < a; i++) {
cin >> b[i];
}
sort(b, b + a);
cout << (b[x] - b[y]);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02989 | C++ | Runtime Error | /*#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
char a=0,b=0;
int aa=0,bb=0;
cin>>s;
for(int i=0;i<4;i++)
if(a==0) a=s[i];
else if(s[i]==a) aa++;
else if(b==0) b=s[i];
else if(s[i]==b) bb++;
else
{
cout<<"No";
return 0;
}
if(aa!=2||bb!=2)
{
cout<<"No";
return 0;
}
cout<<"Yes";
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
int f[10010];
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>f[i];
int ans=0;
for(int i=2;i<=n-1;i++)
if(f[i-1]<f[i]&&f[i]<f[i+1]||f[i+1]<f[i]&&f[i]<f[i-1]) ans++;
cout<<ans<<endl;
}*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int f[10010];
for (int i = 1; i <= n; i++)
cin >> f[i];
sort(f + 1, f + n + 1);
if (n % 2 != 0) {
cout << 0;
return 0;
}
cout << f[n / 2 + 1] - f[n / 2];
} | /*#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
char a=0,b=0;
int aa=0,bb=0;
cin>>s;
for(int i=0;i<4;i++)
if(a==0) a=s[i];
else if(s[i]==a) aa++;
else if(b==0) b=s[i];
else if(s[i]==b) bb++;
else
{
cout<<"No";
return 0;
}
if(aa!=2||bb!=2)
{
cout<<"No";
return 0;
}
cout<<"Yes";
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
int f[10010];
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>f[i];
int ans=0;
for(int i=2;i<=n-1;i++)
if(f[i-1]<f[i]&&f[i]<f[i+1]||f[i+1]<f[i]&&f[i]<f[i-1]) ans++;
cout<<ans<<endl;
}*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int f[800010];
for (int i = 1; i <= n; i++)
cin >> f[i];
sort(f + 1, f + n + 1);
if (n % 2 != 0) {
cout << 0;
return 0;
}
cout << f[n / 2 + 1] - f[n / 2];
} | replace | 43 | 44 | 43 | 44 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
cout << d.at(N / 2 + 1) - d.at(N / 2) + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
cout << d.at(N / 2) - d.at(N / 2 - 1) << endl;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i, s, t) for (int i = s; i < t; ++i)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PP;
vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
int main() {
int n, d[105];
cin >> n;
rep(i, n) cin >> d[i];
sort(d, d + n);
int ans = d[n / 2] - d[n / 2 - 1];
// cout << d[n/2] <<" " <<d[n/2-1] << endl;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i, s, t) for (int i = s; i < t; ++i)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PP;
vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
int main() {
int n, d[100005];
cin >> n;
rep(i, n) cin >> d[i];
sort(d, d + n);
int ans = d[n / 2] - d[n / 2 - 1];
// cout << d[n/2] <<" " <<d[n/2-1] << endl;
cout << ans << endl;
return 0;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02989 | C++ | Runtime Error | /* ****GT_18**** */
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
#define N 100005
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
ll i, j, k, l, m, n, a[100];
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
cout << a[n / 2] - a[n / 2 - 1];
// ll ans=0;
}
return 0;
} | /* ****GT_18**** */
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
using namespace std;
#define N 100005
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
ll i, j, k, l, m, n, a[100400];
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
cout << a[n / 2] - a[n / 2 - 1];
// ll ans=0;
}
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n = 0;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
cout << d.at(n / 2 + 1) - d.at(n / 2) << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n = 0;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define int long long int
using namespace std;
int check(int a[], int n, int num) {
int c1 = 0, c2 = 0;
for (int i = 0; i < n; i++) {
if (a[i] < num)
c1++;
else
c2++;
}
return (c1 == c2);
}
void solve() {
int n;
cin >> n;
int a[n];
int max = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > max)
max = a[i];
}
sort(a, a + n);
int count = 0;
int mid = (a[n / 2]);
for (int i = a[n / 2 - 1]; i <= mid; i++) {
if (check(a, n, i))
count++;
}
cout << count << '\n';
return;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | #include <bits/stdc++.h>
#define int long long int
using namespace std;
int check(int a[], int n, int num) {
int c1 = 0, c2 = 0;
for (int i = 0; i < n; i++) {
if (a[i] < num)
c1++;
else
c2++;
}
return (c1 == c2);
}
void solve() {
int n;
cin >> n;
int a[n];
int max = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > max)
max = a[i];
}
sort(a, a + n);
int count = 0;
cout << a[n / 2] - a[n / 2 - 1] << '\n';
return;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | replace | 25 | 31 | 25 | 26 | TLE | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
cout << d.at(n / 2 + 1) - d.at(n / 2) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++) {
cin >> d.at(i);
}
sort(d.begin(), d.end());
cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#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);
}
sort(vec.begin(), vec.end());
int ans = 0;
for (int i = 0; i < vec.at(N - 1); i++) {
if (vec.at((N - 2) / 2) < i && i <= vec.at((N + 2) / 2)) {
ans++;
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#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);
}
sort(vec.begin(), vec.end());
int ans = 0;
for (int i = 0; i < vec.at(N - 1) + 1; i++) {
if (vec.at((N - 2) / 2) < i && i <= vec.at(N / 2)) {
ans++;
}
}
cout << ans << endl;
return 0;
}
| replace | 16 | 18 | 16 | 18 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
#define FOR(i, start, end) \
for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \
i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for (i64 i = 1; i <= n; ++i)
#define RREP(i, n) for (i64 i = n - 1; i >= 0; --i)
#define RREPS(i, n) for (i64 i = n; i >= 1; --i)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define pb push_back
#define mp make_pair
#define F first
#define S second
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 <typename C> i64 SIZE(const C &c) {
return static_cast<i64>(c.size());
}
template <typename T, size_t N> i64 SIZE(const T (&)[N]) {
return static_cast<i64>(N);
}
struct ProconInit {
static constexpr int IOS_PREC = 15;
static constexpr bool AUTOFLUSH = false;
ProconInit() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH)
cout << unitbuf;
}
} PROCON_INIT;
#define MAX_N 10000
i64 N;
i64 d[MAX_N];
int main() {
cin >> N;
REP(i, N) cin >> d[i];
sort(d, d + N);
i64 cnt = 0;
if (N % 2 == 0) {
cnt = d[N / 2] - d[N / 2 - 1];
} else {
cnt = 0;
}
cout << cnt << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
#define FOR(i, start, end) \
for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \
i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for (i64 i = 1; i <= n; ++i)
#define RREP(i, n) for (i64 i = n - 1; i >= 0; --i)
#define RREPS(i, n) for (i64 i = n; i >= 1; --i)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define pb push_back
#define mp make_pair
#define F first
#define S second
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 <typename C> i64 SIZE(const C &c) {
return static_cast<i64>(c.size());
}
template <typename T, size_t N> i64 SIZE(const T (&)[N]) {
return static_cast<i64>(N);
}
struct ProconInit {
static constexpr int IOS_PREC = 15;
static constexpr bool AUTOFLUSH = false;
ProconInit() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH)
cout << unitbuf;
}
} PROCON_INIT;
#define MAX_N 100000
i64 N;
i64 d[MAX_N];
int main() {
cin >> N;
REP(i, N) cin >> d[i];
sort(d, d + N);
i64 cnt = 0;
if (N % 2 == 0) {
cnt = d[N / 2] - d[N / 2 - 1];
} else {
cnt = 0;
}
cout << cnt << endl;
return 0;
} | replace | 76 | 77 | 76 | 77 | 0 | |
p02989 | C++ | Runtime Error | #pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void) { return; }
template <typename First, typename... Rest>
void ci(First &first, Rest &...rest) {
cin >> first;
ci(rest...);
return;
}
inline void co(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest> void co(First first, Rest... rest) {
cout << first << " ";
co(rest...);
return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n *m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size())
#define each(i, n) for (auto &&i : n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd 最大公約数
int main() {
int N;
ci(N);
ve<int> d(N);
rep(i, N) { ci(d.at(i)); }
so(d);
if (d.at(N / 2) - d.at(N / 2 - 1) == 0) {
co(0);
rt;
} else if (d.at(N / 2) - d.at(N / 2 - 1) != 0) {
if (d.at(N / 2) != d.at(N / 2 + 1) && d.at(N / 2 - 1) != d.at(N / 2 - 2)) {
co(d.at(N / 2) - d.at(N / 2 - 1));
rt;
} else if (d.at(N / 2) == d.at(N / 2 + 1) &&
d.at(N / 2 - 1) == d.at(N / 2 - 2)) {
co(d.at(N / 2) - d.at(N / 2 - 1) - 1);
rt;
} else if (d.at(N / 2) == d.at(N / 2 + 1) ||
d.at(N / 2 - 1) == d.at(N / 2 - 2)) {
co(d.at(N / 2) - d.at(N / 2 - 1));
rt;
}
}
} | #pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void) { return; }
template <typename First, typename... Rest>
void ci(First &first, Rest &...rest) {
cin >> first;
ci(rest...);
return;
}
inline void co(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest> void co(First first, Rest... rest) {
cout << first << " ";
co(rest...);
return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n *m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size())
#define each(i, n) for (auto &&i : n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd 最大公約数
int main() {
int N;
ci(N);
ve<int> d(N);
rep(i, N) { ci(d.at(i)); }
so(d);
co(d.at(N / 2) - d.at(N / 2 - 1));
} | replace | 53 | 70 | 53 | 54 | 0 | |
p02989 | 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;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> d(n);
rep(i, n) cin >> d[i];
sort(d.begin(), d.end());
int cnt = 0;
for (int i = 1; i <= d[n - 1]; i++) {
int l = 0, r = 0;
rep(j, n) {
if (d[j] < i)
l++;
else
r++;
}
if (l == r)
cnt++;
}
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> b(n);
rep(i, n) cin >> b[i];
sort(b.begin(), b.end());
int ans = b[b.size() / 2] - b[b.size() / 2 - 1];
cout << ans << endl;
return 0;
}
| replace | 9 | 25 | 9 | 14 | TLE | |
p02989 | 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);
}
sort(a.begin(), a.end());
cout << a.at(n / 2 + 1) - a.at(n / 2) << 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);
}
sort(a.begin(), a.end());
cout << a.at(n / 2) - a.at(n / 2 - 1) << endl;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02989 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int mid(int a, int b, int c) {
return a + b + c - max(max(a, b), c) - min(min(a, b), c);
}
int main() {
int N;
cin >> N;
vector<int> D(N);
for (int i = 0; i < N; i++) {
cin >> D.at(i);
}
int count = 0;
for (int k = 0; k < 100000; k++) {
int R = 0, C = 0;
for (int j = 0; j < N; j++) {
if (D.at(j) >= k) {
R++;
} else {
C++;
}
}
if (N / 2 == R) {
count++;
}
if (R < C)
break;
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int mid(int a, int b, int c) {
return a + b + c - max(max(a, b), c) - min(min(a, b), c);
}
int main() {
int N;
cin >> N;
vector<int> D(N);
for (int i = 0; i < N; i++) {
cin >> D.at(i);
}
sort(D.begin(), D.end());
cout << D.at(N / 2) - D.at(N / 2 - 1) << endl;
}
| replace | 13 | 30 | 13 | 15 | TLE | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
// C
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
ll i;
ll a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
cout << a[n / 2] - a[(n / 2) - 1];
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
// C
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
ll i;
ll a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
cout << a[n / 2] - a[(n / 2) - 1];
} | delete | 6 | 9 | 6 | 6 | -11 | |
p02989 | C++ | Runtime Error | #include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> ppi;
const int MAX_N = 5e4 + 20, MAX_M = 2e5 + 10, SQRT = 230, inf = 1000000000;
int n, Arr[MAX_N];
int cnt;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> Arr[i];
sort(Arr, Arr + n);
cout << Arr[n / 2] - Arr[n / 2 - 1];
return 0;
} | #include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> ppi;
const int MAX_N = 2e5 + 10, MAX_M = 2e5 + 10, SQRT = 230, inf = 1000000000;
int n, Arr[MAX_N];
int cnt;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> Arr[i];
sort(Arr, Arr + n);
cout << Arr[n / 2] - Arr[n / 2 - 1];
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[21];
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
if (a[n / 2] == a[n / 2 - 1])
cout << 0 << endl;
else
cout << (a[n / 2] - a[n / 2 - 1]) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[200001];
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
if (a[n / 2] == a[n / 2 - 1])
cout << 0 << endl;
else
cout << (a[n / 2] - a[n / 2 - 1]) << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> mp(n, 0);
for (int i = 0; i < n; i++) {
int d;
cin >> d;
mp[d - 1]++;
}
int ans = 0;
long long sum = 0;
for (int i = 0; i < 100000; i++) {
sum += mp[i];
if (n - sum == sum) {
ans++;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> mp(100000, 0);
for (int i = 0; i < n; i++) {
int d;
cin >> d;
mp[d - 1]++;
}
int ans = 0;
long long sum = 0;
for (int i = 0; i < 100000; i++) {
sum += mp[i];
if (n - sum == sum) {
ans++;
}
}
cout << ans << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | -11 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
map<int, int> frec;
for (int i = 0; i < n; i++) {
int elem;
cin >> elem;
frec[elem]++;
}
vector<pii> arr;
for (auto pp : frec)
arr.pb(pp);
int cnt = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
cnt += arr[i].second;
if (n / 2 == cnt) {
ans = arr[i + 1].first - arr[i].first;
}
}
cout << ans << '\n';
return (0);
}
| #include <bits/stdc++.h>
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
map<int, int> frec;
for (int i = 0; i < n; i++) {
int elem;
cin >> elem;
frec[elem]++;
}
vector<pii> arr;
for (auto pp : frec)
arr.pb(pp);
int cnt = 0;
int ans = 0;
for (int i = 0; i < sz(arr); i++) {
cnt += arr[i].second;
if (n / 2 == cnt) {
ans = arr[i + 1].first - arr[i].first;
}
}
cout << ans << '\n';
return (0);
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p02989 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
int mx = 0;
for (int &i : v) {
cin >> i;
mx = max(i, mx);
}
sort(all(v));
int cnt = 0;
for (int i = 1; i <= mx; ++i) {
int x = lower_bound(all(v), i) - v.begin();
if (2 * x == n)
cnt++;
}
cout << cnt << endl;
} | #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
int mx = 0;
for (int &i : v) {
cin >> i;
mx = max(i, mx);
}
sort(all(v));
int cnt = 0;
for (int i = 1; i <= mx; ++i) {
int x = upper_bound(all(v), i) - v.begin();
if (2 * x == n)
cnt++;
}
cout << cnt << endl;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02989 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge {
int to, cost;
};
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;
int modpow(int x, int n) {
if (n == 0)
return 1;
if (n % 2)
return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
return (modpow(x * x % mod, n / 2) + mod) % mod;
}
int fact(int n) {
int ans = 1;
rep(i, n) {
ans *= (i + 1);
ans %= mod;
}
return (ans + mod) % mod;
}
int comb(int n, int r) {
if (n < r)
swap(n, r);
if (n - r < r)
r = n - r;
return (fact(n) * modpow(fact(n - r), mod - 2) % mod *
modpow(fact(r), mod - 2) +
mod) %
mod;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool pri(int p) {
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return p > 1;
}
int n;
int a[22];
int ans;
signed main() {
cin >> n;
rep(i, n) { cin >> a[i]; }
sort(a, a + n);
cout << a[n / 2] - a[n / 2 - 1] << endl;
} | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge {
int to, cost;
};
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;
int modpow(int x, int n) {
if (n == 0)
return 1;
if (n % 2)
return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
return (modpow(x * x % mod, n / 2) + mod) % mod;
}
int fact(int n) {
int ans = 1;
rep(i, n) {
ans *= (i + 1);
ans %= mod;
}
return (ans + mod) % mod;
}
int comb(int n, int r) {
if (n < r)
swap(n, r);
if (n - r < r)
r = n - r;
return (fact(n) * modpow(fact(n - r), mod - 2) % mod *
modpow(fact(r), mod - 2) +
mod) %
mod;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool pri(int p) {
for (int i = 2; i * i <= p; i++)
if (p % i == 0)
return false;
return p > 1;
}
int n;
int a[114514];
int ans;
signed main() {
cin >> n;
rep(i, n) { cin >> a[i]; }
sort(a, a + n);
cout << a[n / 2] - a[n / 2 - 1] << endl;
} | replace | 62 | 63 | 62 | 63 | 0 | |
p02990 | Python | Runtime Error | import math
n, k = map(int, input().split())
mod = 10**9 + 7
def cmb_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1, k + 1):
# print("{0}C{1} * {2}C{3}".format(n - k + 1, i, k-1,i-1))
print(((cmb_count((n - k + 1), i) % mod) * (cmb_count(k - 1, i - 1)) % mod))
| import math
n, k = map(int, input().split())
mod = 10**9 + 7
def cmb_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1, k + 1):
# print("{0}C{1} * {2}C{3}".format(n - k + 1, i, k-1,i-1))
if n - k + 1 >= i:
print(((cmb_count((n - k + 1), i) % mod) * (cmb_count(k - 1, i - 1)) % mod))
else:
print(0)
| replace | 12 | 13 | 12 | 16 | 0 | |
p02990 | Python | Runtime Error | from scipy.special import comb
def solve(string):
n, k = map(int, string.split())
ans = []
for i in range(1, k + 1):
base = comb(n - k + 1, i, exact=True)
var = comb(k - 1, i - 1, exact=True)
ans.append(str(base * var % (10**9 + 7)))
return "\n".join(ans)
if __name__ == "__main__":
print(solve(input()))
| from scipy.misc import comb
def solve(string):
n, k = map(int, string.split())
ans = []
for i in range(1, k + 1):
base = comb(n - k + 1, i, exact=True)
var = comb(k - 1, i - 1, exact=True)
ans.append(str(base * var % (10**9 + 7)))
return "\n".join(ans)
if __name__ == "__main__":
print(solve(input()))
| replace | 0 | 1 | 0 | 1 | ModuleNotFoundError: No module named 'scipy' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02990/Python/s841009615.py", line 1, in <module>
from scipy.special import comb
ModuleNotFoundError: No module named 'scipy'
|
p02990 | C++ | Runtime Error | #include <iostream>
// #include <iomanip>
// #include <string>
#include <vector>
// #include <algorithm>
// #include <utility>
// #include <set>
// #include <map>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <math.h>
using namespace std;
using ll = long long;
// using ld = long double ;
using vll = vector<ll>;
// using vvll = vector<vll> ;
// using vc = vector<char> ;
// using vvc = vector<vc> ;
// using vb = vector<bool> ;
// using vvb = vector<vb> ;
// using pll = pair<ll,ll> ;
ll mod = 1000000007;
// long double pie = acos(-1) ;
// string yorn(bool a){if(a) return"Yes" ; return "No" ;}
// string YorN(bool a){if(a) return"YES" ; return "NO" ;}
// ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
// ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
// ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
// void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
// void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
ll modpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
int main() {
ll n, k;
cin >> n >> k;
vll fac(n + 5, 1);
for (int i = 2; i < n + 5; i++)
fac.at(i) = fac.at(i - 1) * i % mod;
n -= k;
for (int i = 1; i <= k; i++) {
ll blue = fac.at(k - 1) * modpow(fac.at(k - i), mod - 2) % mod *
modpow(fac.at(i - 1), mod - 2) % mod;
ll red = fac.at(n + 1) * modpow(fac.at(n + 1 - i), mod - 2) % mod *
modpow(fac.at(i), mod - 2) % mod;
cout << blue * red % mod << endl;
}
}
| #include <iostream>
// #include <iomanip>
// #include <string>
#include <vector>
// #include <algorithm>
// #include <utility>
// #include <set>
// #include <map>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <math.h>
using namespace std;
using ll = long long;
// using ld = long double ;
using vll = vector<ll>;
// using vvll = vector<vll> ;
// using vc = vector<char> ;
// using vvc = vector<vc> ;
// using vb = vector<bool> ;
// using vvb = vector<vb> ;
// using pll = pair<ll,ll> ;
ll mod = 1000000007;
// long double pie = acos(-1) ;
// string yorn(bool a){if(a) return"Yes" ; return "No" ;}
// string YorN(bool a){if(a) return"YES" ; return "NO" ;}
// ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
// ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
// ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
// void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
// void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
ll modpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
int main() {
ll n, k;
cin >> n >> k;
vll fac(n + 5, 1);
for (int i = 2; i < n + 5; i++)
fac.at(i) = fac.at(i - 1) * i % mod;
n -= k;
for (int i = 1; i <= k; i++) {
ll blue = fac.at(k - 1) * modpow(fac.at(k - i), mod - 2) % mod *
modpow(fac.at(i - 1), mod - 2) % mod;
if (n + 1 - i < 0) {
cout << 0 << endl;
continue;
}
ll red = fac.at(n + 1) * modpow(fac.at(n + 1 - i), mod - 2) % mod *
modpow(fac.at(i), mod - 2) % mod;
cout << blue * red % mod << endl;
}
}
| insert | 55 | 55 | 55 | 59 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define Hello \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ll long long
const int mod = 1e9 + 7, N = 20000;
ll fact[N], inv[N];
ll fp(ll base, ll exp) {
if (exp == 0)
return 1;
ll ans = fp(base, exp / 2);
if (exp % 2 == 0)
return (ans * ans) % mod;
else
return (((ans * ans) % mod) * base) % mod;
}
void calcFacAndInv(ll n) {
fact[0] = inv[0] = 1;
for (ll i = 1; i <= n; i++) {
fact[i] = (i * fact[i - 1]) % mod;
inv[i] = fp(fact[i], mod - 2);
}
}
ll ncr(ll n, ll r) { return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod; }
int main() {
Hello calcFacAndInv(N - 5);
ll n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
ll ans = ((ncr(n - k + 1, i) % mod) * (ncr(k - 1, i - 1) % mod)) % mod;
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define Hello \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ll long long
const int mod = 1e9 + 7, N = 20000;
ll fact[N], inv[N];
ll fp(ll base, ll exp) {
if (exp == 0)
return 1;
ll ans = fp(base, exp / 2);
if (exp % 2 == 0)
return (ans * ans) % mod;
else
return (((ans * ans) % mod) * base) % mod;
}
void calcFacAndInv(ll n) {
fact[0] = inv[0] = 1;
for (ll i = 1; i <= n; i++) {
fact[i] = (i * fact[i - 1]) % mod;
inv[i] = fp(fact[i], mod - 2);
}
}
ll ncr(ll n, ll r) {
if (r > n)
return 0;
return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}
int main() {
Hello calcFacAndInv(N - 5);
ll n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
ll ans = ((ncr(n - k + 1, i) % mod) * (ncr(k - 1, i - 1) % mod)) % mod;
cout << ans << endl;
}
return 0;
}
| replace | 26 | 27 | 26 | 31 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MAXN = 5010;
const int mod = 1e9 + 7;
int n, k, fac[MAXN], inv[MAXN];
int getc(int n, int m) {
return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void work() {
fac[0] = inv[0] = fac[1] = inv[1] = 1;
for (reg int i = 2; i <= 2000; ++i)
fac[i] = 1ll * fac[i - 1] * i % mod,
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for (reg int i = 2; i <= 2000; ++i)
inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
scanf("%lld%lld", &n, &k);
for (reg int i = 1; i <= k; ++i)
printf("%lld\n", getc(k - 1, i - 1) * getc(n - k + 1, i) % mod);
}
signed main() {
int _ = 1;
// scanf("%d", &_);
while (_--)
work();
return 0;
}
| #include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MAXN = 5010;
const int mod = 1e9 + 7;
int n, k, fac[MAXN], inv[MAXN];
int getc(int n, int m) {
if (m > n)
return 0;
return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void work() {
fac[0] = inv[0] = fac[1] = inv[1] = 1;
for (reg int i = 2; i <= 2000; ++i)
fac[i] = 1ll * fac[i - 1] * i % mod,
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for (reg int i = 2; i <= 2000; ++i)
inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
scanf("%lld%lld", &n, &k);
for (reg int i = 1; i <= k; ++i)
printf("%lld\n", getc(k - 1, i - 1) * getc(n - k + 1, i) % mod);
}
signed main() {
int _ = 1;
// scanf("%d", &_);
while (_--)
work();
return 0;
}
| insert | 8 | 8 | 8 | 10 | 0 | |
p02990 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
using LL = long long;
const LL MOD = 1000000007;
LL fac[2020];
LL power(LL a, LL b) {
LL x = 1, y = a;
while (b > 0) {
if (b % 2)
x = (x * y) % MOD;
y = (y * y) % MOD;
b /= 2;
}
return x % MOD;
}
LL mod_inv(LL n) { return power(n, MOD - 2); }
LL nCr(LL n, LL k) {
if (k == 0 || k == n)
return 1;
return (fac[n] * mod_inv(fac[k]) % MOD * mod_inv(fac[n - k]) % MOD) % MOD;
}
int main() {
int n, k;
cin >> n >> k;
fac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = (fac[i - 1] * i) % MOD;
}
for (int i = 1; i <= k; ++i) {
LL ans = (nCr(k - 1, i - 1) * nCr(n - k + 1, i)) % MOD;
cout << ans << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
using LL = long long;
const LL MOD = 1000000007;
LL fac[2020];
LL power(LL a, LL b) {
LL x = 1, y = a;
while (b > 0) {
if (b % 2)
x = (x * y) % MOD;
y = (y * y) % MOD;
b /= 2;
}
return x % MOD;
}
LL mod_inv(LL n) { return power(n, MOD - 2); }
LL nCr(LL n, LL k) {
if (k == 0 || k == n)
return 1;
return (fac[n] * mod_inv(fac[k]) % MOD * mod_inv(fac[n - k]) % MOD) % MOD;
}
int main() {
int n, k;
cin >> n >> k;
fac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = (fac[i - 1] * i) % MOD;
}
for (int i = 1; i <= k; ++i) {
// group blues: k - 1 choose i - 1
// place reds: i - 1 set, (n - k + 1) choose i
if (i - 1 > n - k) {
cout << 0 << endl;
} else {
LL ans = (nCr(k - 1, i - 1) * nCr(n - k + 1, i)) % MOD;
cout << ans << endl;
}
}
return 0;
} | replace | 38 | 40 | 38 | 46 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define ff(i, n) for (int i = 1; i <= n; i++)
ll C[4005][4005], n, k;
ll solve(int i, int total) {
if (total < i)
return 0;
if (i == 0 && total > 0)
return 0;
if (i < 0)
return 0;
total -= i;
return C[i - 1][total + i - 1];
}
int main() {
C[0][0] = 1;
for (int i = 1; i <= 4000; i++) {
C[0][i] = C[i][i] = 1;
for (int j = 1; j < i; j++) {
C[j][i] = (C[j][i - 1] + C[j - 1][i - 1]) % mod;
}
}
cin >> n >> k;
for (int i = 1; i <= k; i++)
cout << (solve(i, k) *
(solve(i - 1, n - k) + 2 * solve(i, n - k) + solve(i + 1, n - k)) %
mod) %
mod
<< endl;
}
// hahahahahahahahahhahahahahahaahahahahhahahahahahahah
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define ff(i, n) for (int i = 1; i <= n; i++)
ll C[4005][4005], n, k;
ll solve(int i, int total) {
if (total < i)
return 0;
if (i == 0 && total > 0)
return 0;
if (i == 0 && total == 0)
return 1;
if (i < 0)
return 0;
total -= i;
return C[i - 1][total + i - 1];
}
int main() {
C[0][0] = 1;
for (int i = 1; i <= 4000; i++) {
C[0][i] = C[i][i] = 1;
for (int j = 1; j < i; j++) {
C[j][i] = (C[j][i - 1] + C[j - 1][i - 1]) % mod;
}
}
cin >> n >> k;
for (int i = 1; i <= k; i++)
cout << (solve(i, k) *
(solve(i - 1, n - k) + 2 * solve(i, n - k) + solve(i + 1, n - k)) %
mod) %
mod
<< endl;
}
// hahahahahahahahahhahahahahahaahahahahhahahahahahahah
| insert | 16 | 16 | 16 | 18 | -11 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// 関数
const long INF = 1000000000000000;
const long MOD = 1000000007;
long modinv(long a) {
long b = MOD, u = 1, v = 0;
while (b) {
long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0)
u += MOD;
return u;
}
int main(void) {
vector<long> kaizyo(50000);
kaizyo.at(0) = 1;
for (int i = 1; i < 5000; i++) {
kaizyo.at(i) = kaizyo.at(i - 1) * i;
kaizyo.at(i) %= MOD;
}
long N, K;
cin >> N >> K;
for (int i = 1; i <= K; i++) {
long freeb = K - i;
long freer = (N - K) - i + 1;
long b = (kaizyo.at(freeb + i - 1) * modinv(kaizyo.at(freeb)) % MOD) *
modinv(kaizyo.at(i - 1));
long r = (kaizyo.at(freer + i) * modinv(kaizyo.at(freer)) % MOD) *
modinv(kaizyo.at(i));
cout << ((b % MOD) * (r % MOD)) % MOD << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
// 関数
const long INF = 1000000000000000;
const long MOD = 1000000007;
long modinv(long a) {
long b = MOD, u = 1, v = 0;
while (b) {
long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0)
u += MOD;
return u;
}
int main(void) {
vector<long> kaizyo(50000);
kaizyo.at(0) = 1;
for (int i = 1; i < 5000; i++) {
kaizyo.at(i) = kaizyo.at(i - 1) * i;
kaizyo.at(i) %= MOD;
}
long N, K;
cin >> N >> K;
for (int i = 1; i <= K; i++) {
long freeb = K - i;
long freer = (N - K) - i + 1;
if (freer < 0) {
cout << 0 << endl;
continue;
}
long b = (kaizyo.at(freeb + i - 1) * modinv(kaizyo.at(freeb)) % MOD) *
modinv(kaizyo.at(i - 1));
long r = (kaizyo.at(freer + i) * modinv(kaizyo.at(freer)) % MOD) *
modinv(kaizyo.at(i));
cout << ((b % MOD) * (r % MOD)) % MOD << endl;
}
} | replace | 34 | 35 | 34 | 38 | 0 | |
p02990 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define MOD (long)(1e9 + 7)
#define MAX 1000000 // 階乗をいくつまで計算するか
class modlong;
void computeAll(long n);
modlong modComb(long n, long k);
modlong modFact(long n);
class modlong {
long val;
const long mod = MOD;
public:
// 初期化 値を引数に与えなかった場合はval=0としておく
modlong(long init = 0) {
while (init < 0)
init += mod; // 0以上であることを保証
val = init % mod;
}
// longへのキャスト operator long()で定義すると modlong +
// longとかができなくなる
long tol() { return this->val; }
// 代入
void operator=(const modlong &r) { this->val = r.val; }
void operator=(const long &r) {
long rr = r;
while (rr < 0)
rr += mod; // 0以上であることを保証
this->val = rr % mod;
}
// 比較
bool operator<(const modlong &r) { return this->val < r.val; }
bool operator>(const modlong &r) { return this->val > r.val; }
bool operator==(const modlong &r) { return this->val == r.val; }
bool operator!=(const modlong &r) { return !(*this == r); }
bool operator<=(const modlong &r) { return !(*this > r); }
bool operator>=(const modlong &r) { return !(*this < r); }
// 足し算; 符号反転; 引き算
modlong operator+(const modlong &r) {
long aval = (this->val + r.val) % mod;
modlong ans(aval);
return ans;
}
modlong operator-() {
long aval = (mod - this->val) % mod;
modlong ans(aval);
return ans;
}
modlong operator-(const modlong &r) {
modlong rr = r;
return *this + (-rr);
}
// かけ算; 逆元; わり算
modlong operator*(const modlong &r) {
long aval = (this->val * r.val) % mod;
modlong ans(aval);
return ans;
}
modlong inv() {
if (*this == 1)
return modlong(1);
if (*this == 0)
cerr << "modlong warning: dividebyzero!!!" << '\n';
modlong p, q = *this, m(0), n(1), r, c;
p.val = mod; // p=modとかくとp.val=mod%mod=0となってしまう
while (q > 1) {
r = p.val % q.val; // r.val=p.val / q.val
// とかくよりもこのほうが代入時に%modされるので安全
c = m.val - n.val * (p.val / q.val);
p = q, q = r, m = n, n = c;
}
return n;
}
modlong operator/(const modlong &r) {
modlong rr = r;
return *this * rr.inv();
}
// ++ -- 前付きと後ろ付き
void operator++() { ++this->val; }
void operator++(int a) {
a = 0;
this->val++;
} // a使ってなくねっていうwarningをsilenceするためにaをいじってる
void operator--() { --this->val; }
void operator--(int a) {
a = 0;
this->val--;
}
// 四則演算&代入
void operator+=(const modlong &r) { *this = *this + r; }
void operator-=(const modlong &r) { *this = *this - r; }
void operator*=(const modlong &r) { *this = *this * r; }
void operator/=(const modlong &r) { *this = *this / r; }
// べき乗
modlong pow(long n) {
if (n < 0)
return inv().pow(-n); // 逆元の-n乗
else if (n == 0)
return modlong(1);
modlong half = pow(n / 2);
if (n % 2)
return *this * half * half;
else
return half * half;
}
// コンビネーション modCombは少し下に書いてある
modlong C(modlong k) { return modComb(this->val, k.val); }
modlong fact() { return modFact(this->val); }
friend ostream &operator<<(ostream &os, const modlong &out);
friend istream &operator>>(istream &is, modlong &out);
};
// cout、cerr、cin用の演算子たち
ostream &operator<<(ostream &os, const modlong &out) {
os << out.val;
return os;
}
istream &operator>>(istream &is, modlong &in) {
long inl;
is >> inl;
in.val = inl % MOD;
return is;
}
////// 階乗を全て求める -> 二項係数を求める
long invs[MAX], facts[MAX], finvs[MAX];
long listlen = 0; // invs, facts, finvsの配列長
void computeAll(long n) {
if (n >= MAX)
cerr << "modlong error: index out of range in computeAll" << '\n';
long i;
if (listlen == 0) {
invs[1] = 1;
facts[0] = 1;
facts[1] = 1;
finvs[0] = 1;
finvs[1] = 1;
i = 2;
} else {
i = listlen;
}
if (n < 2)
return;
for (; i <= n; i++) {
invs[i] = -invs[MOD % i] * (MOD / i) % MOD;
facts[i] = facts[i - 1] * i % MOD;
finvs[i] = finvs[i - 1] * invs[i] % MOD;
}
listlen = n + 1; // 次呼び出すときはn+1以降から再開すれば良い
}
// コンビネーション
modlong modComb(long n, long k) {
if (k < 0 || k > n)
return 0;
if (k == 0 || k == n)
return 1;
if (listlen <= n)
computeAll(n); // 毎回足りない分だけ補う
return modlong(facts[n]) * finvs[k] * finvs[n - k];
}
// 階乗
modlong modFact(long n) {
if (listlen <= n)
computeAll(n); // 毎回足りない分だけ補う
return modlong(facts[n]);
}
int main() {
modlong n, k;
cin >> n >> k;
for (modlong i = 1; i <= k; i++) {
modlong a = (k + i - 3).C(i - 1) -
(k + i - 4).C(i - 2) * (max(i.tol() - 2, 0l)),
b = (n - k + i - 2).C(n - k - 2) -
(n - k + i - 3).C(n - k - 2) * (max(i.tol() - 1, 0l)),
c = (n - k + i - 3).C(n - k - 2) -
(n - k + i - 4).C(n - k - 2) * (max(i.tol() - 2, 0l)),
d = (n - k + i - 4).C(n - k - 2) -
(n - k + i - 5).C(n - k - 2) * (max(i.tol() - 3, 0l));
if (i == 1)
d = 0;
if (n - k < i)
b = 0;
if (n - k + 1 < i)
c = 0;
if (n - k + 2 < i)
b = 0;
cout << a * (b + c * 2 + d) << '\n';
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define MOD (long)(1e9 + 7)
#define MAX 1000000 // 階乗をいくつまで計算するか
class modlong;
void computeAll(long n);
modlong modComb(long n, long k);
modlong modFact(long n);
class modlong {
long val;
const long mod = MOD;
public:
// 初期化 値を引数に与えなかった場合はval=0としておく
modlong(long init = 0) {
while (init < 0)
init += mod; // 0以上であることを保証
val = init % mod;
}
// longへのキャスト operator long()で定義すると modlong +
// longとかができなくなる
long tol() { return this->val; }
// 代入
void operator=(const modlong &r) { this->val = r.val; }
void operator=(const long &r) {
long rr = r;
while (rr < 0)
rr += mod; // 0以上であることを保証
this->val = rr % mod;
}
// 比較
bool operator<(const modlong &r) { return this->val < r.val; }
bool operator>(const modlong &r) { return this->val > r.val; }
bool operator==(const modlong &r) { return this->val == r.val; }
bool operator!=(const modlong &r) { return !(*this == r); }
bool operator<=(const modlong &r) { return !(*this > r); }
bool operator>=(const modlong &r) { return !(*this < r); }
// 足し算; 符号反転; 引き算
modlong operator+(const modlong &r) {
long aval = (this->val + r.val) % mod;
modlong ans(aval);
return ans;
}
modlong operator-() {
long aval = (mod - this->val) % mod;
modlong ans(aval);
return ans;
}
modlong operator-(const modlong &r) {
modlong rr = r;
return *this + (-rr);
}
// かけ算; 逆元; わり算
modlong operator*(const modlong &r) {
long aval = (this->val * r.val) % mod;
modlong ans(aval);
return ans;
}
modlong inv() {
if (*this == 1)
return modlong(1);
if (*this == 0)
cerr << "modlong warning: dividebyzero!!!" << '\n';
modlong p, q = *this, m(0), n(1), r, c;
p.val = mod; // p=modとかくとp.val=mod%mod=0となってしまう
while (q > 1) {
r = p.val % q.val; // r.val=p.val / q.val
// とかくよりもこのほうが代入時に%modされるので安全
c = m.val - n.val * (p.val / q.val);
p = q, q = r, m = n, n = c;
}
return n;
}
modlong operator/(const modlong &r) {
modlong rr = r;
return *this * rr.inv();
}
// ++ -- 前付きと後ろ付き
void operator++() { ++this->val; }
void operator++(int a) {
a = 0;
this->val++;
} // a使ってなくねっていうwarningをsilenceするためにaをいじってる
void operator--() { --this->val; }
void operator--(int a) {
a = 0;
this->val--;
}
// 四則演算&代入
void operator+=(const modlong &r) { *this = *this + r; }
void operator-=(const modlong &r) { *this = *this - r; }
void operator*=(const modlong &r) { *this = *this * r; }
void operator/=(const modlong &r) { *this = *this / r; }
// べき乗
modlong pow(long n) {
if (n < 0)
return inv().pow(-n); // 逆元の-n乗
else if (n == 0)
return modlong(1);
modlong half = pow(n / 2);
if (n % 2)
return *this * half * half;
else
return half * half;
}
// コンビネーション modCombは少し下に書いてある
modlong C(modlong k) { return modComb(this->val, k.val); }
modlong fact() { return modFact(this->val); }
friend ostream &operator<<(ostream &os, const modlong &out);
friend istream &operator>>(istream &is, modlong &out);
};
// cout、cerr、cin用の演算子たち
ostream &operator<<(ostream &os, const modlong &out) {
os << out.val;
return os;
}
istream &operator>>(istream &is, modlong &in) {
long inl;
is >> inl;
in.val = inl % MOD;
return is;
}
////// 階乗を全て求める -> 二項係数を求める
long invs[MAX], facts[MAX], finvs[MAX];
long listlen = 0; // invs, facts, finvsの配列長
void computeAll(long n) {
if (n >= MAX)
cerr << "modlong error: index out of range in computeAll" << '\n';
long i;
if (listlen == 0) {
invs[1] = 1;
facts[0] = 1;
facts[1] = 1;
finvs[0] = 1;
finvs[1] = 1;
i = 2;
} else {
i = listlen;
}
if (n < 2)
return;
for (; i <= n; i++) {
invs[i] = -invs[MOD % i] * (MOD / i) % MOD;
facts[i] = facts[i - 1] * i % MOD;
finvs[i] = finvs[i - 1] * invs[i] % MOD;
}
listlen = n + 1; // 次呼び出すときはn+1以降から再開すれば良い
}
// コンビネーション
modlong modComb(long n, long k) {
if (k < 0 || k > n)
return 0;
if (k == 0 || k == n)
return 1;
if (listlen <= n)
computeAll(n); // 毎回足りない分だけ補う
return modlong(facts[n]) * finvs[k] * finvs[n - k];
}
// 階乗
modlong modFact(long n) {
if (listlen <= n)
computeAll(n); // 毎回足りない分だけ補う
return modlong(facts[n]);
}
int main() {
modlong n, k;
cin >> n >> k;
for (modlong i = 1; i <= k; i++)
cout << (n - k + 1).C(i) * (k - 1).C(i - 1) << '\n';
return 0;
}
| replace | 190 | 209 | 190 | 192 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector<int>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i > b; i--)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pii,null_type,less
<pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
/// X.order_of_key("key")
#define deb(x) cerr << #x << " : " << x << "\n";
#ifndef local
#define deb(x) ;
#endif
///----------------------------------------------------------------------------------
int n, k;
int fac[5000];
int expo(int x, int y) {
int res = 1;
while (y > 0) {
if (y & 1)
res = (res * x) % MOD;
x = (x * x) % MOD;
y /= 2;
}
return res;
}
int Inv(int r) { return expo(r, MOD - 2); }
int ncr(int n, int r) {
/// if (r>n || n<=0||r<0)return 0;
if (r == 0 || r == n)
return 1;
if (r == 1 || r == n - 1)
return n;
return (((fac[n] * Inv(fac[n - r])) % MOD) * Inv(fac[r])) % MOD;
}
void solve() {
fac[0] = 1;
rep(i, 1, 5000) fac[i] = (fac[i - 1] * i) % MOD;
cin >> n >> k;
if (n == k) {
cout << "1\n";
rep(i, 0, k - 1) cout << 0 << "\n";
return;
}
rep(i, 1, k + 1) {
cout << (ncr(n - k + 1, i) * ncr(k - 1, i - 1)) % MOD << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef local
/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
clock_t qwertyuiop = clock();
#endif
int t = 1;
// cin>>t;
rep(a, 0, t) {
/// cout<<"Case #"<<a+1<<": ";
solve();
}
#ifdef local
{
qwertyuiop = clock() - qwertyuiop;
double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC;
cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken
<< " seconds\n";
}
#endif
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector<int>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i > b; i--)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pii,null_type,less
<pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
/// X.order_of_key("key")
#define deb(x) cerr << #x << " : " << x << "\n";
#ifndef local
#define deb(x) ;
#endif
///----------------------------------------------------------------------------------
int n, k;
int fac[5000];
int expo(int x, int y) {
int res = 1;
while (y > 0) {
if (y & 1)
res = (res * x) % MOD;
x = (x * x) % MOD;
y /= 2;
}
return res;
}
int Inv(int r) { return expo(r, MOD - 2); }
int ncr(int n, int r) {
if (r > n || n < 0 || r < 0)
return 0;
if (r == 0 || r == n)
return 1;
if (r == 1 || r == n - 1)
return n;
return (((fac[n] * Inv(fac[n - r])) % MOD) * Inv(fac[r])) % MOD;
}
void solve() {
fac[0] = 1;
rep(i, 1, 5000) fac[i] = (fac[i - 1] * i) % MOD;
cin >> n >> k;
if (n == k) {
cout << "1\n";
rep(i, 0, k - 1) cout << 0 << "\n";
return;
}
rep(i, 1, k + 1) {
cout << (ncr(n - k + 1, i) * ncr(k - 1, i - 1)) % MOD << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef local
/// freopen("input.txt","r",stdin);
/// freopen("output.txt","w",stdout);
clock_t qwertyuiop = clock();
#endif
int t = 1;
// cin>>t;
rep(a, 0, t) {
/// cout<<"Case #"<<a+1<<": ";
solve();
}
#ifdef local
{
qwertyuiop = clock() - qwertyuiop;
double time_taken = ((double)qwertyuiop) / CLOCKS_PER_SEC;
cerr << fixed << setprecision(5) << "\n\nTime Taken : " << time_taken
<< " seconds\n";
}
#endif
} | replace | 49 | 50 | 49 | 51 | 0 | |
p02990 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
long long int mod = 1000000007;
long long int f[1010100];
void init() {
f[0] = 1;
for (int i = 1; i < 1010100; i++)
f[i] = (f[i - 1] * i) % mod;
}
long long int inv(long long int x) {
long long int res = 1;
long long int k = mod - 2;
long long int y = x;
while (k) {
if (k & 1)
res = (res * y) % mod;
y = (y * y) % mod;
k /= 2;
}
return res;
}
long long int C(int n, int k) {
long long int a = f[n]; // = n!
long long int b = f[n - k]; // = (n-k)!
long long int c = f[k]; // = k!
long long int bc = (b * c) % mod;
return (a * inv(bc)) % mod;
}
void Main() {
init();
int n, k;
cin >> n >> k;
for (int i = 0; i < k; i++) {
if (k - 1 < i)
cout << 0 << endl;
else
cout << (C(n - k + 1, i + 1) * C(k - 1, i)) % mod << endl;
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
long long int mod = 1000000007;
long long int f[1010100];
void init() {
f[0] = 1;
for (int i = 1; i < 1010100; i++)
f[i] = (f[i - 1] * i) % mod;
}
long long int inv(long long int x) {
long long int res = 1;
long long int k = mod - 2;
long long int y = x;
while (k) {
if (k & 1)
res = (res * y) % mod;
y = (y * y) % mod;
k /= 2;
}
return res;
}
long long int C(int n, int k) {
long long int a = f[n]; // = n!
long long int b = f[n - k]; // = (n-k)!
long long int c = f[k]; // = k!
long long int bc = (b * c) % mod;
return (a * inv(bc)) % mod;
}
void Main() {
init();
int n, k;
cin >> n >> k;
for (int i = 0; i < k; i++) {
if (n - k + 1 < i + 1 || k - 1 < i)
cout << 0 << endl;
else
cout << (C(n - k + 1, i + 1) * C(k - 1, i)) % mod << endl;
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll modpow(ll a, ll n) {
if (n == 0)
return 1;
else if (n == 1)
return a;
else if (n % 2)
return a * modpow(a * a % mod, (n - 1) / 2) % mod;
else
return modpow(a * a % mod, n / 2);
}
ll modfact(ll na, ll nz) {
if (na == nz)
return 1;
else
return na * modfact(na - 1, nz) % mod;
}
ll modcomb(ll n, ll k) {
return modfact(n, k) * modpow(modfact(n - k, 0), mod - 2) % mod;
}
int main() {
ll n, k;
cin >> n >> k;
for (ll i = 1; i <= k; i++) {
if (i > (n + 1) / 2)
cout << 0 << endl;
else
cout << modcomb(n - k + 1, i) * modcomb(k - 1, i - 1) % mod << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll modpow(ll a, ll n) {
if (n == 0)
return 1;
else if (n == 1)
return a;
else if (n % 2)
return a * modpow(a * a % mod, (n - 1) / 2) % mod;
else
return modpow(a * a % mod, n / 2);
}
ll modfact(ll na, ll nz) {
if (na == nz)
return 1;
else
return na * modfact(na - 1, nz) % mod;
}
ll modcomb(ll n, ll k) {
return modfact(n, k) * modpow(modfact(n - k, 0), mod - 2) % mod;
}
int main() {
ll n, k;
cin >> n >> k;
for (ll i = 1; i <= k; i++) {
if (i > n - k + 1)
cout << 0 << endl;
else
cout << modcomb(n - k + 1, i) * modcomb(k - 1, i - 1) % mod << endl;
}
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p02990 | C++ | Runtime Error | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <stdio.h>
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }
int modPow(long long a, long long n, long long p) {
if (n == 0)
return 1; // 0乗にも対応する場合
if (n == 1)
return a % p;
if (n % 2 == 1)
return (a * modPow(a, n - 1, p)) % p;
long long t = modPow(a, n / 2, p);
return (t * t) % p;
}
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
fact.resize(n + 5);
factinv.resize(n + 5);
inv.resize(n + 5);
fact.at(0) = fact.at(1) = 1;
factinv.at(0) = factinv.at(1) = 1;
inv.at(1) = 1;
for (ll i = 2; i < n + 5; i++) {
fact.at(i) = (fact.at(i - 1) * i) % mod;
inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
}
}
ll nCk(ll n, ll k) {
return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
int main() {
ll N, K;
cin >> N >> K;
prenCkModp(N);
rep(i, K) { cout << (nCk(N - K + 1, i + 1) * nCk(K - 1, i)) % mod << endl; }
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cstdlib>
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <stdio.h>
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }
int modPow(long long a, long long n, long long p) {
if (n == 0)
return 1; // 0乗にも対応する場合
if (n == 1)
return a % p;
if (n % 2 == 1)
return (a * modPow(a, n - 1, p)) % p;
long long t = modPow(a, n / 2, p);
return (t * t) % p;
}
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
fact.resize(n + 5);
factinv.resize(n + 5);
inv.resize(n + 5);
fact.at(0) = fact.at(1) = 1;
factinv.at(0) = factinv.at(1) = 1;
inv.at(1) = 1;
for (ll i = 2; i < n + 5; i++) {
fact.at(i) = (fact.at(i - 1) * i) % mod;
inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
}
}
ll nCk(ll n, ll k) {
if (n < k)
return 0;
else {
return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
}
int main() {
ll N, K;
cin >> N >> K;
prenCkModp(N);
rep(i, K) { cout << (nCk(N - K + 1, i + 1) * nCk(K - 1, i)) % mod << endl; }
}
| replace | 54 | 55 | 54 | 59 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);
ll mpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll fac(int n, ll mod) {
if (n == 1 || n == 0)
return 1;
return n * fac(n - 1, mod) % mod;
}
ll solve(int n, int i, int k) {
ll x1, x2, x3, tmp, mod = 1e9 + 7;
if (k == 0)
x1 = 1ll;
else {
tmp = fac(k - 1 - i, mod) * fac(i, mod) % mod;
x1 = fac(k - 1, mod) * mpow(tmp, mod - 2, mod) % mod;
}
x3 = fac(n - k + 1, mod);
tmp = fac(i + 1, mod) * fac(n - k - i, mod) % mod;
x2 = x3 * mpow(tmp, mod - 2, mod) % mod;
return x1 * x2 % mod;
}
int main() {
int n, k;
sc(n) sc(k) for (int i = 0; i < k; i++) {
if (n - k - i < 0)
cout << 0 << endl;
cout << solve(n, i, k) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);
ll mpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll fac(int n, ll mod) {
if (n == 1 || n == 0)
return 1;
return n * fac(n - 1, mod) % mod;
}
ll solve(int n, int i, int k) {
ll x1, x2, x3, tmp, mod = 1e9 + 7;
if (k == 0)
x1 = 1ll;
else {
tmp = fac(k - 1 - i, mod) * fac(i, mod) % mod;
x1 = fac(k - 1, mod) * mpow(tmp, mod - 2, mod) % mod;
}
x3 = fac(n - k + 1, mod);
tmp = fac(i + 1, mod) * fac(n - k - i, mod) % mod;
x2 = x3 * mpow(tmp, mod - 2, mod) % mod;
return x1 * x2 % mod;
}
int main() {
int n, k;
sc(n) sc(k) for (int i = 0; i < k; i++) {
if (n - k - i < 0)
cout << 0 << endl;
else
cout << solve(n, i, k) << endl;
}
return 0;
} | replace | 43 | 44 | 43 | 45 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <complex>
#define ll long long
#define ld long double
#define F first
#define S second
#define Tsetso \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define pi acos(-1)
#define X real()
#define Y imag()
#define angle(a) (atan2((a).imag(), (a).real()))
#define vec(a, b) ((b) - (a))
#define lenght(a) (hypot((a).imag(), (a).real()))
#define normalize(a) (a) / length(a)
#define point complex<long double>
#define dP(a, b) ((conj(a) * (b)).real())
#define cP(a, b) ((conj(a) * (b)).imag())
#define same(p1, p2) (dP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthsqr(p) dP(p, p)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotataA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(v, m) (conj((v) / (m)) * (m))
const ld EPS = (1e-10);
using namespace std;
const int N = 2e3 + 40, mod = 1e9 + 7;
ll fact[N], INV[N];
ll fp(ll b, ll p) {
if (p == 0)
return 1;
ll temp = fp(b, p / 2) % mod;
temp = (temp * temp) % mod;
if (p % 2)
temp = (temp * b) % mod;
return temp;
}
void pre() {
fact[0] = 1;
INV[0] = 1;
for (int i = 1; i <= N; i++) {
fact[i] = (fact[i - 1] * i) % mod;
INV[i] = fp(fact[i], mod - 2);
}
return;
}
ll nCr(ll n, ll r) {
if (n == r || r == 0)
return 1;
return (((fact[n] * INV[n - r]) % mod) * INV[r]) % mod;
}
int main() {
Tsetso pre();
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++)
cout << (nCr(n - k + 1, i) * nCr(k - 1, i - 1)) % mod << endl;
}
| #include <bits/stdc++.h>
#include <complex>
#define ll long long
#define ld long double
#define F first
#define S second
#define Tsetso \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define pi acos(-1)
#define X real()
#define Y imag()
#define angle(a) (atan2((a).imag(), (a).real()))
#define vec(a, b) ((b) - (a))
#define lenght(a) (hypot((a).imag(), (a).real()))
#define normalize(a) (a) / length(a)
#define point complex<long double>
#define dP(a, b) ((conj(a) * (b)).real())
#define cP(a, b) ((conj(a) * (b)).imag())
#define same(p1, p2) (dP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthsqr(p) dP(p, p)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotataA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(v, m) (conj((v) / (m)) * (m))
const ld EPS = (1e-10);
using namespace std;
const int N = 2e3 + 40, mod = 1e9 + 7;
ll fact[N], INV[N];
ll fp(ll b, ll p) {
if (p == 0)
return 1;
ll temp = fp(b, p / 2) % mod;
temp = (temp * temp) % mod;
if (p % 2)
temp = (temp * b) % mod;
return temp;
}
void pre() {
fact[0] = 1;
INV[0] = 1;
for (int i = 1; i <= N; i++) {
fact[i] = (fact[i - 1] * i) % mod;
INV[i] = fp(fact[i], mod - 2);
}
return;
}
ll nCr(ll n, ll r) {
if (r > n)
return 0;
if (n == r || r == 0)
return 1;
return (((fact[n] * INV[n - r]) % mod) * INV[r]) % mod;
}
int main() {
Tsetso pre();
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++)
cout << (nCr(n - k + 1, i) * nCr(k - 1, i - 1)) % mod << endl;
}
| insert | 47 | 47 | 47 | 49 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdlib.h>
#define ll long long
const ll INF = 0x3f3f3f3f;
#define mod 1000000007
using namespace std;
// priority_queue
const ll Maxn = 1e5;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll kc(ll a, ll b) {
ll c = 1;
while (b) {
if (b & 1)
c = (c * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return c;
}
bool cmp(double x, double y) { return x > y; }
ll vim[2003], ly[2003];
ll C(int a, int b) {
if (b == 0 || a == b)
return 1;
return vim[a] * ly[b] % mod * ly[a - b] % mod;
}
void dd() {
vim[0] = 1;
for (int i = 1; i <= 2000; i++)
vim[i] = vim[i - 1] * i % mod, ly[i] = kc(vim[i], mod - 2);
}
int main() {
ios::sync_with_stdio(false);
dd();
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cout << C(m - 1, i - 1) % mod * C(n - m + 1, i) % mod << endl;
}
}
| #include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdlib.h>
#define ll long long
const ll INF = 0x3f3f3f3f;
#define mod 1000000007
using namespace std;
// priority_queue
const ll Maxn = 1e5;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll kc(ll a, ll b) {
ll c = 1;
while (b) {
if (b & 1)
c = (c * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return c;
}
bool cmp(double x, double y) { return x > y; }
ll vim[2003], ly[2003];
ll C(int a, int b) {
if (b == 0 || a == b)
return 1;
if (a < b)
return 0;
return vim[a] * ly[b] % mod * ly[a - b] % mod;
}
void dd() {
vim[0] = 1;
for (int i = 1; i <= 2000; i++)
vim[i] = vim[i - 1] * i % mod, ly[i] = kc(vim[i], mod - 2);
}
int main() {
ios::sync_with_stdio(false);
dd();
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cout << C(m - 1, i - 1) % mod * C(n - m + 1, i) % mod << endl;
}
}
| insert | 26 | 26 | 26 | 28 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
const int mod = (int)1e9 + 7;
void __print() { cerr << "]\n"; }
template <typename T, typename... V> void __print(T t, V... v) {
cerr << t;
if (sizeof...(v))
cerr << ", ";
__print(v...);
}
#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)
i64 C[2002][2002];
int main() {
memset(C, 0, sizeof C);
for (int i = 0; i <= 2000; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
C[i][j] %= mod;
}
}
}
i64 n, k;
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= k; i++) {
i64 ans = 0;
if (i > 1)
ans += C[k - 1][i - 1] * C[n - k - 1][i - 2];
ans %= mod;
ans += C[k - 1][i - 1] * C[n - k - 1][i];
ans %= mod;
ans += 2 * C[k - 1][i - 1] * C[n - k - 1][i - 1];
ans %= mod;
printf("%lld\n", ans);
}
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
const int mod = (int)1e9 + 7;
void __print() { cerr << "]\n"; }
template <typename T, typename... V> void __print(T t, V... v) {
cerr << t;
if (sizeof...(v))
cerr << ", ";
__print(v...);
}
#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)
i64 C[2002][2002];
int main() {
memset(C, 0, sizeof C);
for (int i = 0; i <= 2000; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
C[i][j] %= mod;
}
}
}
i64 n, k;
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= k; i++) {
i64 ans = 0;
if (n == k) {
if (i == 1)
puts("1");
else
puts("0");
continue;
}
if (i > 1)
ans += C[k - 1][i - 1] * C[n - k - 1][i - 2];
ans %= mod;
ans += C[k - 1][i - 1] * C[n - k - 1][i];
ans %= mod;
ans += 2 * C[k - 1][i - 1] * C[n - k - 1][i - 1];
ans %= mod;
printf("%lld\n", ans);
}
}
| insert | 37 | 37 | 37 | 44 | 0 | |
p02990 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
#define IO \
ios::sync_with_stdio(false); \
cin.tie(); \
cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
ll fac[5500];
ll pows(ll a, ll n) {
ll ans = 1;
while (n) {
if (n & 1) {
ans = ans * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return ans % mod;
}
ll inv(ll a) { return pows(a, mod - 2) % mod; }
ll c(ll n, ll m) { return fac[m] * inv(fac[m - n]) % mod * inv(fac[n]) % mod; }
int main() {
fac[0] = 1;
for (ll i = 1; i < 3000; i++) {
fac[i] = fac[i - 1] * i % mod;
}
ll n, k;
ll ans;
cin >> n >> k;
for (ll i = 1; i <= k; i++) {
ll a, b;
a = c(i, n - k + 1);
b = c(i - 1, k - 1);
ans = a * b % mod;
cout << ans << endl;
}
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
#define IO \
ios::sync_with_stdio(false); \
cin.tie(); \
cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
ll fac[5500];
ll pows(ll a, ll n) {
ll ans = 1;
while (n) {
if (n & 1) {
ans = ans * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return ans % mod;
}
ll inv(ll a) { return pows(a, mod - 2) % mod; }
ll c(ll n, ll m) {
if (n == 0 || m == n)
return 1;
if (m < n)
return 0;
return fac[m] * inv(fac[m - n]) % mod * inv(fac[n]) % mod;
}
int main() {
fac[0] = 1;
for (ll i = 1; i < 3000; i++) {
fac[i] = fac[i - 1] * i % mod;
}
ll n, k;
ll ans;
cin >> n >> k;
for (ll i = 1; i <= k; i++) {
ll a, b;
a = c(i, n - k + 1);
b = c(i - 1, k - 1);
ans = a * b % mod;
cout << ans << endl;
}
return 0;
}
| replace | 36 | 37 | 36 | 43 | 0 | |
p02990 | C++ | Runtime Error | #include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
const ll Q = 1000000007;
ll fact_list[100005];
ll pow_q(ll x, ll y) {
if (y == 0)
return 1;
ll ans = 1;
ll z = x;
ll s = 0;
while (y >> s > 0) {
if ((y >> s) % 2)
ans *= z;
ans %= Q;
++s;
z *= z;
z %= Q;
}
return ans;
}
void set_fact() {
fact_list[0] = 1;
for (ll i = 1; i < 100005; i++) {
fact_list[i] = i * fact_list[i - 1];
fact_list[i] %= Q;
}
}
ll combi_q(ll x, ll y) {
return (((fact_list[x] * pow_q(fact_list[y], Q - 2)) % Q) *
pow_q(fact_list[x - y], Q - 2)) %
Q;
}
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
set_fact();
for (int i = 0; i < k; i++)
cout << combi_q(n - k + 1, i + 1) * combi_q(k - 1, i) % Q << endl;
return 0;
}
| #include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
const ll Q = 1000000007;
ll fact_list[100005];
ll pow_q(ll x, ll y) {
if (y == 0)
return 1;
ll ans = 1;
ll z = x;
ll s = 0;
while (y >> s > 0) {
if ((y >> s) % 2)
ans *= z;
ans %= Q;
++s;
z *= z;
z %= Q;
}
return ans;
}
void set_fact() {
fact_list[0] = 1;
for (ll i = 1; i < 100005; i++) {
fact_list[i] = i * fact_list[i - 1];
fact_list[i] %= Q;
}
}
ll combi_q(ll x, ll y) {
if (x < y)
return 0;
return (((fact_list[x] * pow_q(fact_list[y], Q - 2)) % Q) *
pow_q(fact_list[x - y], Q - 2)) %
Q;
}
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
set_fact();
for (int i = 0; i < k; i++)
cout << combi_q(n - k + 1, i + 1) * combi_q(k - 1, i) % Q << endl;
return 0;
}
| insert | 38 | 38 | 38 | 40 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 4003;
int sum(int a, int b, int mod = MOD) {
int c = a + b;
if (c >= mod) {
c -= mod;
}
return c;
}
inline int prod(int a, int b, int mod = MOD) { return (1LL * a * b) % mod; }
int modpow(int base, int exp, int mod = MOD) {
int res = 1;
int cur = base;
for (int p = 1; p <= exp; p <<= 1) {
if (p & exp) {
res = prod(res, cur, mod);
}
cur = prod(cur, cur, mod);
}
return res;
}
inline int inv(int x, int mod = MOD) { return modpow(x, mod - 2, mod); }
int fact[MAXN], tcaf[MAXN];
void gen_fact() {
fact[0] = 1;
for (int i = 1; i < MAXN; ++i) {
fact[i] = prod(fact[i - 1], i);
}
tcaf[MAXN - 1] = inv(fact[MAXN - 1]);
for (int i = MAXN - 2; i >= 0; --i) {
tcaf[i] = prod(tcaf[i + 1], i + 1);
}
}
int choose(int n, int k) {
assert(k >= 0 and k <= n);
return prod(fact[n], prod(tcaf[k], tcaf[n - k]));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
gen_fact();
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; ++i) {
// break up k balls into i non-empty groups
// (k - 1) choose (i - 1)
int splits = choose(k - 1, i - 1);
// n + 1 places to put them
int spots = choose(n - k + 1, i);
cout << prod(splits, spots) << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 4003;
int sum(int a, int b, int mod = MOD) {
int c = a + b;
if (c >= mod) {
c -= mod;
}
return c;
}
inline int prod(int a, int b, int mod = MOD) { return (1LL * a * b) % mod; }
int modpow(int base, int exp, int mod = MOD) {
int res = 1;
int cur = base;
for (int p = 1; p <= exp; p <<= 1) {
if (p & exp) {
res = prod(res, cur, mod);
}
cur = prod(cur, cur, mod);
}
return res;
}
inline int inv(int x, int mod = MOD) { return modpow(x, mod - 2, mod); }
int fact[MAXN], tcaf[MAXN];
void gen_fact() {
fact[0] = 1;
for (int i = 1; i < MAXN; ++i) {
fact[i] = prod(fact[i - 1], i);
}
tcaf[MAXN - 1] = inv(fact[MAXN - 1]);
for (int i = MAXN - 2; i >= 0; --i) {
tcaf[i] = prod(tcaf[i + 1], i + 1);
}
}
int choose(int n, int k) {
if (!(0 <= k and k <= n)) {
return 0;
}
return prod(fact[n], prod(tcaf[k], tcaf[n - k]));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
gen_fact();
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; ++i) {
// break up k balls into i non-empty groups
// (k - 1) choose (i - 1)
int splits = choose(k - 1, i - 1);
// n + 1 places to put them
int spots = choose(n - k + 1, i);
cout << prod(splits, spots) << '\n';
}
return 0;
}
| replace | 56 | 57 | 56 | 59 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long int nCr[2003][2003];
int main() {
int N, K, MOD = 1000000007;
cin >> N >> K;
for (int i = 0; i < 2003; i++)
for (int j = 0; j < 2003; j++)
nCr[i][j] = 0;
nCr[0][0] = 1;
for (int i = 1; i < 2003; i++)
for (int j = 0; j <= i; j++) {
if (i == j || j == 0)
nCr[i][j] = 1;
else
nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % MOD;
}
for (int i = 1; i <= K; i++) {
long long int res = 0;
res += 2 * (((nCr[N - K - 1][i - 1]) * (nCr[K - 1][i - 1])) % MOD);
res += (((nCr[N - K - 1][i]) * (nCr[K - 1][i - 1])) % MOD);
if (i - 2 >= 0)
res += (((nCr[N - K - 1][i - 2]) * (nCr[K - 1][i - 1])) % MOD);
cout << (res % MOD) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long int nCr[2003][2003];
int main() {
int N, K, MOD = 1000000007;
cin >> N >> K;
for (int i = 0; i < 2003; i++)
for (int j = 0; j < 2003; j++)
nCr[i][j] = 0;
nCr[0][0] = 1;
for (int i = 1; i < 2003; i++)
for (int j = 0; j <= i; j++) {
if (i == j || j == 0)
nCr[i][j] = 1;
else
nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % MOD;
}
for (int i = 1; i <= K; i++) {
long long int res = 0;
res += (((nCr[N - K + 1][i]) * (nCr[K - 1][i - 1])) % MOD);
cout << (res % MOD) << endl;
}
return 0;
} | replace | 20 | 24 | 20 | 21 | 0 | |
p02990 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
long long kMod = 1e9 + 7;
vector<vector<long long>> nck;
long long combinations(long long n, long long k) {
if (n < (long long)nck.size() && k < (long long)nck.at(n).size()) {
return nck.at(n).at(k);
}
nck.resize(n + 1);
for (int i = 0; i < (int)nck.size(); i++) {
nck.at(i).resize(i + 1);
}
nck.at(0).at(0) = 1;
nck.at(1).at(0) = 1;
nck.at(1).at(1) = 1;
for (int i = 2; i < (int)nck.size(); i++) {
for (int j = 0; j < (int)nck.at(i).size(); j++) {
if (j == 0 || j == (int)nck.at(i).size() - 1) {
nck.at(i).at(j) = 1;
} else {
nck.at(i).at(j) =
(nck.at(i - 1).at(j - 1) + nck.at(i - 1).at(j)) % kMod;
}
}
}
return nck.at(n).at(k);
}
long long solve(long long n, long long k, long long i) {
if (k - 1 > n - k + 1) {
return (combinations(k - 1, i - 1) * combinations(n - k + 1, i)) % kMod;
} else {
return (combinations(n - k + 1, i) * combinations(k - 1, i - 1)) % kMod;
}
}
int main() {
long long n, k;
cin >> n >> k;
// cout << combinations(n, k) << '\n';
for (long long i = 1; i <= k; i++) {
// cout << k-1 << ',' << i-1 << '*' << n-k+2 << ',' << i+1 << '\n';
cout << solve(n, k, i) << '\n';
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
long long kMod = 1e9 + 7;
vector<vector<long long>> nck;
long long combinations(long long n, long long k) {
if (n < k) {
return 0;
}
if (n < (long long)nck.size() && k < (long long)nck.at(n).size()) {
return nck.at(n).at(k);
}
nck.resize(n + 1);
for (int i = 0; i < (int)nck.size(); i++) {
nck.at(i).resize(i + 1);
}
nck.at(0).at(0) = 1;
nck.at(1).at(0) = 1;
nck.at(1).at(1) = 1;
for (int i = 2; i < (int)nck.size(); i++) {
for (int j = 0; j < (int)nck.at(i).size(); j++) {
if (j == 0 || j == (int)nck.at(i).size() - 1) {
nck.at(i).at(j) = 1;
} else {
nck.at(i).at(j) =
(nck.at(i - 1).at(j - 1) + nck.at(i - 1).at(j)) % kMod;
}
}
}
return nck.at(n).at(k);
}
long long solve(long long n, long long k, long long i) {
if (k - 1 > n - k + 1) {
return (combinations(k - 1, i - 1) * combinations(n - k + 1, i)) % kMod;
} else {
return (combinations(n - k + 1, i) * combinations(k - 1, i - 1)) % kMod;
}
}
int main() {
long long n, k;
cin >> n >> k;
// cout << combinations(n, k) << '\n';
for (long long i = 1; i <= k; i++) {
// cout << k-1 << ',' << i-1 << '*' << n-k+2 << ',' << i+1 << '\n';
cout << solve(n, k, i) << '\n';
}
return 0;
}
| insert | 10 | 10 | 10 | 13 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long fac[2005];
long long ncr(long long n, long long r, long long p) {
if (r == 0)
return 1;
if (r > n)
return 0;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
fac[0] = 1;
ll n, i, k, mod = 1e9 + 7;
for (i = 1; i <= 2000; i++)
fac[i] = (fac[i - 1] * i) % mod;
cin >> n >> k;
for (i = 1; i <= k; i++) {
// cout<<n-k+1;
cout << (ncr(n - k + 1, i, mod) * (ncr(k - 1, i - 1, mod))) % mod << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long fac[2005];
long long ncr(long long n, long long r, long long p) {
if (r == 0)
return 1;
if (r > n)
return 0;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
fac[0] = 1;
ll n, i, k, mod = 1e9 + 7;
for (i = 1; i <= 2000; i++)
fac[i] = (fac[i - 1] * i) % mod;
cin >> n >> k;
for (i = 1; i <= k; i++) {
// cout<<n-k+1;
cout << (ncr(n - k + 1, i, mod) * (ncr(k - 1, i - 1, mod))) % mod << "\n";
}
}
| replace | 30 | 34 | 30 | 31 | -11 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif
#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b) for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }
class ModCase { // modの元での場合の数
public:
vector<ll> fact, finv;
static ll mod_pow(ll a, ll n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return mod_pow((a * a) % mod, n / 2);
return (a * mod_pow(a, n - 1) % mod);
}
ModCase(ll N) : fact(N + 1), finv(N + 1) { // O(N)で初期化
fact[0] = 1;
FOR(i, 1, N + 1) fact[i] = (i * fact[i - 1]) % mod;
finv[N] = mod_pow(fact[N], mod - 2);
ROF(i, N, 0) finv[i] = finv[i + 1] * (i + 1) % mod;
}
ll C(ll n, ll r) { // nCr
if (r < 0 or n < r)
return 0;
return fact[n] * finv[r] % mod * finv[n - r] % mod;
}
ll P(ll n, ll r) { // nPr
if (r < 0 or n < r)
return 0;
return fact[n] * finv[n - r] % mod;
}
ll H(ll n, ll r) { // nHr
return C(n + r - 1, r);
}
};
signed main() {
int n, k;
cin >> n >> k;
ModCase mc(n + k);
vvi dp(n - k + 2, vi(k + 1)); // dp[i][j] i箇所にj個置く組み合わせ
rep(i, n - k + 2) dp[i][0] = 1;
rep(i, n - k + 1) rep(j, k) {
dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
}
FOR(i, 1, k + 1) {
// dump(mc.C(n-k+1,i));
// dump(dp[i][k-i]);
cout << (mc.C(n - k + 1, i) * dp[i][k - i]) % mod << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif
#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b) for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }
class ModCase { // modの元での場合の数
public:
vector<ll> fact, finv;
static ll mod_pow(ll a, ll n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return mod_pow((a * a) % mod, n / 2);
return (a * mod_pow(a, n - 1) % mod);
}
ModCase(ll N) : fact(N + 1), finv(N + 1) { // O(N)で初期化
fact[0] = 1;
FOR(i, 1, N + 1) fact[i] = (i * fact[i - 1]) % mod;
finv[N] = mod_pow(fact[N], mod - 2);
ROF(i, N, 0) finv[i] = finv[i + 1] * (i + 1) % mod;
}
ll C(ll n, ll r) { // nCr
if (r < 0 or n < r)
return 0;
return fact[n] * finv[r] % mod * finv[n - r] % mod;
}
ll P(ll n, ll r) { // nPr
if (r < 0 or n < r)
return 0;
return fact[n] * finv[n - r] % mod;
}
ll H(ll n, ll r) { // nHr
return C(n + r - 1, r);
}
};
signed main() {
int n, k;
cin >> n >> k;
ModCase mc(n + k);
vvi dp(n - k + 2, vi(k + 1)); // dp[i][j] i箇所にj個置く組み合わせ
rep(i, n - k + 2) dp[i][0] = 1;
rep(i, n - k + 1) rep(j, k) {
dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
}
FOR(i, 1, k + 1) {
// dump(mc.C(n-k+1,i));
// dump(dp[i][k-i]);
if (i > n - k + 1)
cout << 0 << endl;
else
cout << (mc.C(n - k + 1, i) * dp[i][k - i]) % mod << endl;
}
}
| replace | 83 | 84 | 83 | 87 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MOD (1000000007)
using namespace std;
long long f(long long n) {
static long long memo[1000000] = {0};
if (memo[n] > 0)
return memo[n];
if (n == 0)
return 1;
return memo[n] = (n * f(n - 1)) % MOD;
}
long long expmod(long long b, long long e) {
if (e == 0)
return 1;
long long ret = expmod(b, e / 2);
ret *= ret;
ret %= MOD;
if (e % 2 == 1) {
ret *= b;
ret %= MOD;
}
return ret;
}
long long inv(long long n) { return expmod(n, MOD - 2); }
int main(void) {
long long N, K;
cin >> N >> K;
for (int i = 1; i <= K; i++) {
long long ans = 1;
ans *= f(K - 1);
ans *= inv(f(K - i));
ans %= MOD;
ans *= inv(f(i - 1));
ans %= MOD;
ans *= f(N - K + 1);
ans %= MOD;
ans *= inv(f(i));
ans %= MOD;
ans *= inv(f(N - K - i + 1));
ans %= MOD;
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define MOD (1000000007)
using namespace std;
long long f(long long n) {
static long long memo[1000000] = {0};
if (memo[n] > 0)
return memo[n];
if (n == 0)
return 1;
return memo[n] = (n * f(n - 1)) % MOD;
}
long long expmod(long long b, long long e) {
if (e == 0)
return 1;
long long ret = expmod(b, e / 2);
ret *= ret;
ret %= MOD;
if (e % 2 == 1) {
ret *= b;
ret %= MOD;
}
return ret;
}
long long inv(long long n) { return expmod(n, MOD - 2); }
int main(void) {
long long N, K;
cin >> N >> K;
for (int i = 1; i <= K; i++) {
long long ans = 1;
ans *= f(K - 1);
ans *= inv(f(K - i));
ans %= MOD;
ans *= inv(f(i - 1));
ans %= MOD;
ans *= f(N - K + 1);
ans %= MOD;
ans *= inv(f(i));
ans %= MOD;
if (N - K - i + 1 >= 0) {
ans *= inv(f(N - K - i + 1));
ans %= MOD;
} else {
ans = 0;
}
cout << ans << endl;
}
return 0;
} | replace | 44 | 46 | 44 | 50 | 0 | |
p02990 | C++ | Runtime Error | #include <iostream>
using namespace std;
const int M = 1e9 + 7;
int n, k;
long long kaijo[2200];
int mpow(long long a, int n) {
if (n == 0)
return 1;
if (n % 2)
return mpow(a, n - 1) * a % M;
return mpow(a * a % M, n / 2);
}
long long cmb(int n, int r) {
return kaijo[n] * mpow(kaijo[r], M - 2) % M * mpow(kaijo[n - r], M - 2) % M;
}
int main() {
cin >> n >> k;
kaijo[0] = 1;
for (int i = 1; i <= 2100; i++) {
kaijo[i] = kaijo[i - 1] * i % M;
}
for (int r = 1; r <= k; r++) {
int ans = cmb(k - 1, r - 1) * cmb(n - k + 1, r) % M;
cout << ans << endl;
}
return 0;
} | #include <iostream>
using namespace std;
const int M = 1e9 + 7;
int n, k;
long long kaijo[2200];
int mpow(long long a, int n) {
if (n == 0)
return 1;
if (n % 2)
return mpow(a, n - 1) * a % M;
return mpow(a * a % M, n / 2);
}
long long cmb(int n, int r) {
return kaijo[n] * mpow(kaijo[r], M - 2) % M * mpow(kaijo[n - r], M - 2) % M;
}
int main() {
cin >> n >> k;
kaijo[0] = 1;
for (int i = 1; i <= 2100; i++) {
kaijo[i] = kaijo[i - 1] * i % M;
}
for (int r = 1; r <= k; r++) {
int ans = 0;
if (n - k + 1 >= r) {
ans = cmb(k - 1, r - 1) * cmb(n - k + 1, r) % M;
}
cout << ans << endl;
}
return 0;
}
| replace | 29 | 30 | 29 | 33 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef int64_t ll;
typedef long double ld;
const int INF = 1e9;
const ld EPS = 1e-8;
// MOD
const int64_t MOD = 1e9 + 7;
struct Fp {
int64_t x;
Fp() : x(0) {}
Fp(int y) : x(y >= 0 ? y % MOD : (MOD - (-y) % MOD) % MOD) {}
Fp &operator+=(const Fp &p) {
x = (x + p.x) % MOD;
return *this;
}
Fp &operator-=(const Fp &p) {
x = (x + MOD - p.x) % MOD;
return *this;
}
Fp &operator*=(const Fp &p) {
x = x * p.x % MOD;
return *this;
}
bool operator==(const Fp &rhs) const { return this->x == rhs.x; }
Fp operator-() const { return Fp(-x); }
Fp operator+(const Fp &rhs) const { return Fp(*this) += rhs; }
Fp operator-(const Fp &rhs) const { return Fp(*this) -= rhs; }
Fp operator*(const Fp &rhs) const { return Fp(*this) *= rhs; }
Fp operator+(const int y) const { return Fp(*this) += Fp(y); }
Fp operator-(const int y) const { return Fp(*this) -= Fp(y); }
Fp operator*(const int y) const { return Fp(*this) *= Fp(y); }
};
Fp operator+(const int x, const Fp &rhs) { return Fp(x) += rhs; }
Fp operator-(const int x, const Fp &rhs) { return Fp(x) -= rhs; }
Fp operator*(const int x, const Fp &rhs) { return Fp(x) *= rhs; }
ostream &operator<<(ostream &out, const Fp &p) {
out << p.x;
return out;
}
int64_t inv(int64_t a, int64_t p) {
// return x s.t. ax = 1 (mod p)
if (a == 1)
return 1;
return ((1 - p * inv(p % a, a)) / a + p);
}
Fp operator/(const Fp &lhs, const Fp &rhs) { return lhs * Fp(inv(rhs.x, MOD)); }
Fp operator/(const Fp &lhs, const int x) { return (lhs / Fp(x)); }
#define MAX_FACT_N 10000
Fp fact[MAX_FACT_N], invfact[MAX_FACT_N];
void init_fact() {
fact[0] = Fp(1);
invfact[0] = Fp(1);
for (int i = 1; i < MAX_FACT_N; i++) {
fact[i] = fact[i - 1] * i;
invfact[i] = invfact[i - 1] / i;
}
}
Fp comb(int n, int k) { return fact[n] * invfact[k] * invfact[n - k]; }
int main() {
int N, K;
cin >> N >> K;
init_fact();
for (int i = 1; i <= K; i++) {
Fp ret = comb(K - 1, i - 1) * comb(N - K + 1, i);
cout << ret << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef int64_t ll;
typedef long double ld;
const int INF = 1e9;
const ld EPS = 1e-8;
// MOD
const int64_t MOD = 1e9 + 7;
struct Fp {
int64_t x;
Fp() : x(0) {}
Fp(int y) : x(y >= 0 ? y % MOD : (MOD - (-y) % MOD) % MOD) {}
Fp &operator+=(const Fp &p) {
x = (x + p.x) % MOD;
return *this;
}
Fp &operator-=(const Fp &p) {
x = (x + MOD - p.x) % MOD;
return *this;
}
Fp &operator*=(const Fp &p) {
x = x * p.x % MOD;
return *this;
}
bool operator==(const Fp &rhs) const { return this->x == rhs.x; }
Fp operator-() const { return Fp(-x); }
Fp operator+(const Fp &rhs) const { return Fp(*this) += rhs; }
Fp operator-(const Fp &rhs) const { return Fp(*this) -= rhs; }
Fp operator*(const Fp &rhs) const { return Fp(*this) *= rhs; }
Fp operator+(const int y) const { return Fp(*this) += Fp(y); }
Fp operator-(const int y) const { return Fp(*this) -= Fp(y); }
Fp operator*(const int y) const { return Fp(*this) *= Fp(y); }
};
Fp operator+(const int x, const Fp &rhs) { return Fp(x) += rhs; }
Fp operator-(const int x, const Fp &rhs) { return Fp(x) -= rhs; }
Fp operator*(const int x, const Fp &rhs) { return Fp(x) *= rhs; }
ostream &operator<<(ostream &out, const Fp &p) {
out << p.x;
return out;
}
int64_t inv(int64_t a, int64_t p) {
// return x s.t. ax = 1 (mod p)
if (a == 1)
return 1;
return ((1 - p * inv(p % a, a)) / a + p);
}
Fp operator/(const Fp &lhs, const Fp &rhs) { return lhs * Fp(inv(rhs.x, MOD)); }
Fp operator/(const Fp &lhs, const int x) { return (lhs / Fp(x)); }
#define MAX_FACT_N 10000
Fp fact[MAX_FACT_N], invfact[MAX_FACT_N];
void init_fact() {
fact[0] = Fp(1);
invfact[0] = Fp(1);
for (int i = 1; i < MAX_FACT_N; i++) {
fact[i] = fact[i - 1] * i;
invfact[i] = invfact[i - 1] / i;
}
}
Fp comb(int n, int k) { return fact[n] * invfact[k] * invfact[n - k]; }
int main() {
int N, K;
cin >> N >> K;
init_fact();
for (int i = 1; i <= K; i++) {
if (N - K + 1 - i < 0) {
cout << 0 << endl;
} else {
Fp ret = comb(K - 1, i - 1) * comb(N - K + 1, i);
cout << ret << endl;
}
}
return 0;
}
| replace | 80 | 82 | 80 | 86 | 0 | |
p02990 | Python | Runtime Error | import math
def combi(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n, k = map(int, input().split())
div_num = 10**9 + 7
for i in range(1, k + 1):
print(combi(n - k + 1, i) * combi(k - 1, i - 1) % div_num)
| import math
def combi(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n, k = map(int, input().split())
div_num = 10**9 + 7
for i in range(1, k + 1):
if n - k + 1 >= i:
print(combi(n - k + 1, i) * combi(k - 1, i - 1) % div_num)
else:
print(0)
| replace | 10 | 11 | 10 | 14 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll fact(ll n) {
if (n == 0) {
return 1;
}
return fact((n - 1) % MOD) * n % MOD;
}
ll power(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
ll factinv(ll a) {
ll res = power(fact(a), MOD - 2);
return res;
}
ll comb(ll n, ll r) {
return (fact(n) * factinv(r)) % MOD * factinv(n - r) % MOD;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % MOD << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll fact(ll n) {
if (n == 0) {
return 1;
}
return fact((n - 1) % MOD) * n % MOD;
}
ll power(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
ll factinv(ll a) {
ll res = power(fact(a), MOD - 2);
return res;
}
ll comb(ll n, ll r) {
ll res;
if (n < 0 || r < 0 || n < r) {
res = 0;
} else {
res = (fact(n) * factinv(r)) % MOD * factinv(n - r) % MOD;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % MOD << endl;
}
return 0;
}
| replace | 28 | 29 | 28 | 35 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(var, n) for (int var = 0; var < (n); ++var)
const ll MOD = 1e9 + 7;
#define MAX_V (long long)(1e5 * 2 + 200)
ll MAX_VAL;
ll fac[MAX_V], mmi[MAX_V];
inline void factorial() {
fac[0] = fac[1] = 1;
for (long long i = 2; i < MAX_VAL; fac[i] %= MOD, i++)
fac[i] = fac[i - 1] * (i % MOD);
}
inline long long power_mod(long long x, long long n) {
long long ans = 1;
for (; n; n >>= 1, x *= x, ans %= MOD, x %= MOD)
if (n & 1)
ans *= x;
return ans;
}
inline void modular_multiplicatibe_inverse() {
mmi[MAX_VAL - 1] = power_mod(fac[MAX_VAL - 1], MOD - 2);
for (long long i = MAX_VAL - 2; i >= 0; mmi[i] %= MOD, i--)
mmi[i] = mmi[i + 1] * (i + 1);
}
inline long long combination(long long n, long long r) {
return fac[n] * (mmi[r] * mmi[n - r] % MOD) % MOD;
}
int main() {
ll n, k;
cin >> n >> k;
MAX_VAL = n + 3;
factorial();
modular_multiplicatibe_inverse();
rep(i, k) cout << (combination(k - 1, i) * combination(n - k + 1, i + 1)) %
MOD
<< endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(var, n) for (int var = 0; var < (n); ++var)
const ll MOD = 1e9 + 7;
#define MAX_V (long long)(1e5 * 2 + 200)
ll MAX_VAL;
ll fac[MAX_V], mmi[MAX_V], temp[MAX_V];
inline void factorial() {
fac[0] = fac[1] = 1;
for (long long i = 2; i < MAX_VAL; fac[i] %= MOD, i++)
fac[i] = fac[i - 1] * (i % MOD);
}
inline long long power_mod(long long x, long long n) {
long long ans = 1;
for (; n; n >>= 1, x *= x, ans %= MOD, x %= MOD)
if (n & 1)
ans *= x;
return ans;
}
inline void modular_multiplicatibe_inverse() {
mmi[MAX_VAL - 1] = power_mod(fac[MAX_VAL - 1], MOD - 2);
for (long long i = MAX_VAL - 2; i >= 0; mmi[i] %= MOD, i--)
mmi[i] = mmi[i + 1] * (i + 1);
}
inline long long combination(long long n, long long r) {
return fac[n] * (mmi[r] * mmi[n - r] % MOD) % MOD;
}
int main() {
ll n, k;
cin >> n >> k;
MAX_VAL = n + 3;
factorial();
modular_multiplicatibe_inverse();
rep(i, k) cout << (combination(k - 1, i) * combination(n - k + 1, i + 1)) %
MOD
<< endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02990 | Python | Runtime Error | import math
def combination_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, K = map(int, input().split())
blue = K
red = N - K
num = 10**9 + 7
for k in range(K):
space_comb = combination_count(red + 1, k + 1)
ball_comb = combination_count(K - 1, k)
print((space_comb * ball_comb) % num)
| import math
def combination_count(n, r):
if n - r < 0:
return 0
else:
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, K = map(int, input().split())
blue = K
red = N - K
num = 10**9 + 7
for k in range(K):
space_comb = combination_count(red + 1, k + 1)
ball_comb = combination_count(K - 1, k)
print((space_comb * ball_comb) % num)
| replace | 4 | 5 | 4 | 8 | 0 | |
p02990 | Python | Runtime Error | import math
n, k = map(int, input().split())
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1, k + 1):
tmp1 = combinations_count(k - 1, i - 1) % 1000000007
tmp2 = combinations_count(n - k + 1, i) % 1000000007
ans = (tmp1 * tmp2) % 1000000007
print(ans)
if ans == 1:
exit()
| import math
n, k = map(int, input().split())
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1, k + 1):
if n - k + 1 >= i:
tmp1 = combinations_count(k - 1, i - 1) % 1000000007
tmp2 = combinations_count(n - k + 1, i) % 1000000007
ans = (tmp1 * tmp2) % 1000000007
print(ans)
else:
print(0)
| replace | 10 | 16 | 10 | 17 | 0 | |
p02990 | Python | Runtime Error | import math
import sys
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
input = sys.stdin.readline
N, K = map(int, input().strip().split(" "))
div = 1000000000 + 7
for i in range(K):
perm = comb(N - K + 1, i + 1) * comb(K - 1, i)
print(perm % div)
| import math
import sys
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
input = sys.stdin.readline
N, K = map(int, input().strip().split(" "))
div = 1000000000 + 7
for i in range(K):
if i > N - K:
print(0)
else:
perm = comb(N - K + 1, i + 1) * comb(K - 1, i)
print(perm % div)
| replace | 14 | 16 | 14 | 19 | 0 | |
p02990 | Python | Runtime Error | N, K = map(int, input().split())
ans = N - K + 1
for i in range(1, K + 1):
if i > N - K + 1:
ans = 0
print(int(ans % 1000000007))
ans = ans * (N - K + 1 - i) / (i + 1) * (K - i) / i
| N, K = map(int, input().split())
ans = N - K + 1
for i in range(1, K + 1):
if i > N - K + 1:
ans = 0
print(ans % 1000000007)
ans = ans * (N - K + 1 - i) * (K - i)
ans = ans // ((i + 1) * i)
| replace | 5 | 7 | 5 | 8 | 0 | |
p02990 | C++ | Runtime Error | void solve();
int main() {
solve();
return 0;
}
//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <algorithm>
#include <assert.h>
#include <complex>
#include <functional>
#include <iostream>
#include <limits.h>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef complex<ld> Point;
int N, K;
vector<vector<ll>> dp;
int MOD = 1e9 + 7;
// N!を求める(O(N))
long long stair(int N, int mod = 1000000007) {
long long temp = 1;
if (mod != -1) {
for (int i = 2; i <= N; i++) {
temp = (temp * i) % mod;
}
} else {
for (int i = 2; i <= N; i++) {
temp = temp * i;
}
}
return temp;
}
// 0!,1!,...,N!を求める(O(N))
void stairs(int N, vector<long long> &vec, int mod = 1000000007) {
long long temp = 1;
vec.resize(N + 1);
vec[0] = 1;
vec[1] = 1;
for (int i = 2; i <= N; i++) {
if (mod != -1)
temp = (temp * i) % mod;
else
temp *= i;
vec[i] = temp;
}
return;
}
// 繰り返し二乗法
// 掛け算が定義されていることが必要
// O(log n)
template <class T> T pow(T base, int p, T mod = -1) {
if (p == 0)
return 1;
if (p == 1)
return mod == -1 ? base % mod : base;
int b = 1, c = 0;
while (b <= p) {
b *= 2;
c++;
}
T *arr2 = new T[c]; // T[n] = T^(2^n)
arr2[0] = mod == -1 ? base % mod : base;
for (int n = 1; n < c; n++) {
if (mod != -1)
arr2[n] = (arr2[n - 1] * arr2[n - 1]) % mod;
else
arr2[n] = arr2[n - 1] * arr2[n - 1];
}
c--;
T ans = arr2[c];
b /= 2;
p -= b;
while (p > 0) {
c--;
b /= 2;
if (p >= b) {
if (mod != -1)
ans = (ans * arr2[c]) % mod;
else
ans = ans * arr2[c];
p -= b;
}
}
return ans;
}
// 0!,1!,...,N!の逆元(mod剰余)を求める
// O(log(mod)+N)
void stairInv(int N, vector<long long> &vect, int mod = 1000000007) {
vect.resize(N + 1);
long long temp = stair(N, mod);
temp = pow(temp, mod - 2, (long long)mod);
vect[N] = temp;
for (long long n = N - 1; n >= 1; n--) {
temp = (vect[n + 1] * (n + 1)) % mod;
vect[n] = temp;
}
return;
}
// nCkを求める(mod剰余)
// O(N+log(mod)+max(n-k,k))
long long C(int n, int k, int mod = 1000000007) {
if (n == k)
return 1;
if (k == 0)
return 1;
long long temp = stair(n, mod);
vector<long long> *vect = new vector<long long>;
stairInv(max(n - k, k), *vect, mod);
temp = (temp * vect->at(n - k)) % mod;
temp = (temp * vect->at(k)) % mod;
delete vect;
return temp;
}
void solve() {
C(3, 3);
cin >> N >> K;
dp.resize(K + 1);
for (int k = 0; k <= K; k++) {
dp[k].resize(K + 1, 0);
}
for (int k = 1; k <= K; k++)
dp[k][1] = 1;
dp[1][1] = 1;
for (int k = 2; k <= K; k++) {
for (int i = 2; i <= k; i++) {
dp[k][i] = dp[k - 1][i] + dp[k - 1][i - 1];
dp[k][i] %= MOD;
}
}
for (int i = 1; i <= K; i++) {
cout << (C(N - K + 1, i) * dp[K][i]) % MOD << endl;
}
return;
} | void solve();
int main() {
solve();
return 0;
}
//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <algorithm>
#include <assert.h>
#include <complex>
#include <functional>
#include <iostream>
#include <limits.h>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef complex<ld> Point;
int N, K;
vector<vector<ll>> dp;
int MOD = 1e9 + 7;
// N!を求める(O(N))
long long stair(int N, int mod = 1000000007) {
long long temp = 1;
if (mod != -1) {
for (int i = 2; i <= N; i++) {
temp = (temp * i) % mod;
}
} else {
for (int i = 2; i <= N; i++) {
temp = temp * i;
}
}
return temp;
}
// 0!,1!,...,N!を求める(O(N))
void stairs(int N, vector<long long> &vec, int mod = 1000000007) {
long long temp = 1;
vec.resize(N + 1);
vec[0] = 1;
vec[1] = 1;
for (int i = 2; i <= N; i++) {
if (mod != -1)
temp = (temp * i) % mod;
else
temp *= i;
vec[i] = temp;
}
return;
}
// 繰り返し二乗法
// 掛け算が定義されていることが必要
// O(log n)
template <class T> T pow(T base, int p, T mod = -1) {
if (p == 0)
return 1;
if (p == 1)
return mod == -1 ? base % mod : base;
int b = 1, c = 0;
while (b <= p) {
b *= 2;
c++;
}
T *arr2 = new T[c]; // T[n] = T^(2^n)
arr2[0] = mod == -1 ? base % mod : base;
for (int n = 1; n < c; n++) {
if (mod != -1)
arr2[n] = (arr2[n - 1] * arr2[n - 1]) % mod;
else
arr2[n] = arr2[n - 1] * arr2[n - 1];
}
c--;
T ans = arr2[c];
b /= 2;
p -= b;
while (p > 0) {
c--;
b /= 2;
if (p >= b) {
if (mod != -1)
ans = (ans * arr2[c]) % mod;
else
ans = ans * arr2[c];
p -= b;
}
}
return ans;
}
// 0!,1!,...,N!の逆元(mod剰余)を求める
// O(log(mod)+N)
void stairInv(int N, vector<long long> &vect, int mod = 1000000007) {
vect.resize(N + 1);
long long temp = stair(N, mod);
temp = pow(temp, mod - 2, (long long)mod);
vect[N] = temp;
for (long long n = N - 1; n >= 1; n--) {
temp = (vect[n + 1] * (n + 1)) % mod;
vect[n] = temp;
}
return;
}
// nCkを求める(mod剰余)
// O(N+log(mod)+max(n-k,k))
long long C(int n, int k, int mod = 1000000007) {
if (n == k)
return 1;
if (k == 0)
return 1;
long long temp = stair(n, mod);
vector<long long> *vect = new vector<long long>;
stairInv(max(n - k, k), *vect, mod);
temp = (temp * vect->at(n - k)) % mod;
temp = (temp * vect->at(k)) % mod;
delete vect;
return temp;
}
void solve() {
C(3, 3);
cin >> N >> K;
dp.resize(K + 1);
for (int k = 0; k <= K; k++) {
dp[k].resize(K + 1, 0);
}
for (int k = 1; k <= K; k++)
dp[k][1] = 1;
dp[1][1] = 1;
for (int k = 2; k <= K; k++) {
for (int i = 2; i <= k; i++) {
dp[k][i] = dp[k - 1][i] + dp[k - 1][i - 1];
dp[k][i] %= MOD;
}
}
for (int i = 1; i <= K; i++) {
if (i > N - K + 1)
cout << 0 << endl;
else
cout << (C(N - K + 1, i) * dp[K][i]) % MOD << endl;
}
return;
} | replace | 145 | 146 | 145 | 149 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
std::vector<std::vector<long long>> comb(int n, int r) {
std::vector<std::vector<long long>> v(n + 1,
std::vector<long long>(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % MOD;
}
}
return v;
}
int main(void) {
long long N, K;
cin >> N >> K;
vector<vector<long long>> com = comb(N, N);
for (int i = 1; i <= K; i++) {
printf("%lld\n",
(com[K - i + i - 1][i - 1] * com[N - K - i + i + 2][i + 1]) % MOD);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
std::vector<std::vector<long long>> comb(int n, int r) {
std::vector<std::vector<long long>> v(n + 1,
std::vector<long long>(n + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int j = 1; j < v.size(); j++) {
for (int k = 1; k < j; k++) {
v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % MOD;
}
}
return v;
}
int main(void) {
long long N, K;
cin >> N >> K;
vector<vector<long long>> com = comb(N, N);
for (int i = 1; i <= K; i++) {
long long a = com[K - i + i - 1][i - 1];
long long b = com[N - K - i + 1 + i][i];
printf("%d\n", (a * b) % MOD);
}
return 0;
}
| replace | 25 | 27 | 25 | 28 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define repf(i, a, b) for (ll i = a; i < b; i++)
#define repb(i, a, b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
using namespace std;
ll power(ll a, ll n) {
ll ans = 1;
while (n) {
if (n & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return ans;
}
ll fac[4001];
int main() {
IOS;
fac[0] = 1;
repf(i, 1, 4001) { fac[i] = (fac[i - 1] * i) % mod; }
ll N, K;
cin >> N >> K;
ll n = (N - K + 1);
ll r;
repf(i, 1, K + 1) {
r = i;
ll Nr = fac[n];
ll Dr = (fac[n - r] * fac[r]) % mod;
ll ans = (Nr * power(Dr, mod - 2)) % mod;
Nr = fac[K - 1];
Dr = (fac[K - i] * fac[i - 1]) % mod;
ans = ((ans * Nr) % mod * power(Dr, mod - 2)) % mod;
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define repf(i, a, b) for (ll i = a; i < b; i++)
#define repb(i, a, b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
using namespace std;
ll power(ll a, ll n) {
ll ans = 1;
while (n) {
if (n & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
n >>= 1;
}
return ans;
}
ll fac[4001];
int main() {
IOS;
fac[0] = 1;
repf(i, 1, 4001) { fac[i] = (fac[i - 1] * i) % mod; }
ll N, K;
cin >> N >> K;
ll n = (N - K + 1);
ll r;
repf(i, 1, K + 1) {
r = i;
if (n < r) {
cout << 0 << endl;
continue;
}
ll Nr = fac[n];
ll Dr = (fac[n - r] * fac[r]) % mod;
ll ans = (Nr * power(Dr, mod - 2)) % mod;
Nr = fac[K - 1];
Dr = (fac[K - i] * fac[i - 1]) % mod;
ans = ((ans * Nr) % mod * power(Dr, mod - 2)) % mod;
cout << ans << endl;
}
}
| insert | 40 | 40 | 40 | 44 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
#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 999999999
#define P 1000000007
#define ll long long
using namespace std;
ll a[2001];
ll inv[2001];
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K, z1, z2, x = 1;
cin >> N >> K;
a[0] = 1;
inv[0] = 1;
FOR(i, 1, N + 1) {
x = (x * i) % P;
a[i] = x;
inv[i] = modinv(x, P);
}
FOR(i, 1, K + 1) {
z1 = ((a[N - K + 1] * inv[i] % P) * inv[N - K - i + 1] % P);
z2 = ((a[K - 1] * inv[i - 1] % P) * inv[K - i] % P);
cout << z1 * z2 % P << endl;
}
return 0;
} | #include <bits/stdc++.h>
#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 999999999
#define P 1000000007
#define ll long long
using namespace std;
ll a[2001];
ll inv[2001];
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
ll N, K, z1, z2, x = 1;
cin >> N >> K;
a[0] = 1;
inv[0] = 1;
FOR(i, 1, N + 1) {
x = (x * i) % P;
a[i] = x;
inv[i] = modinv(x, P);
}
FOR(i, 1, K + 1) {
if (N - K < i - 1)
cout << 0 << endl;
else {
z1 = ((a[N - K + 1] * inv[i] % P) * inv[N - K - i + 1] % P);
z2 = ((a[K - 1] * inv[i - 1] % P) * inv[K - i] % P);
cout << z1 * z2 % P << endl;
}
}
return 0;
} | replace | 38 | 41 | 38 | 45 | 0 | |
p02990 | C++ | Runtime Error | //
// Created by Hideaki Imamura on 2020-03-17.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll N, K;
ll fact[10000], invfact[10000];
inline ll take_mod(ll a) { return (a % mod + mod) % mod; }
inline ll add(ll a, ll b) { return take_mod(a + b); }
inline ll sub(ll a, ll b) { return take_mod(a - b); }
inline ll mul(ll a, ll b) { return take_mod(a * b); }
inline ll mod_pow(ll x, ll n) {
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = mul(res, x);
x = mul(x, x);
n >>= 1;
}
return res;
}
ll mod_inv(ll x) { return mod_pow(x, mod - 2); }
// nは上限
void make_fact(ll n) {
fact[0] = 1;
ll res = 1;
for (int i = 1; i <= n; i++) {
fact[i] = res;
res = mul(res, i + 1);
}
}
// nは上限
void make_invfact(ll n) {
invfact[0] = 1;
invfact[n] = mod_inv(fact[n]);
for (int i = n - 1; i >= 1; i--) {
invfact[i] = mul(invfact[i + 1], i + 1);
}
}
ll perm(ll n, ll k) { return mul(fact[n], invfact[n - k]); }
ll comb(ll n, ll k) { return mul(mul(fact[n], invfact[n - k]), invfact[k]); }
int main() {
cin >> N >> K;
make_fact(5000);
make_invfact(5000);
for (int i = 1; i <= K; ++i) {
cout << mul(comb(N - K + 1, i), comb(K - 1, i - 1)) << endl;
}
return 0;
} | //
// Created by Hideaki Imamura on 2020-03-17.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll N, K;
ll fact[10000], invfact[10000];
inline ll take_mod(ll a) { return (a % mod + mod) % mod; }
inline ll add(ll a, ll b) { return take_mod(a + b); }
inline ll sub(ll a, ll b) { return take_mod(a - b); }
inline ll mul(ll a, ll b) { return take_mod(a * b); }
inline ll mod_pow(ll x, ll n) {
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = mul(res, x);
x = mul(x, x);
n >>= 1;
}
return res;
}
ll mod_inv(ll x) { return mod_pow(x, mod - 2); }
// nは上限
void make_fact(ll n) {
fact[0] = 1;
ll res = 1;
for (int i = 1; i <= n; i++) {
fact[i] = res;
res = mul(res, i + 1);
}
}
// nは上限
void make_invfact(ll n) {
invfact[0] = 1;
invfact[n] = mod_inv(fact[n]);
for (int i = n - 1; i >= 1; i--) {
invfact[i] = mul(invfact[i + 1], i + 1);
}
}
ll perm(ll n, ll k) { return mul(fact[n], invfact[n - k]); }
ll comb(ll n, ll k) { return mul(mul(fact[n], invfact[n - k]), invfact[k]); }
int main() {
cin >> N >> K;
make_fact(5000);
make_invfact(5000);
for (int i = 1; i <= K; ++i) {
ll ans = 1;
if (N - K + 1 >= i) {
ans = comb(N - K + 1, i);
} else {
ans = 0;
}
ans = mul(ans, comb(K - 1, i - 1));
cout << ans << endl;
}
return 0;
} | replace | 83 | 84 | 83 | 91 | 0 | |
p02990 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define LAR(a, b) ((a) = max((a), (b)))
#define SML(a, b) ((a) = min((a), (b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
#define MOD 1'000'000'007LL
#define N 2048
ll fct[N] = {1};
inline ll pw(ll a, ll b) {
ll c = 1, d = a;
while (b) {
if (b & 1)
c = c * d % MOD;
d = d * d % MOD;
b /= 2;
}
return c;
}
inline ll inv(ll a) { return pw(a, MOD - 2); }
inline ll cmb(ll a, ll b) {
return fct[a] * inv(fct[b]) % MOD * inv(fct[a - b]) % MOD;
}
int main() {
FOR(i, 1, N) fct[i] = fct[i - 1] * i % MOD;
ll n, k;
scanf("%lld%lld", &n, &k);
FOR(i, 1, k + 1) {
ll ans = cmb(k - 1, i - 1);
ans = ans * cmb(n - k + 1, i) % MOD;
printf("%lld\n", ans);
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define LAR(a, b) ((a) = max((a), (b)))
#define SML(a, b) ((a) = min((a), (b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
#define MOD 1'000'000'007LL
#define N 2048
ll fct[N] = {1};
inline ll pw(ll a, ll b) {
ll c = 1, d = a;
while (b) {
if (b & 1)
c = c * d % MOD;
d = d * d % MOD;
b /= 2;
}
return c;
}
inline ll inv(ll a) { return pw(a, MOD - 2); }
inline ll cmb(ll a, ll b) {
return fct[a] * inv(fct[b]) % MOD * inv(fct[a - b]) % MOD;
}
int main() {
FOR(i, 1, N) fct[i] = fct[i - 1] * i % MOD;
ll n, k;
scanf("%lld%lld", &n, &k);
FOR(i, 1, k + 1) {
ll ans = cmb(k - 1, i - 1);
if (n - k + 1 < i)
ans = 0;
else
ans = ans * cmb(n - k + 1, i) % MOD;
printf("%lld\n", ans);
}
}
| replace | 48 | 49 | 48 | 52 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.