QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607460 | #8935. Puzzle: Easy as Scrabble | lllei# | WA | 1ms | 3628kb | C++20 | 3.4kb | 2024-10-03 14:58:28 | 2024-10-03 14:58:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n,m;
cin >>n >>m;
vector<string> s(n + 2);
for (int i = 0; i <= n + 1; ++i) {
cin >> s[i];
}
vector<bool> vis(m + 2);
vector<char> chr(m + 2);
for (int i = 1; i <= m; ++i) {
chr[i] = s[0][i];
}
vector<string> ans(n + 2, string(m + 2, '.'));
vector<int> pp1(n + 2), pp2(n + 2);
for (int i = 1; i <= n; ++i) {
char ch = s[i][0];
bool f = false;
int p1 = 0, p2 = m + 1;
if (s[i][0] != '.') {
for (int j = 1; j <= m; ++j) {
if (s[i][j] == 'x') {
continue;
}
if ((!vis[j] && (chr[j] == ch || chr[j] == '.')) || vis[j]) {
vis[j] = true;
ans[i][j] = ch;
f = true;
p1 = j;
break;
}
}
} else {
f = true;
}
if (!f) {
cout << "NO\n";
return 0;
}
f = false;
ch = s[i][m + 1];
if (ch != '.') {
for (int j = m; j >= 1; --j) {
if (s[i][j] == 'x') {
continue;
}
if ((!vis[j] && (chr[j] == ch || chr[j] == '.')) || vis[j]) {
vis[j] = true;
ans[i][j] = ch;
f = true;
p2 = j;
break;
}
}
} else {
f = true;
}
if (!f) {
cout << "NO\n";
return 0;
}
if (p1 > p2) {
cout << "NO\n";
return 0;
}
if (p1 == p2) {
if (s[i][0] != s[i][m + 1]) {
cout << "NO\n";
return 0;
}
}
// cout<<p1<<" "<<p2<<'\n';
//cout<<ans[2][5]<<'\n';
for (int k = p1 + 1; k < p2; ++k) {
if (s[i][k] == 'x' || vis[k] || chr[k] == '.') {
continue;
}
ans[i][k] = chr[k];
vis[k] = true;
}
pp1[i] = p1, pp2[i] = p2;
}
for (int i = 1; i <= m; ++i) {
if (s[0][i] != '.' && !vis[i]) {
cout << "NO\n";
return 0;
}
}
for (int i = 1; i <= m; ++i) {
if (s[n + 1][i] == '.') {
continue;
}
char ch = s[n + 1][i];
bool f = false;
for (int j = n; j >= 1; --j) {
if (s[j][i] == 'x') {
continue;
}
if (ans[j][i] == ch) {
f = true;
break;
} else if (ans[j][i] == '.') {
if (pp1[j] < i && i < pp2[j]) {
f = true;
ans[j][i] = ch;
break;
}
} else {
f = false;
break;
}
}
if (!f) {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m;++j) {
cout << ans[i][j];
}
cout << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
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: 1ms
memory: 3624kb
input:
1 2 .... Nx.. ..O.
output:
NO
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3624kb
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: -100
Wrong Answer
time: 1ms
memory: 3568kb
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:
NO
result:
wrong answer Jury has answer but participant has not.