QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#277285#5066. String-dle CountzhaohaikunTL 922ms87508kbC++142.7kb2023-12-06 17:23:382023-12-06 17:23:38

Judging History

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

  • [2023-12-06 17:23:38]
  • 评测
  • 测评结果:TL
  • 用时:922ms
  • 内存:87508kb
  • [2023-12-06 17:23:38]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#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> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
template <typename T> inline void 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);
	x *= f;
}
const int MOD = 1e9 + 7;
inline void add(int &x, ll y) {x = (x + y) % MOD;}
int n, m, f[1 << 19], t1[30], t2[30], cnt[30], e[30], lim[30], g[20][1 << 19], gg[20][1 << 19];
signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	cin >> n >> m;
	int full = (1 << m) - 1;
	ms(e, -1);
	while (n--) {
		string a, b; cin >> a >> b;
		a = ' ' + a, b = ' ' + b;
		ms(cnt, 0);
		F(j, 1, m) {
			int id = a[j] - 'A' + 1;
			if (b[j] == 'O') {
				if (cnt[id] == -1) return puts("0"), 0;
				cnt[id]++;
				t1[id] |= 1 << (j - 1);
			} else {
				if (b[j] == 'x') {
					if (~cnt[id]) {
						if ((~e[id]) && e[id] != cnt[id]) return puts("0"), 0;
						e[id] = cnt[id];
						cnt[id] = -1;
					}
				} else {
					if (cnt[id] == -1) return puts("0"), 0;
					cnt[id]++;
				}
				t2[id] |= 1 << (j - 1);
			}
		}
		F(j, 1, 26) chkmax(lim[j], cnt[j]);
	}
	// debug << "OK\n";
	int ss = 0;
	F(i, 1, 26) {
		if ((~e[i]) && e[i] < lim[i]) return puts("0"), 0;
		if (~e[i]) lim[i] = e[i];
		ss += lim[i];
	}
	if (ss > m) return puts("0"), 0;
	f[0] = 1;
	F(i, 1, 26) {
		if (t1[i] & t2[i]) return puts("0"), 0;
		ms(g, 0);
		swap(f, g[0]);
		F(j, 1, m) {
			ms(gg, 0);
			F(t, 0, min(j, lim[i]))
				F(l, 0, full)
					gg[t][l] = 0;
			F(t, 0, min(j - 1, lim[i])) {
				F(l, 0, full) {
					if (!(t1[i] & (1 << (j - 1)))) add(gg[t][l], g[t][l]);
					if (!(t2[i] & (1 << (j - 1))) && !(l & (1 << (j - 1)))) {
						if (t == lim[i]) {
							if (e[i] == -1) add(gg[t][l | (1 << (j - 1))], g[t][l]);
						} else {
							add(gg[t + 1][l | (1 << (j - 1))], g[t][l]);
						}
					}
				}
			}
			F(t, 0, min(j, lim[i]))
				F(l, 0, full)
					g[t][l] = gg[t][l];
			// swap(g, gg);
		}
		swap(f, g[lim[i]]);
		// debug << lim[i] << " " << e[i] << " " << t1[i] << " " << t2[i] << endl;
		// F(l, 0, full)
		// 	if (f[l]) cout << i << " " << l << " " << f[l] << endl;
	}
	cout << f[full];
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 422ms
memory: 87404kb

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 299ms
memory: 87412kb

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 922ms
memory: 87404kb

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

score: 0
Accepted
time: 897ms
memory: 87456kb

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 165ms
memory: 87508kb

input:

1 1
K
x

output:

25

result:

ok 1 number(s): "25"

Test #8:

score: -100
Time Limit Exceeded

input:

19 19
ZAZZZAZZZZZZZZZZAAZ
x-xxxxxxxxxxxxxxxxx
ZBZBZZBZZZZBZZZZBZZ
x-xxxxxxxxxxxxxxxxx
CZZCZZCZCZZCZZZCZZZ
-xxxxxxxxxxxxxxxxxx
ZDZZDZDZZZZZZZZZZZZ
x-xxxxxxxxxxxxxxxxx
ZZZZEEZEZZEEZZZZZZZ
xxxx-xxxxxxxxxxxxxx
ZZZZZFZZZZZZZZZZZZF
xxxxx-xxxxxxxxxxxxx
ZZGGZZZZZZZZGGGZZGZ
xx-xxxxxxxxxxxxxxxx
HHHHZHZZZZHHZZ...

output:


result: