QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#770221 | #9621. 连方 | proven# | AC ✓ | 26ms | 10700kb | C++20 | 2.6kb | 2024-11-21 21:10:03 | 2024-11-21 21:10:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int mod = 998244353;
void solve() {
int n; cin >> n;
string a, b;
cin >> a >> b;
vector<vector<int> > ans(8, vector<int> (n + 1));
a = ' ' + a;
b = ' ' + b;
for(int i = 1;i <= n;i++) {
if(a[i] == '#') ans[1][i] = 1;
if(b[i] == '#') ans[7][i] = 1;
}
auto out = [&] () {
for(int i = 1;i <= 7;i++) {
for(int j = 1;j <= n;j++) {
if(ans[i][j]) cout << '#';
else cout << ".";
}
cout << endl;
}
};
int x = 0, y = 0;
for(int i = 1;i <= n;i++) {
x += (a[i] == '#');
y += (b[i] == '#');
}
if(x == 0) {
cout << "Yes" << endl;
for(int i = 1;i <= n;i++) {
ans[6][i] = ans[7][i] ^ 1;
}
out();
return;
}
if(x == n) {
if(y == n || y == 0) {
cout << "Yes" << endl;
for(int j = 2;j <= 6;j++) {
for(int i = 1;i <= n;i++) ans[j][i] = 1;
}
out();
}
else {
cout << "No" << endl;
}
return;
}
if(y == n) {
if(x == n || x == 0) {
cout << "Yes" << endl;
for(int j = 2;j <= 6;j++) {
for(int i = 1;i <= n;i++) ans[j][i] = 1;
}
out();
}
else {
cout << "No" << endl;
}
return;
}
for(int i = 1;i <= n;i++) {
ans[2][i] = ans[1][i] ^ 1;
ans[6][i] = ans[7][i] ^ 1;
}
int mn = 1e9, mx = 0;
for(int i = 1;i < n;i++) {
if(ans[2][i] && !ans[2][i + 1]) mn = min(mn, i + 1);
if(ans[6][i] && !ans[6][i + 1]) mx = max(mx, i + 1);
if(ans[2][i+1] && !ans[2][i]) mn = min(mn, i);
if(ans[6][i+1] && !ans[6][i]) mx = max(mx, i);
}
ans[3][mn] = 1;
ans[5][mx] = 1;
if(mn > mx) swap(mn, mx);
if(mn == mx) {
ans[4][mn] = 1;
}
else {
if(abs(mn - mx) == 1) ans[4][mn] = 1;
else {
for(int i = mn + 1;i < mx;i++) ans[4][i] = 1;
}
}
cout << "Yes" << endl;
out();
}
/*
4
4
#..#
.##.
5
##.#.
.#.##
6
######
.####.
27
.######.######.####.#.#####
.####...####..#.......#####
*/
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
5 4 #..# .##. 5 ##.#. .#.## 6 ###### .####. 27 .######.######.####.#.##### .####...####..#.......##### 10 ########## ##########
output:
Yes #..# .##. #... .#.. ..#. #..# .##. Yes ##.#. ..#.# .#... ..#.. ...#. #.#.. .#.## No Yes .######.######.####.#.##### #......#......#....#.#..... .#......................... ..####################..... ......................#.... #....###....##.#######..... .####...####..#.......##### Yes ########...
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 22ms
memory: 3760kb
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: 23ms
memory: 3812kb
input:
10000 41 #######.#######.######################### ################.###.#######.############ 6 ..#..# #..##. 6 #.#... #...#. 6 .#.##. ....## 6 ...#.# ##..#. 33 #####.########################### ###########.##################### 6 .##.## .##.#. 5 ..##. ####. 17 #.###.##########. ####.##.#####.##. 5 ....
output:
Yes #######.#######.######################### .......#.......#......................... ......#.................................. .......######################............ .............................#........... ................#...#.......#............ ################.###.#######.############ Ye...
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 23ms
memory: 3948kb
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: 26ms
memory: 3772kb
input:
10000 5 ...#. ##### 6 ###... ##..#. 9 .#.###### #.#..#### 49 ######.########################################## ########.#############.########################## 41 ###########.#######.##################### ##############.########################## 6 ###..# ###.## 49 #################################...
output:
No Yes ###... ...### ..#... ...#.. ....#. ..##.# ##..#. Yes .#.###### #.#...... .#....... ..###.... .....#... .#.##.... #.#..#### Yes ######.########################################## ......#.......................................... .....#........................................... ......##########...
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 26ms
memory: 10472kb
input:
2 100000 ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.#...
output:
Yes ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 22ms
memory: 10700kb
input:
2 100000 ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##...
output:
Yes ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........
result:
ok Correct.