QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#737302 | #9621. 连方 | Kotomi | AC ✓ | 6ms | 4264kb | C++20 | 1.9kb | 2024-11-12 15:24:11 | 2024-11-12 15:24:12 |
Judging History
answer
#include <bits/stdc++.h>
int count(std::string &s, char c) {
int cnt = 0;
for (char x : s) {
if (x == c) {
++cnt;
}
}
return cnt;
}
void solve() {
int n;
std::string a, b;
std::cin >> n >> a >> b;
// if (a == b) {
// std::cout << "Yes\n";
// for (int i = 0; i < 7; ++i) {
// std::cout << a << '\n';
// }
// return;
// }
int cnt1 = count(a, '#');
int cnt2 = count(b, '#');
if ((cnt1 == n and cnt2 < n) or (cnt1 < n and cnt2 == n)) {
std::cout << "No\n";
return;
}
std::cout << "Yes\n";
if (cnt1 == n and cnt2 == n) {
for (int i = 1; i <= 7; ++i) {
std::cout << std::string(n, '#') << '\n';
}
return;
}
auto ans = std::vector(7, std::string(n, '.'));
ans[0] = a, ans[6] = b;
int pos1 = -1, pos2 = -1;
{
auto &x = ans[1], &y = ans[5];
for (int i = 0; i < n; ++i) {
x[i] = a[i] == '#' ? '.' : '#';
y[i] = b[i] == '#' ? '.' : '#';
}
auto check = [&](std::string &s, int p) {
int n = s.size();
if (p == 0)
return s[0] == '.' and s[1] == '#';
if (p == n - 1)
return s[p] == '.' and s[p - 1] == '#';
return s[p] == '.' and (s[p - 1] == '#' or s[p + 1] == '#');
};
for (int i = 0; i < n; ++i) {
if (pos1 == -1 and check(x, i)) {
pos1 = i;
}
if (pos2 == -1 and check(y, i)) {
pos2 = i;
}
}
}
{
auto &x = ans[2], &y = ans[4];
x[pos1] = y[pos2] = '#';
auto &z = ans[3];
if (std::abs(pos1 - pos2) > 1) {
for (int i = std::min(pos1, pos2) + 1; i < std::max(pos1, pos2); ++i) {
z[i] = '#';
}
} else {
z[pos1] = '#';
}
}
for (auto &s : ans) {
std::cout << s << '\n';
}
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int T;
std::cin >> T;
while (T--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
5 4 #..# .##. 5 ##.#. .#.## 6 ###### .####. 27 .######.######.####.#.##### .####...####..#.......##### 10 ########## ##########
output:
Yes #..# .##. #... #... .#.. #..# .##. Yes ##.#. ..#.# .#... .#... .#... #.#.. .#.## No Yes .######.######.####.#.##### #......#......#....#.#..... .#......................... .#......................... .#......................... #....###....##.#######..... .####...####..#.......##### Yes ########...
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 6ms
memory: 3708kb
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: 3ms
memory: 3640kb
input:
10000 41 #######.#######.######################### ################.###.#######.############ 6 ..#..# #..##. 6 #.#... #...#. 6 .#.##. ....## 6 ...#.# ##..#. 33 #####.########################### ###########.##################### 6 .##.## .##.#. 5 ..##. ####. 17 #.###.##########. ####.##.#####.##. 5 ....
output:
Yes #######.#######.######################### .......#.......#......................... ......#.................................. .......########.......................... ...............#......................... ................#...#.......#............ ################.###.#######.############ Ye...
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 6ms
memory: 3868kb
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: 6ms
memory: 3704kb
input:
10000 5 ...#. ##### 6 ###... ##..#. 9 .#.###### #.#..#### 49 ######.########################################## ########.#############.########################## 41 ###########.#######.##################### ##############.########################## 6 ###..# ###.## 49 #################################...
output:
No Yes ###... ...### ..#... ..#... .#.... ..##.# ##..#. Yes .#.###### #.#...... .#....... .#....... #........ .#.##.... #.#..#### Yes ######.########################################## ......#.......................................... .....#........................................... ......#............
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 3ms
memory: 4264kb
input:
2 100000 ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.#...
output:
Yes ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 3ms
memory: 4232kb
input:
2 100000 ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##...
output:
Yes ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........
result:
ok Correct.