QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143250#7018. Insertion SortSorting#AC ✓5ms3492kbC++20844b2023-08-20 23:25:102023-08-20 23:25:10

Judging History

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

  • [2023-08-20 23:25:10]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3492kb
  • [2023-08-20 23:25:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int a[51];
int w[51][51];
void pre(){
	for(int n=1; n<=50 ;n++)
		for(int i=1; i<=n ;i++){
			for(int j=1; j<=n ;j++){
				if(j==i || j==i+1) continue;
				int cx=0,cy=0;
				for(int k=1; k<=n ;k++){
					cx++;while(cx==i) cx++;
					cy++;while(cy==j) cy++;
					a[cx]=cy;
				}
				a[i]=j;
				int frog=1;
				while(frog<n && a[frog]<a[frog+1]) frog++;
				for(int k=1; k<=frog ;k++) w[n][k]++;
			}
		}
		
}
void solve(int rr){
	int n,k;ll mod;cin >> n >> k >> mod;
	k=min(k,n);
	ll ans=w[n][k]+1;
	for(int i=1; i<=k ;i++) ans=ans*i%mod;
	cout << "Case #" << rr << ": " << ans << '\n';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	pre();
	int t;cin >> t;
	for(int i=1; i<=t ;i++) solve(i);
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3472kb

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: 5ms
memory: 3492kb

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