QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625906#8935. Puzzle: Easy as ScrabblejysWA 1ms3728kbC++144.5kb2024-10-09 21:40:212024-10-09 21:40:23

Judging History

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

  • [2024-10-09 21:40:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3728kb
  • [2024-10-09 21:40:21]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1e3 + 10, INF = 0x3f3f3f3f, mod = 998244353;

char grid[N][N];

char cluex[2][N], cluey[2][N];
int row[2][N], col[2][N];

int n, m;

bool deal_up(int j)
{
    if (cluex[0][j] != '.')
    {
        if (grid[row[0][j]][j] == cluex[0][j])
            return true;

        while (grid[row[0][j]][j] == 'x' && row[0][j] <= n)
            row[0][j]++;
        if (row[0][j] <= n && grid[row[1][j]][j] == '.')
        {
            grid[row[0][j]][j] = cluex[0][j];
            return true;
        }
        else if (row[0][j] > n)
        {
            cout << "NO";
            exit(0);
        }
        else
        {
            grid[row[0][j]][j] = 'x';
            return false;
        }
    }
    else
        return true;
}

bool deal_down(int j)
{
    if (cluex[1][j] != '.')
    {
        if (grid[row[1][j]][j] == cluex[1][j])
            return true;

        while (grid[row[1][j]][j] == 'x' && row[1][j] >= 0)
            row[1][j]--;
        if (row[1][j] >= 1 && grid[row[1][j]][j] == '.')
        {
            grid[row[1][j]][j] = cluex[1][j];
            return true;
        }

        else if (row[1][j] < 1)
        {
            cout << "NO";
            exit(0);
        }
        else
        {
            grid[row[1][j]][j] = 'x';
            return false;
        }
    }
    else
        return true;
}

bool deal_left(int i)
{
    if (cluey[0][i] != '.')
    {
        if (grid[i][col[0][i]] == cluey[0][i])
            return true;

        while (grid[i][col[0][i]] == 'x' && col[0][i] <= m)
            col[0][i]++;
        if (col[0][i] <= m && grid[i][col[0][i]] == '.')
        {
            grid[i][col[0][i]] = cluey[0][i];
            return true;
        }
        else if (col[0][i] > m)
        {
            cout << "NO";
            exit(0);
        }
        else
        {
            grid[i][col[0][i]] = 'x';
            return false;
        }
    }
    else
        return true;
}

bool deal_right(int i)
{
    if (cluey[1][i] != '.')
    {
        if (grid[i][col[1][i]] == cluey[1][i])
            return true;

        while (grid[i][col[1][i]] == 'x' && col[1][i] >= 0)
            col[1][i]--;
        if (col[1][i] >= 1 && grid[i][col[1][i]] == '.')
        {
            grid[i][col[1][i]] = cluey[1][i];
            return true;
        }
        else if (col[1][i] < 1)
        {
            cout << "NO";
            exit(0);
        }
        else
        {
            grid[i][col[1][i]] = 'x';
            return false;
        }
    }
    else
        return true;
}

void solve()
{
    cin >> n >> m;

    for (int i = 0; i < n + 2; ++i)
    {
        for (int j = 0; j < m + 2; ++j)
        {
            char tmp;
            cin >> tmp;
            if (j == 0)
                cluey[0][i] = tmp;
            if (j == m + 1)
                cluey[1][i] = tmp;
            if (i == 0)
                cluex[0][j] = tmp;
            if (i == n + 1)
                cluex[1][j] = tmp;

            if (i > 0 && i < n + 1 && j > 0 && j < m + 1)
            {
                grid[i][j] = tmp;
            }
        }
    }

    for (int j = 0; j < n + 2; ++j)
    {
        row[0][j] = 1;
        row[1][j] = n;
    }
    for (int j = 0; j < m + 2; ++j)
    {
        col[0][j] = 1;
        col[1][j] = m;
    }

    for (int j = 0; j < m + 2; ++j)
    {
        while (1)
        {
            bool f1 = deal_up(j), f2 = deal_down(j), f3 = deal_left(row[0][j]), f4 = deal_right(row[1][j]);
            if (f1 && f2 && f3 && f4)
                break;
        }
    }
    for (int i = 0; i < n + 2; ++i)
    {
        while (1)
        {
            bool f1 = deal_left(i), f2 = deal_right(i), f3 = deal_up(col[0][i]), f4 = deal_down(col[1][i]);
            if (f1 && f2 && f3 && f4)
                break;
        }
    }

    cout << "YES" << '\n';
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (grid[i][j] == 'x')
                grid[i][j] = '.';
            cout << grid[i][j];
        }
        cout << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tcase = 1;
    // cin >> tcase;
    while (tcase--)
        solve();
}

詳細信息

Test #1:

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

input:

5 5
.CBA...
....x..
..x...C
A.....B
B..x..A
C......
.......

output:

YES
CBA..
....C
A...B
B...A
C....

result:

ok Correct.

Test #2:

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

input:

1 2
....
Nx..
..O.

output:

NO

result:

ok Correct.

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3672kb

input:

5 5
.U.N.X.
U....xX
Ox....X
M...xxN
Vx....S
Ix.x..X
..IBHX.

output:

NO

result:

wrong answer Jury has answer but participant has not.