QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#544361 | #8935. Puzzle: Easy as Scrabble | ucup-team4821# | WA | 0ms | 3568kb | C++20 | 3.2kb | 2024-09-02 15:38:21 | 2024-09-02 15:38:22 |
Judging History
answer
#include <bits/stdc++.h>
int n, m, L[1005], R[1005], U[1005], D[1005];
char a[1005][1005], l[1005], r[1005], u[1005], d[1005];
std::queue<std::pair<int, int>> que;
void NO()
{
std::cout << "NO" << std::endl;
exit(0);
}
void set(int x, int y)
{
if (a[x][y] != 'x')
{
a[x][y] = 'x';
que.push({x, y});
}
}
void updatel(int p)
{
while (L[p] < m && a[p][L[p] + 1] == 'x')
++L[p];
if (L[p] == m)
NO();
int q = L[p] + 1;
if (U[q] + 1 == p && l[p] != '.' && u[q] != '.' && l[p] != u[q])
set(p, q);
if (n - D[q] == p && l[p] != '.' && d[q] != '.' && l[p] != d[q])
set(p, q);
}
void updater(int p)
{
while (R[p] < m && a[p][m - R[p]] == 'x')
++R[p];
if (R[p] == m)
NO();
int q = m - R[p];
if (U[q] + 1 == p && r[p] != '.' && u[q] != '.' && r[p] != u[q])
set(p, q);
if (n - D[q] == p && r[p] != '.' && d[q] != '.' && r[p] != d[q])
set(p, q);
}
void updateu(int q)
{
while (U[q] < n && a[U[q] + 1][q] == 'x')
++U[q];
if (U[q] == n)
NO();
int p = U[q] + 1;
if (L[p] + 1 == q && u[q] != '.' && l[p] != '.' && u[q] != l[p])
set(p, q);
if (m - R[p] == q && u[q] != '.' && r[p] != '.' && u[q] != r[p])
set(p, q);
}
void updated(int q)
{
while (D[q] < n && a[n - D[q]][q] == 'x')
++D[q];
if (D[q] == n)
NO();
int p = n - D[q];
if (L[p] + 1 == q && u[q] != '.' && l[p] != '.' && u[q] != l[p])
set(p, q);
if (m - R[p] == q && u[q] != '.' && r[p] != '.' && u[q] != r[p])
set(p, q);
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin >> n >> m;
for (int i = 0; i <= n + 1; ++i)
for (int j = 0; j <= m + 1; ++j)
std::cin >> a[i][j];
for (int i = 1; i <= n; ++i)
l[i] = a[i][0];
for (int i = 1; i <= n; ++i)
r[i] = a[i][m + 1];
for (int i = 1; i <= m; ++i)
u[i] = a[0][i];
for (int i = 1; i <= m; ++i)
d[i] = a[n + 1][i];
for (int i = 1; i <= n; ++i)
updatel(i);
for (int i = 1; i <= n; ++i)
updater(i);
for (int i = 1; i <= m; ++i)
updateu(i);
for (int i = 1; i <= m; ++i)
updated(i);
while (!que.empty())
{
std::pair<int, int> now = que.front();
que.pop();
updatel(now.first);
updater(now.first);
updateu(now.second);
updated(now.second);
}
for (int i = 1; i <= n; ++i)
if (l[i] != '.')
a[i][L[i] + 1] = l[i];
for (int i = 1; i <= n; ++i)
if (r[i] != '.')
a[i][m - R[i]] = r[i];
for (int i = 1; i <= m; ++i)
if (u[i] != '.')
a[U[i] + 1][i] = u[i];
for (int i = 1; i <= m; ++i)
if (d[i] != '.')
a[n - D[i]][i] = d[i];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (a[i][j] == 'x')
a[i][j] = '.';
for (int i = 1; i <= n; ++i, std::cout << std::endl)
for (int j = 1; j <= m; ++j)
std::cout << a[i][j];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3568kb
input:
5 5 .CBA... ....x.. ..x...C A.....B B..x..A C...... .......
output:
CBA.. ....C A...B B...A C....
result:
wrong answer YES or NO expected in answer, but CBA.. found.