提交记录 3829


用户 题目 状态 得分 用时 内存 语言 代码长度
ylsoi noi18a. 【NOI2018】归程 Wrong Answer 0 4 s 83076 KB C++ 1.58 KB
提交时间 评测时间
2018-07-18 18:44:26 2020-07-31 21:47:48
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>

#define REP(i,a,b) for(int i=a;i<=b;++i)
#define DREP(i,a,b) for(int i=a;i>=b;--i)
typedef long long ll;

using namespace std;

void File(){
	freopen("inverse.in","r",stdin);
	freopen("inverse.out","w",stdout);
}

const int maxn=6e5+10;
const int maxw=(1<<19)+10;
const ll mod=998244353;
int T,n,a[maxn];
ll dp[20][maxw];

int bit(int x){return 1<<(x-1);}
int count(int x,int y){return __builtin_popcount(x>>y);}

bool vis[maxn];
ll cal(int x,int len){
	memset(dp,0,sizeof(dp));
	int all=0,las=0;
	REP(i,1,n)if(!vis[i])all|=bit(i);
	else if(i!=x)las|=bit(i);
	all|=bit(x);
	dp[1][bit(x)]=1;
	if(count(las,x)>max(n-len+1-x,0))return 0;
	REP(i,2,len){
		REP(j,1,n){
			if(j==x)continue;
			if(!(bit(j)&all))continue;
			int S0=all^bit(j);
			for(int S=S0;S;S=(S-1)&S0){
				if(!(bit(x)&S))continue;
				if(__builtin_popcount(S)!=i-1)continue;
				int low=n-len+i;
				if(count(S|las,j)>max(low-j,0))continue;
				dp[i][S^bit(j)]=(dp[i][S^bit(j)]+dp[i-1][S])%mod;
			}
		}
	}
	return dp[len][all];
}

ll ans;

int main(){
	//File();
	scanf("%d",&T);
	while(T--){
		ans=0;
		memset(vis,0,sizeof(vis));
		scanf("%d",&n);
		REP(i,1,n){
			scanf("%d",&a[i]);
			vis[a[i]]=1;
		}
		DREP(i,n,1){
			vis[a[i]]=0;
			bool flag=false;
			REP(j,1,i-1){
				int cnt=0;
				REP(k,1,j-1)if(a[k]>a[j])++cnt;
				if(cnt>max(j-a[j],0)){
					flag=true;
					break;
				}
			}
			if(flag)continue;
			REP(j,a[i]+1,n)if(!vis[j]){
				vis[j]=1;
				ans=(ans+cal(j,n-i+1))%mod;
				vis[j]=0;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #16.808 ms80 MB + 628 KBWrong AnswerScore: 0

Testcase #232.389 ms80 MB + 628 KBWrong AnswerScore: 0

Testcase #34 s80 MB + 624 KBTime Limit ExceededScore: 0

Testcase #46.674 ms80 MB + 624 KBRuntime ErrorScore: 0

Testcase #54 s80 MB + 628 KBTime Limit ExceededScore: 0

Testcase #64 s81 MB + 132 KBTime Limit ExceededScore: 0

Testcase #778.35 us624 KBRuntime ErrorScore: 0

Testcase #879.06 us628 KBRuntime ErrorScore: 0

Testcase #980.42 us636 KBRuntime ErrorScore: 0

Testcase #1079.81 us636 KBRuntime ErrorScore: 0

Testcase #1179.64 us632 KBRuntime ErrorScore: 0

Testcase #1282.39 us660 KBRuntime ErrorScore: 0

Testcase #1380.57 us640 KBRuntime ErrorScore: 0

Testcase #1480.54 us644 KBRuntime ErrorScore: 0

Testcase #1578.39 us624 KBRuntime ErrorScore: 0

Testcase #1679.44 us636 KBRuntime ErrorScore: 0

Testcase #1780.61 us640 KBRuntime ErrorScore: 0

Testcase #1882.61 us660 KBRuntime ErrorScore: 0

Testcase #1982.02 us656 KBRuntime ErrorScore: 0

Testcase #2078.51 us624 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-17 22:03:56 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠