QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135171 | #6637. Perfect Strings | Vengeful_Spirit# | WA | 1044ms | 159988kb | C++20 | 918b | 2023-08-05 12:23:57 | 2023-08-05 12:24:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
const int mo=1e9+7;
const int N=1e7+5;
int fac[N],inv[N];
int qpow(int a,int b){
int res=1;
for(;b;b>>=1,a=a*a%mo){
if(b&1)res=res*a%mo;
}
return res;
}
int binom(int n,int m){
if(n>=0&&m>=0&&n-m>=0)
return fac[n]*inv[n-m]%mo*inv[m]%mo;
else return 0;
}
void init(){
fac[0]=1;
for(int i=1;i<N;i++){
fac[i]=fac[i-1]*i%mo;
}
for(int i=0;i<N;i++){
inv[i]=qpow(fac[i],mo-2);
}
}
signed main(){
int m,c;
int Q;
init();
scanf("%lld",&Q);
while(Q--){
scanf("%lld%lld",&m,&c);
m--;
int res=0;
for(int i=0;i<=m;i++){
int x=(binom(2*m-i,m)-binom(2*m-i,m-i-1)+mo)%mo;
if(c-1)
res+=x*qpow(c,i+1)%mo*qpow(c-1,m-i+1)%mo;
res%=mo;
}
if(c==1){
puts("1");
}
else{
printf("%lld\n",res);
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1023ms
memory: 159988kb
input:
2 3 1 2 2
output:
1 6
result:
ok 2 number(s): "1 6"
Test #2:
score: -100
Wrong Answer
time: 1044ms
memory: 159892kb
input:
100000 1 1 4 1 5 5 3 5 1 2 5 3 1 1 3 3 5 2 2 1 4 1 5 5 2 3 4 1 3 3 2 5 3 2 4 3 4 4 3 5 3 1 5 2 2 2 4 2 5 4 1 2 3 1 4 5 2 5 5 3 1 5 5 2 3 2 5 2 4 1 1 3 3 2 4 5 2 1 4 1 2 2 1 1 3 5 4 5 2 3 3 5 2 5 2 4 5 4 2 3 1 1 2 1 4 4 1 5 5 4 1 3 5 4 4 5 1 3 1 1 3 3 2 4 2 4 2 1 5 5 1 3 2 3 4 1 4 3 2 4 2 4 4 2 1 1 1...
output:
1 1 285780 1940 2 7086 1 174 252 1 1 285780 30 1 174 180 20 1086 6276 1940 1 252 6 70 59592 2 1 22900 180 7086 20 252 20 252 1 6 20 22900 1 1 6 1 1940 22900 30 1940 180 84 59592 30 1 1 6276 20 59592 6 59592 22900 6 1 174 84 84 1 285780 6 30 1 1086 84 84 70 1 1 285780 30 6276 6 1 2 30 174 6276 59592 ...
result:
wrong answer 3rd numbers differ - expected: '71445', found: '285780'