QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500559#1263. Keep It CoolBlckCrwAC ✓143ms17988kbC++201.3kb2024-08-01 14:47:222024-08-01 14:47:24

Judging History

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

  • [2024-08-01 14:47:24]
  • 评测
  • 测评结果:AC
  • 用时:143ms
  • 内存:17988kb
  • [2024-08-01 14:47:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define mp make_pair
#define vi vector<int>
#define eb emplace_back
#define pli pair<LL, int>
#define fi first
#define se second
#define rep(rp,a,b) for(int rp=a;rp<=b;++rp)
#define per(bl,a,b) for(int bl=a;bl>=b;--bl)
#define segc int mid = L+R>>1, lc = now<<1, rc = lc|1
const int N = 1e7+5, MOD = 998244353, INF = 1e9;
inline int read() {
	register int x = 0, f = 1;
	register char ch = 0;
	while(ch < 48 || ch > 57) {
			ch = getchar();
			if (ch == '-') f = -1;
		}
	while(ch >= 48 && ch <= 57) x = x*10+(ch^48), ch = getchar();
	return f*x;
}

int n, m, fac[15], a[15], b[15], c[15], d[15], dp[N], val[15];
vi p;
void init() {
	fac[0] = 1; p.eb(0);
	rep (i, 1, n) fac[i] = fac[i-1]*i, p.eb(i);
}

int main() {
	n = read(), m = read();
	rep (i, 1, m) {
		a[i] = read();
		b[i] = read();
		c[i] = read();
		d[i] = read();
	}
	init();
	dp[1] = 1;
	int p1 = 0;
	do {
		++p1;
		int flag = 1;
		rep (i, 1, m)
			if(p[a[i]] < p[b[i]] && p[c[i]] > p[d[i]]) {flag=0; break;}
		if (!flag) dp[p1] = 0;
		rep (i, 1, n) val[p[i]]=i;
		rep (i, 1, n-1)
			if (val[i] < val[i+1]) (dp[p1+fac[n-val[i]]] += dp[p1]) %= MOD;
	} while (next_permutation(p.begin()+1, p.end()));
	printf("%d\n", dp[fac[n]]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3732kb

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: 3800kb

input:

3 0

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

4 0

output:

16

result:

ok 1 number(s): "16"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

5 0

output:

768

result:

ok 1 number(s): "768"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

6 0

output:

292864

result:

ok 1 number(s): "292864"

Test #7:

score: 0
Accepted
time: 1ms
memory: 3896kb

input:

8 0

output:

285163978

result:

ok 1 number(s): "285163978"

Test #8:

score: 0
Accepted
time: 6ms
memory: 5172kb

input:

9 0

output:

67080514

result:

ok 1 number(s): "67080514"

Test #9:

score: 0
Accepted
time: 111ms
memory: 17936kb

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: 130ms
memory: 17980kb

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: 3804kb

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: 3808kb

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: 143ms
memory: 17988kb

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: 119ms
memory: 17928kb

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: 3824kb

input:

7 0

output:

102498303

result:

ok 1 number(s): "102498303"

Test #16:

score: 0
Accepted
time: 90ms
memory: 17984kb

input:

10 0

output:

411322526

result:

ok 1 number(s): "411322526"