QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#414347#6333. Festivals in JOI Kingdom 2Rafi22#Compile Error//C++141.7kb2024-05-18 21:40:452024-05-18 21:40:46

Judging History

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

  • [2024-05-18 21:40:46]
  • 评测
  • [2024-05-18 21:40:45]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
int mod=998244353;

const int N=3007;

int fac[2*N];
int inv[2*N];
 
int pot(int x,int p) {int res=1;for(;p;p>>=1) {if(p&1) res=res*x%mod; x=x*x%mod;} return res;}
int npok(int n,int k)
{
    if(min(k,n)<0||k>n) return 0;
    return fac[n]*inv[n-k]%mod;
}

int DP[2*N][N][3];

int n;

void add(int i,int j,int c,int x)
{
	if(i>2*n||j>n) continue;
	DP[i][j][c]+=x;
	if(DP[i][j][c]>=mod) DP[i][j][c]-=mod;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>mod;
    fac[0]=1;
    for(int i=1;i<=2*n;i++) fac[i]=fac[i-1]*i%mod;
    inv[2*n]=pot(fac[2*n],mod-2);
    for(int i=2*n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
    int tot=fac[2*n]*inv[n]%mod;
    for(int i=1;i<=n;i++) tot=tot*pot(2,mod-2)%mod;
    DP[0][0][2]=1;
    for(int i=0;i<=2*n;i++)
    {
		for(int j=0;j<=min(n,i);j++)
		{
			/*if(DP[i][j][0]>0) cout<<i<<" "<<j<<" "<<0<<" "<<DP[i][j][0]<<endl;
			if(DP[i][j][1]>0) cout<<i<<" "<<j<<" "<<1<<" "<<DP[i][j][1]<<endl;
			if(DP[i][j][2]>0) cout<<i<<" "<<j<<" "<<2<<" "<<DP[i][j][2]<<endl;*/
			if(j>0) add(i+j,0,2,DP[i][j][0]*npok(2*n-i-1,j-1)%mod);
			if(j>1) add(i+j-1,1,1,DP[i][j][0]*npok(2*n-i-1,j-2)%mod*(j-1)%mod);
			add(i+1,j+1,0,DP[i][j][0]);
			
			add(i+1,j-1,2,DP[i][j][1]);
			add(i+1,j+1,1,DP[i][j][1]);
			
			add(i+1,j+1,0,DP[i][j][2]);
		}
	}
    cout<<(tot-DP[2*n][0][2]+mod)%mod;
    
    return 0;
}

详细

answer.code: In function ‘void add(long long int, long long int, long long int, long long int)’:
answer.code:35:24: error: continue statement not within a loop
   35 |         if(i>2*n||j>n) continue;
      |                        ^~~~~~~~