QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290147#5066. String-dle CountRemakee#TL 405ms8556kbC++142.1kb2023-12-24 14:26:352023-12-24 14:26:35

Judging History

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

  • [2023-12-24 14:26:35]
  • 评测
  • 测评结果:TL
  • 用时:405ms
  • 内存:8556kb
  • [2023-12-24 14:26:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e4 + 5, S = 19;

int n, K, f[1 << S], g[1 << S][S + 1];

char A[25], B[25];

bool no[S][26];
int st[26];

bool ok = 1;

int Eq[26], Ge[26];


const int P = 1e9 + 7;

void add(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}

void sv() {
	f[0] = 1;
	for (int c = 0; c < 26; c++) {
		for (int i = 0; i < (1 << K); i++)
			g[i][0] = f[i], f[i] = 0;

		for (int u = 0; u < K; u++) {
			for (int j = K - 1; j >= 0; j--) {
				for (int i = 0; i < (1 << K); i++) {
					if (!g[i][j]) continue;
					if (i >> u & 1) continue;
					if (st[u] != -1 && st[u] != c) continue;
					if (no[u][c]) continue;
					add(g[i | (1 << u)][j + 1], g[i][j]);
				}
			}
		}

		for (int i = 0; i < (1 << K); i++) {
			for (int j = 0; j <= K; j++) {
				if (!g[i][j]) continue;
				if (Eq[c] != -1 && Eq[c] != j) continue;
				if (j < Ge[c]) continue;
				//cout << c << " " << i << " " << j << " awa " << g[i][j] << endl;
				add(f[i], g[i][j]);
			}
		}

		for (int i = 0; i < (1 << K); i++) {
			for (int j = 0; j <= K; j++) {
				g[i][j] = 0;
			}
		}
	}
	printf("%d\n", f[(1 << K) - 1]);	
}

void wk() {
	scanf("%s%s", A, B);
	for (int i = 0; i < K; i++) {
		int c = A[i] - 'A';
		if (B[i] == 'O') {
			if (st[i] != -1 && st[i] != c) {
				ok = 0;
			}
			st[i] = c;
		} else if (B[i] == 'x') {
			int num = 0;
			for (int j = 0; j < K; j++) {
				if (A[j] == A[i]) {
					if (B[j] == 'O') {
						num++;
					} else if (j < i) {
						if (B[j] == '-') num++;
					}
				}

			}
			if (Eq[c] != -1 && Eq[c] != num) ok = 0;
			Eq[c] = num;
			no[i][c] = 1;
		} else if (B[i] == '-') {
			int num = 1;
			for (int j = 0; j < K; j++) {
				if (A[j] == A[i]) {
					if (B[j] == 'O') {
						num++;
					} else if (j < i) {
						if (B[j] == '-') num++;
						else if (B[j] == 'x') {
							ok = 0;
						}
					}
				}
			}
			no[i][c] = 1;
			Ge[c] = max(Ge[c], num);
		}
	}
}


int main() {
	memset(Eq, -1, sizeof Eq);
	memset(st, -1, sizeof st);
	scanf("%d%d", &n, &K); 
	for (int i = 1; i <= n; i++) wk();
	if (!ok) puts("0");
	else sv();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5844kb

input:

2 5
CRANE
xx--x
NASAL
OOxOO

output:

21

result:

ok 1 number(s): "21"

Test #2:

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

input:

1 5
BBBAA
xxxx-

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 5
ABCDE
-xxxx
ABCDE
xxxxx

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

1 3
ABC
---

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 405ms
memory: 8556kb

input:

1 15
AAAAAAAAAAAAAAB
-xxxxxxxxxxxxxx

output:

918547951

result:

ok 1 number(s): "918547951"

Test #6:

score: 0
Accepted
time: 391ms
memory: 8444kb

input:

1 15
AAAAAAAAAAAAAAA
-xxxxxxxxxxxxxx

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

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: