QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#449175#7018. Insertion SortxlwangAC ✓2ms3880kbC++141.6kb2024-06-20 19:44:102024-06-20 19:44:10

Judging History

你现在查看的是最新测评结果

  • [2024-06-20 19:44:10]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3880kb
  • [2024-06-20 19:44:10]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
const int Maxn=1e2+10;
int T=0;
int fac[Maxn],mod,n,k;
inline void add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void work(){
    n=read();k=read();mod=read();++T;
    fac[0]=1;fr(i,1,n) fac[i]=1ll*fac[i-1]*i%mod;
    int ans=0;
    if(k>=n-1){printf("Case #%d: %d\n",T,fac[n]);return;}
    // type1:1-k:
    int now=fac[k],now1=0;add(now1,1ll*(n-k)*(n-k)%mod);add(now1,mod-(n-k-1));
    add(ans,1ll*now*now1%mod);
    // type2:(1-k+1)
    add(ans,1ll*k*fac[k]%mod*(n-k)%mod);
    printf("Case #%d: %d\n",T,ans);
}
inline void init(){
	int t=read();
	while(t--) work();
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3880kb

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: 0
Accepted
time: 2ms
memory: 3808kb

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: 144021228
Case #2: 5040
Case #3: 27680678
Case #4: 82630678
Case #5: 1522
Case #6: 26
Case #7: 497145600
Case #8: 158517076
Case #9: 265540132
Case #10: 174173325
Case #11: 757472701
Case #12: 299738880
Case #13: 83183553
Case #14: 685128802
Case #15: 58404183
Case #16: 5040
Case #17: 19811...

result:

ok 5000 lines