QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248233#7623. Coloring Tapeucup-team2303#TL 1453ms21184kbC++172.5kb2023-11-11 17:58:422023-11-11 17:58:43

Judging History

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

  • [2023-11-11 17:58:43]
  • 评测
  • 测评结果:TL
  • 用时:1453ms
  • 内存:21184kb
  • [2023-11-11 17:58:42]
  • 提交

answer

/*
60 + 0 + 100 + 64 = 224.
*/

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#define L(i, j, k) for (int i = (j); i <= (k); i++)
#define R(i, j, k) for (int i = (j); i >= (k); i--)
#define pb push_back
#define pii pair<int, int>
inline int read()
{
	int sum = 0, nega = 1;
	char ch = getchar();
	while (ch > '9'||ch < '0')
	{
	    if (ch == '-') nega = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
	return sum * nega;
}
const int N = (1 << 14) + 9, M = 509, mod = 998244353;
inline void add(int &x, int y) {x = (x + y) % mod;}
inline void del(int &x, int y) {x = (x - y + mod) % mod;}
int n, m, r, popc[N];
struct node
{
	int x, y;
};
vector<node> G[M], T[M];
int dp[N], f[16][16][N], to[N][16];
bool ok[16][16];
inline void solve(int x)
{
	L(i, 1, n)
		L(j, i, n)
		{
			bool fl = 0;
			for (auto v : T[x])
				if(v.x >= i && v.y <= j) fl = 1;
			for (auto v : G[x])
			{
				if(v.x >= i && v.x <= j && v.y > j) fl = 1;
				if(v.y >= i && v.y <= j && v.x < i) fl = 1;
			}
			ok[i][j] = fl;
		}
	memset(f, 0, sizeof(f));
	for (int i = 1; i < (1 << n); i *= 2)
        for (int j = 0; j < (1 << n); j += i * 2)
            for (int k = 0; k < i; k++)
                add(dp[j + k], dp[i + j + k]);
	L(j, 0, (1 << n) - 1) f[0][0][j] = dp[j];
	L(i, 0, n - 1)
		L(j, 0, (1 << n) - 1)
			if(popc[j] > i)
			{
				int p = to[j][i + 1], Ma = j ^ (1 << p), q = to[j][i + 2];
				if(!q) q = n;
				p++;
				L(k, 0, p - 1)
				{
					if(!f[i][k][j]) continue;
					if(k + 1 == p)
					{
						L(s, p, q)
							if(!ok[p][s]) add(f[i + 1][s][Ma | (1 << (s - 1))], f[i][k][j]);
					}
					else if(k < p && !ok[k + 1][p])
						add(f[i + 1][p][Ma | (1 << k)], f[i][k][j]);
				}
			}
	L(i, 0, (1 << n) - 1) dp[i] = f[popc[i]][n][i];
	return ;
}
signed main()
{
	n = read(), m = read(), r = read();
	L(i, 1, r)
	{
		int c = read(), x = read(), y = read(), dif = read();
		if(c == 1 && dif == 0) {puts("0"); return 0;}
		if(dif == 0) G[c].pb(node{x, y});
		else T[c].pb(node{x, y});
	}
	L(i, 0, (1 << n) - 1)
		L(j, 0, n - 1)
			if(i & (1 << j)) popc[i]++, to[i][popc[i]] = j;
	L(i, 0, (1 << n) - 1) dp[i] = 0;
	dp[(1 << n) - 1] = 1;
	L(i, 2, m) solve(i);
	int ans = 0;
	L(i, 0, (1 << n) - 1)
	{
		ans = (ans + dp[i]) % mod;
	}
	cout << ans << endl;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 20044kb

input:

3 5 3
3 2 3 0
4 1 2 0
5 1 3 0

output:

19

result:

ok 1 number(s): "19"

Test #2:

score: 0
Accepted
time: 4ms
memory: 20028kb

input:

5 10 10
9 3 4 1
2 4 5 0
7 2 3 0
9 2 3 0
6 3 5 0
6 2 4 1
2 4 5 0
1 1 3 1
7 2 4 0
10 2 3 0

output:

1514

result:

ok 1 number(s): "1514"

Test #3:

score: 0
Accepted
time: 8ms
memory: 20040kb

input:

5 10 20
8 4 5 0
2 2 5 1
8 4 5 0
10 3 5 0
7 1 3 1
1 2 4 1
6 3 5 1
10 3 5 0
4 1 5 1
7 3 4 1
2 2 4 1
8 3 4 0
9 3 5 0
5 2 5 1
9 4 5 0
9 1 2 0
6 1 5 1
8 3 5 0
2 2 4 1
8 3 5 0

output:

28131

result:

ok 1 number(s): "28131"

Test #4:

score: 0
Accepted
time: 71ms
memory: 20116kb

input:

10 100 200
95 5 7 0
7 4 6 1
62 9 10 0
32 5 8 1
31 2 6 1
75 7 9 1
1 4 7 1
18 7 10 1
75 1 8 1
87 6 9 1
44 7 8 1
68 6 9 1
95 4 6 0
34 1 2 1
70 1 6 1
31 5 9 1
15 6 10 1
48 5 8 1
51 3 7 1
39 5 9 1
23 2 3 1
7 8 9 1
84 7 10 1
13 4 9 1
18 3 6 1
59 9 10 0
31 8 10 1
6 7 9 1
76 3 10 1
41 5 6 0
33 3 4 1
96 1 10...

output:

655333622

result:

ok 1 number(s): "655333622"

Test #5:

score: 0
Accepted
time: 136ms
memory: 20188kb

input:

10 200 200
106 9 10 0
93 4 10 1
199 3 7 0
73 2 9 1
105 8 9 0
38 9 10 1
73 8 10 1
153 3 9 1
123 2 5 1
159 7 9 0
154 5 7 1
162 3 7 0
113 1 5 1
131 7 9 1
67 4 6 1
178 6 10 0
157 7 9 0
147 9 10 0
154 7 10 0
123 3 4 1
39 8 10 1
139 2 9 1
191 9 10 0
36 4 5 1
17 2 8 1
124 3 7 1
9 9 10 1
71 9 10 1
181 7 8 0...

output:

552037151

result:

ok 1 number(s): "552037151"

Test #6:

score: 0
Accepted
time: 198ms
memory: 20108kb

input:

10 300 200
252 1 5 0
48 9 10 1
18 9 10 1
233 9 10 0
195 2 9 1
125 2 5 1
263 7 9 1
24 1 6 1
258 2 10 1
272 8 10 1
76 5 7 1
147 1 7 1
93 9 10 1
30 6 9 1
10 1 10 1
56 2 10 1
93 8 9 1
206 6 9 1
65 1 9 1
226 3 5 0
88 7 8 1
151 3 4 1
292 9 10 0
129 2 3 1
292 9 10 0
180 7 10 1
4 5 10 1
10 9 10 1
151 4 7 1
...

output:

4494096

result:

ok 1 number(s): "4494096"

Test #7:

score: 0
Accepted
time: 336ms
memory: 20636kb

input:

10 500 300
210 4 7 1
341 8 9 0
371 2 5 0
21 4 10 1
370 8 9 0
368 1 6 0
395 7 9 0
287 6 10 1
299 3 7 1
379 1 9 1
164 4 10 1
390 7 9 0
455 6 9 0
208 8 10 1
402 3 10 0
112 8 10 1
279 3 10 1
180 7 10 1
456 2 6 0
121 5 6 1
312 5 7 0
335 8 10 0
318 2 10 1
497 8 10 0
108 8 9 0
247 3 6 1
155 5 6 1
308 1 2 0...

output:

705403853

result:

ok 1 number(s): "705403853"

Test #8:

score: 0
Accepted
time: 531ms
memory: 20332kb

input:

12 500 300
115 3 10 1
152 10 12 1
89 8 12 1
276 4 7 0
467 6 7 0
405 5 9 0
189 4 9 1
197 1 3 1
341 7 8 0
67 7 8 1
266 2 6 1
78 8 12 1
317 11 12 0
417 8 10 0
380 2 8 0
255 2 5 1
80 7 9 1
317 5 11 1
470 5 9 0
373 3 4 0
413 4 10 0
393 9 12 0
362 8 10 1
42 7 12 1
486 3 5 0
229 1 5 0
224 6 7 0
55 3 10 1
4...

output:

378086467

result:

ok 1 number(s): "378086467"

Test #9:

score: 0
Accepted
time: 533ms
memory: 20872kb

input:

12 500 500
54 11 12 1
325 10 11 0
83 2 3 1
148 3 10 1
165 3 11 1
16 11 12 1
363 8 10 1
78 11 12 1
258 4 12 1
237 8 11 1
403 2 10 1
354 1 9 1
234 4 7 1
454 9 11 0
160 11 12 1
393 1 3 0
375 9 11 0
494 1 3 0
200 6 12 1
414 11 12 0
217 9 10 0
92 5 9 1
172 5 6 1
110 8 12 1
339 4 12 1
429 2 4 0
29 10 11 1...

output:

948753642

result:

ok 1 number(s): "948753642"

Test #10:

score: 0
Accepted
time: 1453ms
memory: 21184kb

input:

14 500 500
362 4 12 1
225 5 9 1
428 5 9 1
101 8 10 1
488 5 9 0
249 11 14 1
232 2 6 1
220 4 10 1
20 7 13 1
154 4 13 1
480 8 14 0
9 2 4 1
201 7 10 1
174 10 11 0
169 13 14 0
256 10 12 1
403 11 13 0
492 10 14 0
167 6 12 1
123 11 13 1
471 9 10 0
77 5 9 1
51 6 10 1
411 11 14 1
422 11 13 0
7 1 7 1
284 5 11...

output:

103280588

result:

ok 1 number(s): "103280588"

Test #11:

score: -100
Time Limit Exceeded

input:

14 500 0

output:

750061283

result: