QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645444#9125. Majority and Permutation275307894aRE 1ms4080kbC++141.5kb2024-10-16 18:25:252024-10-16 18:25:26

Judging History

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

  • [2024-10-16 18:25:26]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4080kb
  • [2024-10-16 18:25:25]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e5+5,M=(1<<20)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,vis[N];
ll dp[N],frc[N];
void Solve(){
	scanf("%d%d",&n,&m);
	while(m--){
		int x;scanf("%d",&x);
		vis[x]=1;
	}
	for(int i=1;i<2*n;i+=2) vis[i]&=vis[2*n-i];
	for(int i=frc[0]=1;i<=2*n;i++) frc[i]=frc[i-1]*i%mod;
	dp[0]=1;
	vis[0]=vis[2*n]=1;
	for(int i=1;i<=2*n;i++)if(vis[i]){
		for(int j=1;j<=i;j++) if(vis[j-1]) (dp[i]+=(mod-dp[j-1])*frc[i-j+1])%=mod;
		gdb(dp[i]);
	}
	printf("%lld\n",(mod-dp[2*n])%mod);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 2
1 3

output:

14

result:

ok "14"

Test #2:

score: 0
Accepted
time: 0ms
memory: 4060kb

input:

5 4
1 3 7 9

output:

2909184

result:

ok "2909184"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3976kb

input:

5 1
5

output:

3614400

result:

ok "3614400"

Test #4:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

3 1
3

output:

684

result:

ok "684"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

5 2
5 9

output:

3614400

result:

ok "3614400"

Test #6:

score: -100
Runtime Error

input:

96685 10195
21 27 35 53 63 81 89 117 119 125 131 135 141 157 181 201 225 229 269 275 287 293 321 325 361 363 379 403 409 429 435 441 491 501 505 543 569 609 611 669 711 717 725 727 731 759 769 785 793 797 809 821 863 899 903 911 929 937 961 997 1051 1073 1077 1123 1157 1179 1235 1251 1275 1317 1319 ...

output:


result: