QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#527868 | #1263. Keep It Cool | xlwang | AC ✓ | 93ms | 17932kb | C++14 | 1.8kb | 2024-08-22 21:08:51 | 2024-08-22 21:08:51 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
const int Maxn=12,Maxs=5e6+10,mod=998244353;
int n,m;
int a[Maxn],b[Maxn],c[Maxn],d[Maxn],p[Maxn],fac[Maxn];
int f[Maxs];
inline void add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void init(){
n=read();m=read();
fr(i,1,m) a[i]=read(),b[i]=read(),c[i]=read(),d[i]=read();
fac[0]=1;fr(i,1,n) fac[i]=fac[i-1]*i;
}
int to[Maxn];
inline void work(){
f[1]=1;fr(i,1,n) p[i]=i;
int id=0;
do{
++id;
int fl=1;
fr(i,1,m) if(p[a[i]]<p[b[i]] && p[c[i]]>p[d[i]]) fl=0;
if(fl==0) {f[id]=0;continue;}
fr(i,1,n) to[p[i]]=i;
fr(i,1,n-1) if(to[i]<to[i+1]) add(f[id+fac[n-to[i]]],f[id]);
}while(next_permutation(p+1,p+n+1));
writeln(f[id]);
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();work();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
input:
2 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
4 3 1 2 2 3 1 2 3 4 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
3 0
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
4 0
output:
16
result:
ok 1 number(s): "16"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5540kb
input:
5 0
output:
768
result:
ok 1 number(s): "768"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
6 0
output:
292864
result:
ok 1 number(s): "292864"
Test #7:
score: 0
Accepted
time: 2ms
memory: 3792kb
input:
8 0
output:
285163978
result:
ok 1 number(s): "285163978"
Test #8:
score: 0
Accepted
time: 7ms
memory: 5100kb
input:
9 0
output:
67080514
result:
ok 1 number(s): "67080514"
Test #9:
score: 0
Accepted
time: 82ms
memory: 17788kb
input:
10 8 1 2 2 3 1 2 3 4 1 2 4 5 1 2 5 6 1 2 6 7 1 2 7 8 1 2 8 9 1 2 9 10
output:
869798492
result:
ok 1 number(s): "869798492"
Test #10:
score: 0
Accepted
time: 38ms
memory: 17932kb
input:
10 10 1 3 2 4 2 4 3 5 3 5 1 5 1 2 4 5 5 6 6 7 5 7 4 6 1 3 3 5 3 5 1 3 6 7 7 8 7 8 8 9
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
3 2 1 2 1 3 2 3 1 3
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
4 4 1 2 2 3 1 2 2 3 1 2 2 3 1 2 2 3
output:
8
result:
ok 1 number(s): "8"
Test #13:
score: 0
Accepted
time: 67ms
memory: 17712kb
input:
10 10 1 3 3 5 2 6 6 8 1 5 7 8 2 7 5 7 4 5 9 10 8 10 5 8 1 6 2 6 1 6 2 8 3 5 9 10 3 6 5 7
output:
772654158
result:
ok 1 number(s): "772654158"
Test #14:
score: 0
Accepted
time: 65ms
memory: 17872kb
input:
10 10 1 2 3 4 2 5 6 7 1 4 7 8 2 6 5 6 4 5 9 10 8 9 5 7 1 5 1 3 1 5 4 5 3 4 9 10 1 2 2 3
output:
298701136
result:
ok 1 number(s): "298701136"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
7 0
output:
102498303
result:
ok 1 number(s): "102498303"
Test #16:
score: 0
Accepted
time: 93ms
memory: 17836kb
input:
10 0
output:
411322526
result:
ok 1 number(s): "411322526"