QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574887 | #8935. Puzzle: Easy as Scrabble | hos_lyric | WA | 6ms | 30760kb | C++14 | 3.1kb | 2024-09-19 07:57:22 | 2024-09-19 07:57:22 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr int DX[4] = {+1, 0, -1, 0};
constexpr int DY[4] = {0, +1, 0, -1};
int M, N;
char A[1010][1010];
int f[1010][1010];
vector<pair<int, char>> ess[1010][1010];
queue<pair<int, int>> que;
bool go(int x, int y, int dir, char cond) {
if (cond == '.') return true;
for (; ; ) {
if (!(0 < x && x < M && 0 < y && y < N)) {
return false;
}
if (A[x][y] == '.') {
ess[x][y].emplace_back(dir, cond);
f[x][y] |= 1 << (cond - 'A');
if (f[x][y] & (f[x][y] - 1)) {
A[x][y] = 'x';
que.emplace(x, y);
}
return true;
}
x += DX[dir];
y += DY[dir];
}
}
bool solve() {
for (int x = 0; x <= M; ++x) for (int y = 0; y <= N; ++y) {
f[x][y] = 0;
ess[x][y].clear();
}
que = {};
for (int x = 1; x <= M-1; ++x) {
if (!go(x, 1 , 1, A[x][0])) return false;
if (!go(x, N-1, 3, A[x][N])) return false;
}
for (int y = 1; y <= N-1; ++y) {
if (!go(1 , y, 0, A[0][y])) return false;
if (!go(M-1, y, 2, A[M][y])) return false;
}
for (; que.size(); ) {
const int x = que.front().first;
const int y = que.front().second;
que.pop();
for (const auto &e : ess[x][y]) {
if (!go(x, y, e.first, e.second)) return false;
}
}
for (int x = 1; x < M; ++x) for (int y = 1; y < M; ++y) if (A[x][y] != 'x') {
A[x][y] = f[x][y] ? ('A' + __builtin_ctz(f[x][y])) : '.';
}
// for(int x=0;x<=M;++x)cerr<<A[x]<<endl;
return true;
}
int main() {
for (; ~scanf("%d%d", &M, &N); ) {
++M;
++N;
for (int x = 0; x <= M; ++x) {
scanf("%s", A[x]);
}
const bool res = solve();
if (res) {
puts("YES");
for (int x = 1; x < M; ++x) {
for (int y = 1; y < N; ++y) if (A[x][y] == 'x') A[x][y] = '.';
A[x][N] = 0;
puts(A[x] + 1);
}
} else {
puts("NO");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 29284kb
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: 3ms
memory: 30760kb
input:
1 2 .... Nx.. ..O.
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 6ms
memory: 29192kb
input:
5 5 .U.N.X. U....xX Ox....X M...xxN Vx....S Ix.x..X ..IBHX.
output:
YES U.NX. .O..X M.N.. .VB.S .I.HX
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 3ms
memory: 28992kb
input:
10 10 .BAZEMIEKUJ. A..........K B..x.x.x..x. K.........xT A.x..x.....J Hx....x....B Q..x....x.xW S...x......W S...x.xxx..Z ...x......xZ I..x..x.x.xR .QKO.ID..RW.
output:
YES .AZEMIEK.. B.......U. K.......T. A........J .H.......B Q.......W. S........W S.O.....Z. QK...D..Z. ...II...R.
result:
ok Correct.
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 28812kb
input:
5 10 .PTWIVVISPY. T...x.x....Y Xx.x.xx..x.K P.x.xx.....K S..........A E.........xS .SPEASDCYSA.
output:
YES .TW.V..... .X.I...... P......... SP........ ..EAS.....
result:
wrong answer Row 1 right clue not satisfied.