QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674033#6309. Aqreji_114514#WA 1ms7636kbC++202.8kb2024-10-25 13:18:272024-10-25 13:18:29

Judging History

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

  • [2024-10-25 13:18:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7636kb
  • [2024-10-25 13:18:27]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 2e3 + 10;
int n, m, ans[N][N], te[N][N];
int p[] = {0, 3, 2, 4, 1};
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
bool vis[N][N];
bool check()
{
    int cnt = 0, u = 0, xt, yt;
    queue<int>q;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++) {
            cnt -= te[i][j];
            if (j >= 4)
            {
                int t[2] = {0};
                for (int k = 0; k < 4; k++)t[te[i][j - k]]++;
                if (!t[0] || !t[1])return 0;
            }
            if (i >= 4)
            {
                int t[2] = {0};
                for (int k = 0; k < 4; k++)t[te[i - k][j]]++;
                if (!t[0] || !t[1])return 0;
            }
            vis[i][j] = 0;
            if (te[i][j])u = (i - 1) * m + j, xt = i, yt = j;
        }
    }
    if (u)q.push(u), vis[xt][yt] = 1;
    while (!q.empty())
    {
        int u = q.front(); q.pop();
        cnt++;
        int x = (u - 1) / m + 1, y = (u - 1) % m + 1;
        for (int k = 0; k < 4; k++)
        {
            int nx = x + dx[k], ny = y + dy[k];
            if (nx == 0 || ny == 0 || nx > n || ny > m || vis[nx][ny] || te[nx][ny] == 0)continue;
            int v = (nx - 1) * m + ny;
            vis[nx][ny] = 1;
            q.push(v);
        }
    }
    return cnt == 0;
}

void solve()
{
    cin >> n >> m;
    int res = 0;
    for (int st = 0; st < 256; st++)
    {
        int temp = st;
        for (int i = 1; i <= 4; i++)
        {
            p[i] = temp % 4 + 1;
            temp /= 4;
        }
        int s = ((n + 3) / 4) * 4, t = ((m + 3) / 4) * 4;
        for (int i = 1; i <= s / 4; i++)
        {
            for (int k = 1; k <= 4; k++)
            {
                for (int j = 1; j <= t / 4; j++)
                {
                    for (int q = 1; q <= 4; q++)
                    {
                        int x = (i - 1) * 4 + k, y = (j - 1) * 4 + q;
                        if (p[k] == q)te[x][y] = 0;
                        else te[x][y] = 1;
                    }
                }
            }
        }
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
                cnt += te[i][j];
        }
        if (cnt > res && check() ) {
            res = cnt;
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= m; j++)ans[i][j] = te[i][j];
        }
    }
    cout << res << '\n';
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            cout << ans[i][j] << ' ';
        cout << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; cin >> t;
    while (t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7636kb

input:

3
2 2
3 4
3 8

output:

4
1 1 
1 1 
9
0 1 1 1 
0 1 1 1 
0 1 1 1 
18
1 1 0 1 1 1 0 1 
0 1 1 1 0 1 1 1 
0 1 1 1 0 1 1 1 

result:

wrong answer Length must be equal to m (test case 1)