QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735700#1263. Keep It CoolzhaohaikunAC ✓81ms17804kbC++231.5kb2024-11-11 21:21:042024-11-11 21:21:04

Judging History

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

  • [2024-11-11 21:21:04]
  • 评测
  • 测评结果:AC
  • 用时:81ms
  • 内存:17804kb
  • [2024-11-11 21:21:04]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 15, M = 4e6 + 10, MOD = 998244353;
inline int& add(int &x, ll y) {return x = (x + y) % MOD;}
int n, m, a[N], b[N], c[N], d[N], p[N], cur, f[M], pos[N], fac[N];
signed main() {
	read(n), read(m);
	F(i, 1, m) read(a[i]), read(b[i]), read(c[i]), read(d[i]);
	fac[0] = 1;
	F(i, 1, n) p[i] = i, fac[i] = i * fac[i - 1];
	f[1] = 1;
	do {
		cur++;
		bool flag = true;
		// debug << f[cur] << endl;
		F(i, 1, m)
			if (p[a[i]] < p[b[i]] && p[c[i]] > p[d[i]]) {
				flag = false;
				break;
			}
		if (flag) {
			F(i, 1, n) pos[p[i]] = i;
			F(i, 1, n - 1)
				if (pos[i] < pos[i + 1]) add(f[cur + fac[n - pos[i]]], f[cur]);
		}
	} while (next_permutation(p + 1, p + n + 1));
	cout << f[cur] << '\n';
	return 0;
}
/* why?
*/

详细

Test #1:

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

input:

2 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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

input:

3 0

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

4 0

output:

16

result:

ok 1 number(s): "16"

Test #5:

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

input:

5 0

output:

768

result:

ok 1 number(s): "768"

Test #6:

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

input:

6 0

output:

292864

result:

ok 1 number(s): "292864"

Test #7:

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

input:

8 0

output:

285163978

result:

ok 1 number(s): "285163978"

Test #8:

score: 0
Accepted
time: 10ms
memory: 5056kb

input:

9 0

output:

67080514

result:

ok 1 number(s): "67080514"

Test #9:

score: 0
Accepted
time: 65ms
memory: 10760kb

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: 27ms
memory: 10728kb

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

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

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: 36ms
memory: 16640kb

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: 38ms
memory: 11936kb

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: 0ms
memory: 3652kb

input:

7 0

output:

102498303

result:

ok 1 number(s): "102498303"

Test #16:

score: 0
Accepted
time: 81ms
memory: 17804kb

input:

10 0

output:

411322526

result:

ok 1 number(s): "411322526"