QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738564 | #9621. 连方 | konbi | AC ✓ | 9ms | 4472kb | C++20 | 3.4kb | 2024-11-12 19:23:53 | 2024-11-12 19:23:54 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
#define pb push_back
#define ls (u << 1)
#define rs (u << 1 | 1)
typedef long long LL;
typedef pair<int, int> PII;
// #define debug(args...) {}
#define debug(args...) { \
string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << ' ';
err(++it, args...);
}
void solve() {
int n; cin >> n;
int ca = 0, cb = 0;
string s; cin >> s;
string t; cin >> t;
for (auto ch : s) ca += ch == '.';
for (auto ch : t) cb += ch == '.';
if (!ca && !cb) {
cout << "Yes\n";
for (int i = 0; i < 7; i++) {
cout << s << "\n";
}
return ;
}
else if (!ca || !cb) {
cout << "No\n";
return ;
}
int cnt = 0;
for (int i = 0; i < n; i++) cnt += s[i] == t[i];
if (!cnt) {
cout << "Yes\n";
for (int i = 0; i < 6; i++) cout << s << "\n";
cout << t << "\n";
return ;
}
string ss = s, tt = t;
for (auto &ch : ss) ch = (ch == '.') ? '#' : '.';
for (auto &ch : tt) ch = (ch == '.') ? '#' : '.';
vector<string> ans(7);
ans[0] = s; ans[6] = t;
ans[1] = ss; ans[5] = tt;
ans[2] = ans[3] = ans[4] = s;
cnt = 0;
for (int i = 0; i < n; i++) cnt += ss[i] == '.' && tt[i] == '.';
int lst = 1, nxt = 5;
if (!cnt) ans[++lst] = s;
for (int i = 0; i < n; i++) {
if (ans[lst][i] != '.' || ans[nxt][i] != '.') continue;
int j = i;
while (j < n && ans[lst][j] == '.' && ans[nxt][j] == '.') j++;
int ok1 = (i && ans[lst][i - 1] == '#') || (j < n && ans[lst][j] == '#');
int ok2 = (i && ans[nxt][i - 1] == '#') || (j < n && ans[nxt][j] == '#');
// debug(i, j, ok1, ok2, nxt);
if (ok1 && !ok2) {
for (int b = 0; b < n; b++) ans[nxt - 1][b] = '.';
for (int b = j; b < n; b++) {
if (ans[nxt][b] == '#') break;
ans[nxt - 1][b] = '#';
}
for (int b = i - 1; b >= 0; b--) {
if (ans[nxt][b] == '#') break;
ans[nxt - 1][b] = '#';
}
nxt--;
}
else if (!ok1 && ok2) {
for (int b = 0; b < n; b++) ans[lst + 1][b] = '.';
for (int b = j; b < n; b++) {
if (ans[lst][b] == '#') break;
ans[lst + 1][b] = '#';
}
for (int b = i - 1; b >= 0; b--) {
if (ans[lst][b] == '#') break;
ans[lst + 1][b] = '#';
}
lst++;
}
for (int a = lst + 1; a < nxt; a++) {
for (int b = 0; b < n; b++) {
if (ans[lst][b] == '.' && ans[nxt][b] == '.') ans[a][b] = '#';
else ans[a][b] = '.';
}
}
break;
}
cout << "Yes\n";
for (int i = 0; i < 7; i++) cout << ans[i] << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1; cin >> tt;
while (tt--) solve();
return 0;
}
/*
g++ std.cpp -Wall --extra -o std && ./std < in.txt > out.txt
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
5 4 #..# .##. 5 ##.#. .#.## 6 ###### .####. 27 .######.######.####.#.##### .####...####..#.......##### 10 ########## ##########
output:
Yes #..# #..# #..# #..# #..# #..# .##. Yes ##.#. ..#.# .#.#. .#.#. .#.#. #.#.. .#.## No Yes .######.######.####.#.##### #......#......#....#.#..... .####...####..........##### .####...####..........##### .####...####..........##### #....###....##.#######..... .####...####..#.......##### Yes ########...
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 9ms
memory: 3720kb
input:
10000 6 .#..## ..#... 5 #..#. ##... 6 .###.# ...### 17 .####..#######..# ###########.##### 6 ..##.# #.##.# 25 #.##.##############.####. ####################.##.# 9 ##.#..##. ##..##### 6 .###.# ##.### 6 ###..# #.#### 25 #####################.#.# ######.################## 6 .#.### .##..# 6 ..#### #......
output:
Yes .#..## #.##.. .#..## ..#... ..#... ##.### ..#... Yes #..#. .##.# #..#. #..#. .#... ..### ##... Yes .###.# #...#. ...#.# ...#.# ...#.# ###... ...### Yes .####..#######..# #....##.......##. .####......###..# .####......###..# #....######...... ...........#..... ###########.##### Yes ..##.# ##..#. ...
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 9ms
memory: 3680kb
input:
10000 41 #######.#######.######################### ################.###.#######.############ 6 ..#..# #..##. 6 #.#... #...#. 6 .#.##. ....## 6 ...#.# ##..#. 33 #####.########################### ###########.##################### 6 .##.## .##.#. 5 ..##. ####. 17 #.###.##########. ####.##.#####.##. 5 ....
output:
Yes #######.#######.######################### .......#.......#......................... #######.........######################### #######.........######################### .......#########......................... ................#...#.......#............ ################.###.#######.############ Ye...
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 9ms
memory: 3656kb
input:
10000 6 ..#### .#.... 6 ...#.# #..##. 9 ..####.## ######..# 33 #######################.#####..## ######.######.###########.####### 6 ####.# #..##. 6 ...### ##.### 25 ######.#.#.############## .#########.##########.### 17 ############.#### ###############.# 6 #..#.# #####. 6 .#.### ..#... 49 ########...
output:
Yes ..#### ##.... ..#### .#.... .#.... #.#### .#.... Yes ...#.# ###.#. ...#.. ...#.. ...#.. .##..# #..##. Yes ..####.## ##....#.. ..####..# ..####..# ..####..# ......##. ######..# Yes #######################.#####..## .......................#.....##.. ......#################.......... ######...........
result:
ok Correct.
Test #5:
score: 0
Accepted
time: 9ms
memory: 3648kb
input:
10000 5 ...#. ##### 6 ###... ##..#. 9 .#.###### #.#..#### 49 ######.########################################## ########.#############.########################## 41 ###########.#######.##################### ##############.########################## 6 ###..# ###.## 49 #################################...
output:
No Yes ###... ...### ..#... ##..#. ##..#. ..##.# ##..#. Yes .#.###### #.#...... ...##.... #.#..#### #.#..#### .#.##.... #.#..#### Yes ######.########################################## ......#.......................................... ######..######################################### ######..########...
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 7ms
memory: 4392kb
input:
2 100000 ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.#...
output:
Yes ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 3ms
memory: 4472kb
input:
2 100000 ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##...
output:
Yes ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........
result:
ok Correct.