QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#426542 | #8047. DFS Order 4 | forget-star | TL | 3ms | 3680kb | C++20 | 703b | 2024-05-31 14:44:00 | 2024-05-31 14:44:00 |
Judging History
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