QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#727023 | #5627. Running Steps | sefnuray# | 0 | 1ms | 3840kb | C++14 | 2.3kb | 2024-11-09 11:00:31 | 2024-11-09 11:00:32 |
answer
#include <iostream>
#include <algorithm>
#include <bitset>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>
#include <stdexcept>
#include <utility>
#include <deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000007
void factorial(vector<ll>& dp, int n) {
dp[0] = 1;
for(int i = 1; i<n; i++) {
dp[i] = i* dp[i-1];
}
}
int nCr(vector<ll>& dp, int n, int r) {
return dp[n] / (dp[r] * dp[(n - r)]);
}
ll gcd (int a, int b) {
return b ? gcd (b, a % b) : a;
}
void FastDoubling (ll n, ll res[]) {
ll a, b, c, d;
// Base Condition
if (n == 0) {
res[0] = 0;
res[1] = 1;
return;
}
FastDoubling((n / 2), res);
// Here a = F(n)
a = res[0];
// Here b = F(n+1)
b = res[1];
c = 2 * b - a;
if (c < 0)
c += MOD;
// As F(2n) = F(n)[2F(n+1) – F(n)]
// Here c = F(2n)
c = (a * c) % MOD;
// As F(2n + 1) = F(n)^2 + F(n+1)^2
// Here d = F(2n + 1)
d = (a * a + b * b) % MOD;
// Check if N is odd
// or even
if (n % 2 == 0) {
res[0] = c;
res[1] = d;
}
else {
res[0] = d;
res[1] = c + d;
}
}
int main()
{
// these first two lines speed up input / output significantly
ios_base::sync_with_stdio(0);
cin.tie(0);
ll p;
cin>>p;
while(p--){
ll k, s;
cin>>k;
cin>>s;
ll sum = 0;
ll t;
ll o;
if(s%4 == 0) {
t = s/4;
o = 0;
} else {
t = s/4;
o = 1;
}
vector<ll> factorial_dp(s/2);
factorial(factorial_dp, s/2);
if(s == 2) {
cout<<k<<" 0"<<"\n";
} else {
while(t >= o) {
ll comb = nCr(factorial_dp, (t+o), t);
sum += comb*comb;
o+=2;
t--;
}
}
cout<<k<<" "<<sum<<"\n";
}
}
详细
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3840kb
input:
1000 1 6 2 8 3 10 4 12 5 60 6 2 7 4 8 14 9 16 10 18 11 20 12 22 13 24 14 26 15 28 16 30 17 32 18 34 19 36 20 38 21 40 22 42 23 44 24 46 25 48 26 50 27 52 28 54 29 56 30 58 31 62 32 64 33 66 34 68 35 70 36 72 37 74 38 76 39 78 40 80 41 82 42 84 43 86 44 88 45 90 46 92 47 94 48 96 49 98 50 100 51 2 52...
output:
1 4 2 1 3 9 4 37 5 40197719157 6 0 6 0 7 1 8 16 9 101 10 425 11 226 12 1261 13 5342 14 3185 15 16661 16 70624 17 45397 18 227925 19 964702 20 654589 21 3192707 22 13483514 23 9533591 24 45499169 25 191695011 26 140024274 27 656975671 28 2761415749 29 2071251366 30 9585067029 31 30823385424 32 174745...
result:
wrong answer 7th lines differ - expected: '7 1', found: '6 0'