QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744066 | #5810. Doubly-sorted Grid | 10circle | 0 | 12551ms | 16644kb | C++14 | 1.8kb | 2024-11-13 20:44:53 | 2024-11-13 20:44:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vint;
int read() {
int a = 0, b = 0; char c = getchar();
while (c < '0' || c > '9') b ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9') a = a * 10 - 48 + c, c = getchar();
return b ? -a : a;
}
const int mod = 10007, K = 1 << 20;
int n, m, ans;
char s[12][12];
int dp[2][K], popc[K];
int cu[1024], lb[1024];
int sol(){
n = read(), m = read(), ans = 0;
for (int i = 0; i < n; i++) scanf("%s", s[i]);
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if('a' <= s[i][j] && s[i][j] <= 'z') s[i][j] -= 'a';
int u = n + m, o = 1 << u;
memset(dp, 0, sizeof dp);
static vint q;
q.clear(); for (int j = 0; j < o; ++j) if (popc[j] == m) q.push_back(j);
int *A = dp[0], *B = dp[1];
A[(1 << m) - 1] = 1;
for (int i = 0; i < 26; i++) {
memcpy(B, A, o << 2);
for (int j : q) {
int c[10] = {}, ct = 0, re = 0, ag = 0;
int rr = 0;
for (int k = 1; k < u; k++) {
re += (j >> k - 1) & 1;
if (!((j >> k - 1) & 1) && ((j >> k) & 1)) {
int q = m - re - 1;
int p = k - re - 1;
if (s[p][q] != '.' && s[p][q] != i) continue;
if (s[p][q] == i) { rr ^= ((1 << k) | (1 << k - 1)); continue; }
c[ct++] = (1 << k) | (1 << k - 1);
}
}
int p = 1 << ct;
for (int k = 1; k < p; k++) {
if (k == (k & -k)) cu[k] = c[lb[k]];
else cu[k] = cu[k & k - 1] ^ cu[k & -k];
int q = B[cu[k] ^ j ^ rr];
B[j] += (popc[k] & 1) ? q : mod - q;
}
B[j] %= mod;
}
swap(A, B);
}
return A[(1 << m) - 1 << n];
}
int main() {
for (int i = 1; i < K; ++i) popc[i] = popc[i & i - 1] + 1;
for (int i = 2; i < 1024; i++) lb[i] = lb[i >> 1] + 1;
int T = read();
for (int i = 1; i <= T; i++) {
printf("Case #%d: %d\n", i, sol());
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 16152kb
input:
40 4 4 .... .... .... .... 4 4 abcd bcde cdef defg 4 4 bbcc ccde cdef deef 4 4 .... .... .r.. ..e. 3 4 .... .... ...g 1 3 f.. 2 2 .b bb 2 3 ... ..f 4 4 .... .... ..t. ..d. 3 3 .gn ... ... 4 4 ...a ...b ...c ...d 4 4 ...b ..bb .bbb bbbb 4 4 a... .b.. ..c. ...d 3 3 c.. glw ..w 1 4 .... 1 3 d.v 4 2 .. ...
output:
Case #1: 7285 Case #2: 0 Case #3: 0 Case #4: 0 Case #5: 0 Case #6: 0 Case #7: 0 Case #8: 0 Case #9: 0 Case #10: 330 Case #11: 0 Case #12: 0 Case #13: 0 Case #14: 0 Case #15: 3737 Case #16: 0 Case #17: 8175 Case #18: 3737 Case #19: 0 Case #20: 0 Case #21: 0 Case #22: 0 Case #23: 0 Case #24: 0 Case #2...
result:
wrong answer 2nd lines differ - expected: 'Case #2: 1', found: 'Case #2: 0'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 12551ms
memory: 16644kb
input:
40 5 10 .......... .......... .......... .......... .......... 10 10 ....a..... ....c..... ....g..... ....j..... ....l..... ....m..... ....n..... ....q..... ....t..... ....v..... 10 10 .......... .......... .......... .......... .......... .......... .......... .......... ...ok..... .......... 9 10 ...
output:
Case #1: 8791 Case #2: 3641 Case #3: 0 Case #4: 0 Case #5: 0 Case #6: 0 Case #7: 4447 Case #8: 0 Case #9: 0 Case #10: 0 Case #11: 3965 Case #12: 0 Case #13: 0 Case #14: 4458 Case #15: 8699 Case #16: 0 Case #17: 0 Case #18: 0 Case #19: 798 Case #20: 0 Case #21: 0 Case #22: 0 Case #23: 0 Case #24: 167...
result:
wrong answer 2nd lines differ - expected: 'Case #2: 7220', found: 'Case #2: 3641'