QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129388 | #6137. Sub-cycle Graph | Energy_is_not_over# | AC ✓ | 1492ms | 5816kb | C++17 | 3.9kb | 2023-07-22 17:59:03 | 2023-07-22 17:59:05 |
Judging History
answer
//
// Created by Barichek on 22.07.2023 11:45:22
//
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(), a.end()
#define len(a) (int) (a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
#ifdef Energy_is_not_over
#define DEBUG for (bool ____DEBUG = true; ____DEBUG; ____DEBUG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif
const int max_n = -1, inf = 1000111222;
/*
* long long version
long long mul(long long a, long long b) {
long long x = (long double) a * b / mod;
long long y = (a * b - x * mod) % mod;
return y < 0 ? y + mod : y;
}
long long power(long long a, long long b) {
if (b == 0) {
return 1 % mod;
}
if (b % 2 == 0) {
return power(mul(a, a), b / 2);
}
return mul(a, power(a, b - 1));
}*/
const int mod = 1000000007;
//const int mod = 998244353;
inline void inc(int &x, int y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
inline void dec(int &x, int y) {
x -= y;
if (x < 0) {
x += mod;
}
}
inline int neg(int x) {
return x ? (mod - x) : 0;
}
inline int mul(int x) {
return x;
}
template<typename... Args>
inline int mul(int x, Args... args) {
return (1LL * x * mul(args...)) % mod;
}
int power(int a, long long b) {
int res = 1 % mod;
while (b) {
if (b % 2) {
res = mul(res, a);
}
b /= 2;
a = mul(a, a);
}
return res;
}
int inv(int x) {
return power(x, mod - 2);
}
const int max_f = 3e5+10;
const int max_rf = max_f;
static_assert(max_f >= 1 && max_rf >= 1);
int f[max_f], rf[max_rf];
bool frf_calculated = []() {
f[0] = 1;
for (int i = 1; i < max_f; ++i) {
f[i] = mul(i, f[i - 1]);
}
int x = f[min(max_f, max_rf) - 1];
for (int i = max_f; i < max_rf; ++i) {
x = mul(x, i);
}
rf[max_rf - 1] = inv(x);
for (int i = max_rf - 2; i >= 0; --i) {
rf[i] = mul(i + 1, rf[i + 1]);
}
return true;
}();
int get_c(int n, int k) {
if (n < k || k < 0) {
return 0;
}
assert(n < max_f && k < max_rf && n - k < max_rf);
return mul(f[n], rf[k], rf[n - k]);
}
string str_fraction(int x, int n = 20) {
stringstream res;
pair<int, int> best(x, 1);
for (int j = 1; j < n; ++j) {
best = min(best, {mul(x, j), j});
best = min(best, {mod - mul(x, j), -j});
}
if (best.second < 0) {
best.first *= -1;
best.second *= -1;
}
res << best.first << "/" << best.second;
return res.str();
}
void solve()
{
int n;
ll m;
cin>>n>>m;
if (m>n){
cout<<0<<"\n";
return;
}
if (m==n){
cout<<mul(f[n-1],inv(2))<<"\n";
return;
}
if (m==0){
cout<<1<<"\n";
return;
}
const int c=n-m;
int ans=0;
for (int ones=0;ones<c;ones++){
int cur_n=n-ones;
int cur_c=c-ones;
LOG(ones,cur_n,cur_c);
if (cur_n>=2*cur_c){
int cur=mul(f[cur_n],get_c((cur_n-2*cur_c)+cur_c-1,cur_c-1),inv(power(2,cur_c)),rf[cur_c]);
LOG(get_c(n,ones),cur);
inc(ans,mul(get_c(n,ones),cur));
}
}
cout<<ans<<"\n";
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int tests;
cin>>tests;
while (tests--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 5816kb
input:
3 4 2 4 3 5 3
output:
15 12 90
result:
ok 3 number(s): "15 12 90"
Test #2:
score: 0
Accepted
time: 1492ms
memory: 5804kb
input:
17446 3 0 3 1 3 2 3 3 4 0 4 1 4 2 4 3 4 4 5 0 5 1 5 2 5 3 5 4 5 5 6 0 6 1 6 2 6 3 6 4 6 5 6 6 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 10 0 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 0 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11...
output:
1 3 3 1 1 6 15 12 3 1 10 45 90 60 12 1 15 105 375 630 360 60 1 21 210 1155 3465 5040 2520 360 1 28 378 2940 13545 35280 45360 20160 2520 1 36 630 6552 42525 170100 393120 453600 181440 20160 1 45 990 13230 114345 643545 2286900 4762800 4989600 1814400 181440 1 55 1485 24750 273735 2047815 10239075 3...
result:
ok 17446 numbers