QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741615 | #9621. 连方 | 123BVN | AC ✓ | 23ms | 4260kb | C++23 | 1.9kb | 2024-11-13 14:47:31 | 2024-11-13 14:47:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
using namespace std;
const int N = 100000 + 10;
const int M = 3000 + 10;
void solve() {
int n;
string s1, s2;
cin >> n;
cin >> s1 >> s2;
int c1 = 0, c2 = 0;
for (int i = 0; i < n; i++) {
if (s1[i] == '#')c1++;
if (s2[i] == '#')c2++;
}
if (c1 == n || c2 == n) {
if (c1 == n && c2 == n) {
cout << "Yes" << endl;
for (int i = 1; i <= 7; i++)cout << s1 << endl;
}
else cout << "No" << endl;
}
else {
cout << "Yes" << endl;
c1 = c2 = 1;
queue<string>ans;
ans.push(s1);
for (int i = 0; i <n; i++) {
if (s1[i] == '#')s1[i] = '.';
else s1[i] = '#';
if (s2[i] == '#')s2[i] = '.';
else s2[i] = '#';
}
ans.push(s1);
for (int i = 0; i < n; i++) {
if (s1[i] == '.' && (i + 1 < n && s1[i + 1] == '#' || i - 1 >= 0 && s1[i - 1] == '#'))c1 = i;
if (s2[i] == '.' && (i + 1 < n && s2[i + 1] == '#' || i - 1 >= 0 && s2[i - 1] == '#'))c2 = i;
}
for (int i = 0; i < n; i++) s1[i] = '.';
s1[c1] = '#';
ans.push(s1);
s1[c1] = '.';
int l, r;
l = min(c1, c2);
r = max(c1, c2);
if (r - l <= 1) {
s1[c2] = '#';
ans.push(s1);
s1[c2] = '.';
}
else {
for (int i = l + 1; i < r; i++)s1[i] = '#';
ans.push(s1);
for (int i = l + 1; i < r; i++)s1[i] = '.';
}
s1[c2] = '#';
ans.push(s1);
ans.push(s2);
for (int i = 0; i < n; i++) {
if (s1[i] == '#')s1[i] = '.';
else s1[i] = '#';
if (s2[i] == '#')s2[i] = '.';
else s2[i] = '#';
}
ans.push(s2);
while (!ans.empty()) {
cout << ans.front() << endl;
ans.pop();
}
}
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
/*
4
4
#..#
.##.
5
##.#.
.#.##
6
######
.####.
27
.######.######.####.#.#####
.####...####..#.......#####
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
5 4 #..# .##. 5 ##.#. .#.## 6 ###### .####. 27 .######.######.####.#.##### .####...####..#.......##### 10 ########## ##########
output:
Yes #..# .##. ...# ..#. ..#. #..# .##. Yes ##.#. ..#.# ...#. ...#. ...#. #.#.. .#.## No Yes .######.######.####.#.##### #......#......#....#.#..... ......................#.... ......................#.... ......................#.... #....###....##.#######..... .####...####..#.......##### Yes ########...
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 23ms
memory: 3900kb
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: 8ms
memory: 3676kb
input:
10000 41 #######.#######.######################### ################.###.#######.############ 6 ..#..# #..##. 6 #.#... #...#. 6 .#.##. ....## 6 ...#.# ##..#. 33 #####.########################### ###########.##################### 6 .##.## .##.#. 5 ..##. ####. 17 #.###.##########. ####.##.#####.##. 5 ....
output:
Yes #######.#######.######################### .......#.......#......................... ................#........................ .................############............ .............................#........... ................#...#.......#............ ################.###.#######.############ Ye...
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 15ms
memory: 3892kb
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: 11ms
memory: 3860kb
input:
10000 5 ...#. ##### 6 ###... ##..#. 9 .#.###### #.#..#### 49 ######.########################################## ########.#############.########################## 41 ###########.#######.##################### ##############.########################## 6 ###..# ###.## 49 #################################...
output:
No Yes ###... ...### ..#... ...#.. ....#. ..##.# ##..#. Yes .#.###### #.#...... ...#..... ....#.... .....#... .#.##.... #.#..#### Yes ######.########################################## ......#.......................................... .......#......................................... ........########...
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 0ms
memory: 4260kb
input:
2 100000 ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.#...
output:
Yes ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 3ms
memory: 4172kb
input:
2 100000 ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##...
output:
Yes ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........
result:
ok Correct.