QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#426542#8047. DFS Order 4forget-starTL 3ms3680kbC++20703b2024-05-31 14:44:002024-05-31 14:44:00

Judging History

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

  • [2024-05-31 14:44:00]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:3680kb
  • [2024-05-31 14:44:00]
  • 提交

answer

#include<bits/stdc++.h>
#define de fprintf(stderr,"on-%d\n",__LINE__)
//#define int long long
#define fr(i,a,b) for(int i(a),end##i(b);i<=end##i;i++)
#define fd(i,a,b) for(int i(a),end##i(b);i>=end##i;i--)
#define vec vector<int>
using namespace std;
int n;
int a[100],mx[100],f[100];
bool check(){
	fr(i,2,n){
		if(a[i]>a[i-1])f[a[i]]=a[i-1];
		else{
			int x=a[i-1];
			while(x>a[i])x=f[x];
			if(x==1)return 0;
			f[a[i]]=f[x];
		}
	}
	return 1;
}
int ans;
signed main(){
#ifdef pig
	freopen("pig.in","r",stdin);
	freopen("pig.out","w",stdout);
#endif
	cin>>n;
	fr(i,1,n)a[i]=i;
	do{
		if(check())ans++;
	}while(next_permutation(a+2,a+n+1));
	cout<<ans;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 3ms
memory: 3680kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: -100
Time Limit Exceeded

input:

100 1000000007

output:


result: