QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645921#7052. Xian XiangSGColinAC ✓840ms5064kbC++172.9kb2024-10-16 20:28:092024-10-16 20:28:13

Judging History

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

  • [2024-10-16 20:28:13]
  • 评测
  • 测评结果:AC
  • 用时:840ms
  • 内存:5064kb
  • [2024-10-16 20:28:09]
  • 提交

answer

#include <bits/stdc++.h>
#define N 20
using namespace std;

inline int rd() {
    int x = 0;
    bool f = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) f |= (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    return f ? -x : x;
}

string ss[100];

int mp[N][N], w[N][N], v[N];

int r[N][N][N], c[N][N][N], f[1 << 18];

int x[N], y[N];

void work() {
    int n = rd();
    int m = rd();
    int K = rd();
    int idcnt = -1;
    string s;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j) {
            cin >> s;
            if (s[0] == '-') mp[i][j] = -1;
            else {
                mp[i][j] = ++idcnt;
                ss[idcnt] = s;
                x[idcnt] = i;
                y[idcnt] = j;
            }
        }
    for (int i =0; i <= K; ++i) v[i] = rd();
    for (int i = 0; i <= idcnt; ++i)
        for (int j = 0; j <= idcnt; ++j) {
            w[i][j] = 0;
            for (int k = 0; k < K; ++k) w[i][j] += (ss[i][k] == ss[j][k]);
            w[i][j] = v[w[i][j]];
        }
    memset(r, 0, sizeof(r));
    memset(c, 0, sizeof(c));
    for (int x = 1; x <= n; ++x)
        for (int y = 1; y <= m; ++y) {
            if (mp[x][y] == -1) continue;
            //go left
            for (int t = y - 1; t; --t)
                r[x][y][t] = r[x][y][t + 1] + (mp[x][t] >= 0 ? (1 << mp[x][t]) : 0);
            //go right
            for (int t = y + 1; t <= m; ++t)
                r[x][y][t] = r[x][y][t - 1] + (mp[x][t] >= 0 ? (1 << mp[x][t]) : 0);
            //go up
            for (int t = x - 1; t; --t)
                c[x][y][t] = c[x][y][t + 1] + (mp[t][y] >= 0 ? (1 << mp[t][y]) : 0);
            //go down
            for (int t = x + 1; t <= n; ++t)
                c[x][y][t] = c[x][y][t - 1] + (mp[t][y] >= 0 ? (1 << mp[t][y]) : 0);
        }
    int S = (1 << (idcnt + 1)) - 1;
    memset(f, 0xcf, sizeof(f));
    f[0] = 0;
    for (int s = 0; s <= S; ++s) {
        for (int i = 0; i <= idcnt; ++i) {
            if (s & (1 << i)) continue;
            for (int j = i + 1; j <= idcnt; ++j) {
                if (s & (1 << j)) continue;
                bool fl = 0;

                int ts = (s | ((1 << i) | (1 << j)));
                int xa = x[i], ya = y[i];
                int xb = x[j], yb = y[j];
                int tars = (r[xa][ya][yb] | c[xb][yb][xa]);
                if ((ts & tars) == tars) fl = 1;
                tars = (r[xb][yb][ya] | c[xa][ya][xb]);
                if ((ts & tars) == tars) fl = 1;

                if (fl) {
                   // printf("%d -> %d %d %d %d + %d\n", s, ts, i, j, f[s], w[i][j]);
                    f[ts] = max(f[ts], f[s] + w[i][j]);
                }
            }
        }
    }
    printf("%d\n", f[S]);
}

int main() {
    for (int t = rd(); t; t--) work();
    return 0;
}

/*
1
2 2 3
aaa aaa
bbb bbb
1 10 100 1000
*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 2 3
aaa aaa
bbb bbb
1 10 100 1000
2 3 3
aaa --- bbb
bbb --- aaa
1 10 100 1000
1 4 3
aaa bba abb aaa
1 10 100 1000

output:

2000
2
1010

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 840ms
memory: 5064kb

input:

20
5 6 5
dbdaa cbcdc ----- dadad dbdaa bdbcc
dbbdc aadcc dbbdc bdbad ----- -----
bccad abdab ----- bbdda ----- ddcbd
adcbb ----- ----- ----- bdbcc -----
----- ----- bbdda ----- ----- -----
156 1333 2713 2853 3242 9881
6 7 4
---- acaa ---- ---- ---- ---- ----
accc accc dcda ---- cbcb bbda ----
bbda d...

output:

49276
65059
38746
34398
39744
73820
31466
33302
43342
26102
45570
69039
61574
63160
66552
57157
69615
76688
79535
34563

result:

ok 20 lines