QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243821 | #7018. Insertion Sort | yiyiyi# | WA | 3ms | 3684kb | C++14 | 1.5kb | 2023-11-08 17:48:43 | 2023-11-08 17:48:43 |
Judging History
answer
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<bitset>
#include<set>
#define int long long
#define lowbit(x) x&(-x)
#define mp make_pair
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define forE(i,x) for(int i=head[x];i;i=nxt[i])
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=2e5+5;
inline int read()
{
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+(c-'0');
c=getchar();
}
return x*f;
}
int T;
int a[maxn];
int fac[maxn];
inline int calc(int n)
{
if(n==0) return 0;
int res=0;
rep(i,1,n) res+=n-i;
rep(i,1,n-1) res+=n-i-1;
return res+1;
}
signed main()
{
T=read();
rep(P,1,T)
{
// printf("%lld\n",calc(2));
int n=read(),k=read(),mod=read();
printf("Case #%lld: ",P);
if(k==1) {printf("%lld\n",calc(n)%mod);continue;}
if(k==2) {printf("%lld\n",(max(0ll,(n-3)*2)%mod+2*(n-2)%mod*2%mod+2*calc(n-2)%mod)%mod);continue;}
fac[0]=1;
rep(i,1,k) fac[i]=fac[i-1]*i%mod;
if(k==n) {printf("%lld\n",fac[k]%mod);continue;}
int ans=k*fac[k]%mod*max(1ll,(n-k))%mod;
// printf("%lld\n",ans);
ans+=calc(n-k)*fac[k]%mod;ans%=mod;
printf("%lld\n",ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3684kb
input:
4 4 1 998244353 4 2 998244353 4 3 998244353 4 4 998244353
output:
Case #1: 10 Case #2: 14 Case #3: 24 Case #4: 24
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3500kb
input:
5000 14 37 557911987 7 10 367410643 16 14 367486993 14 13 257679469 40 1 433152019 6 1 151926713 18 10 831429839 45 23 611504891 43 41 442772417 28 29 651920513 50 43 783397267 34 9 584271757 14 40 136299073 35 24 908302831 32 29 939394321 7 19 925472381 47 24 563986517 42 37 820968349 24 8 36281506...
output:
Case #1: 272085933 Case #2: 39916800 Case #3: 311293812 Case #4: 82630678 Case #5: 1522 Case #6: 26 Case #7: 471744000 Case #8: 406877853 Case #9: 293670654 Case #10: 285233734 Case #11: 530193110 Case #12: 291029760 Case #13: 30611287 Case #14: 473087430 Case #15: 356968239 Case #16: 687038960 Case...
result:
wrong answer 1st lines differ - expected: 'Case #1: 144021228', found: 'Case #1: 272085933'