QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#252303#7714. Rikka with MirrorSolitaryDream#AC ✓4ms3900kbC++172.5kb2023-11-15 17:54:422023-11-15 17:54:42

Judging History

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

  • [2023-11-15 17:54:42]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3900kb
  • [2023-11-15 17:54:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 8;
const int S = 1 << 5;
int f[N][N][40][S][2];
string mp[N];
inline void ChkMax(int &x, int y) {
    x = max(x, y);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int Case;
    cin >> Case;
    while (Case--) {
        int n, m;
        cin >> m >> n;
        for (int i = 0; i < n; ++i) mp[i].resize(m);
        for (int j = 0; j < m; ++j) {
            string s;
            cin >> s;
            for (int i = 0; i < n; ++i) mp[i][j] = s[i];
        }
        for (int i = 0; i <= n; ++i)
            for (int j = 0; j < m; ++j)
                for (int k = 0; k <= n * m; ++k)
                    for (int s = 0; s < (1 << m); ++s)
                        for (int d = 0; d < 2; ++d)
                            f[i][j][k][s][d] = -1;
        f[0][0][0][0][0] = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = 0; k <= n * m; ++k)
                for (int s = 0; s < (1 << m); ++s)
                    f[i][0][k][s][1] = -1;
            for (int j = 0; j < m; ++j) {
                int ni = i, nj = j + 1;
                if (nj == m) ni = i + 1, nj = 0;
                for (int k = 0; k <= n * m; ++k)
                    for (int s = 0; s < (1 << m); ++s)
                        for (int d = 0; d < 2; ++d) if (f[i][j][k][s][d] >= 0) {
                            int val = f[i][j][k][s][d];
                            ChkMax(f[ni][nj][k][s][d], val + d + ((s >> j) & 1));
                            if (mp[i][j] == '1') {
                                int sj = s >> j & 1;
                                { /* type \ */
                                    int ns = s, nd = d;
                                    if (d != sj) nd ^= 1, ns ^= 1 << j;
                                    ChkMax(f[ni][nj][k + 1][ns][nd], val + d + sj);
                                }
                                { /* type / */
                                    if (d == sj) {
                                        ChkMax(f[ni][nj][k + 1][s & ~(1 << j)][0], val + d);
                                        ChkMax(f[ni][nj][k + 1][s |  (1 << j)][1], val + d + 1);
                                    }
                                }
                            }
                        }
            }
        }
        for (int k = 0, cur = 0; k <= n * m; ++k) {
            ChkMax(cur, f[n][0][k][0][0]);
            cout << 4 * n * m - 2 * cur << ' ';
        }
        cout << '\n';
    }
    return 0;
}

詳細信息

Test #1:

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

input:

2
3 3
101
011
101
4 4
1111
1111
1111
1111

output:

36 36 36 36 20 20 20 20 20 20 
64 64 64 64 40 40 40 40 32 32 32 32 24 24 24 24 24 

result:

ok 27 numbers

Test #2:

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

input:

100
1 1
1
1 2
11
1 3
111
1 4
1111
1 5
11111
1 6
111111
1 7
1111111
2 1
1
1
2 2
11
11
2 3
111
111
2 4
1111
1111
2 5
11111
11111
2 6
111111
111111
2 7
1111111
1111111
3 1
1
1
1
3 2
11
11
11
3 3
111
111
111
3 4
1111
1111
1111
3 5
11111
11111
11111
3 6
111111
111111
111111
3 7
1111111
1111111
1111111
4 ...

output:

4 4 
8 8 8 
12 12 12 12 
16 16 16 16 16 
20 20 20 20 20 20 
24 24 24 24 24 24 24 
28 28 28 28 28 28 28 28 
8 8 8 
16 16 16 16 8 
24 24 24 24 12 12 12 
32 32 32 32 16 16 16 16 16 
40 40 40 40 20 20 20 20 20 20 20 
48 48 48 48 24 24 24 24 24 24 24 24 24 
56 56 56 56 28 28 28 28 28 28 28 28 28 28 28 
1...

result:

ok 2411 numbers