QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763751 | #9621. 连方 | lonelywolf# | AC ✓ | 35ms | 10532kb | C++20 | 3.7kb | 2024-11-19 21:54:35 | 2024-11-19 21:54:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n;
cin >> n;
vector<string> a(8);
string x, y;
cin >> x >> y;
a[1] = x, a[7] = y;
if (a[1] == string(n, '#') || a[7] == string(n, '#'))
{
if (a[1] == a[7])
{
cout << "Yes\n";
for (int i = 1; i <= 7; i++)
{
cout << a[1] << " \n"[i == 7];
}
}
else
{
cout << "No\n";
}
return;
}
auto inv = [&](const string &s)
{
string ret;
for (int i = 0; i < n; i++)
{
if (s[i] != '.')
{
ret.push_back('.');
}
else
{
ret.push_back('#');
}
}
return ret;
};
vector<int> pos;
auto find = [&](const string &s)
{
string ret(n, '.');
for (int i = 0; i < n; i++)
{
if (s[i] == '.')
{
if ((i - 1 >= 0 && s[i - 1] == '#') || (i + 1 < n && s[i + 1] == '#'))
{
pos.push_back(i);
ret[i] = '#';
return ret;
}
}
}
return ret;
};
a[2] = inv(a[1]);
a[6] = inv(a[7]);
a[3] = find(a[2]);
a[5] = find(a[6]);
if (pos[0] > pos[1])
{
swap(pos[0], pos[1]);
}
if (pos[1] - pos[0] <= 1)
{
a[4] = a[3];
}
else
{
a[4] = string(n, '.');
for (int i = pos[0] + 1; i <= pos[1] - 1; i++)
{
a[4][i] = '#';
}
}
auto check = [&]()
{
int s = 7 * n;
vector<int> f(s);
for (int i = 0; i < s; i++)
f[i] = i;
auto get = [&](int i, int j)
{
return (i - 1) * n + j;
};
auto fi = [&](int x)
{
while (x != f[x])
{
x = f[x] = f[f[x]];
}
return x;
};
auto merge = [&](int x, int y)
{
x = fi(x), y = fi(y);
f[x] = y;
};
for (int i = 1; i <= 7; i++)
{
for (int j = 0; j < n; j++)
{
for (int dx = -1; dx <= 1; dx++)
{
for (int dy = -1; dy <= 1; dy++)
{
int tx = i + dx, ty = j + dy;
if (tx >= 1 && tx <= 7 && ty >= 0 && ty < n)
{
if (a[i][j] == '#' && a[tx][ty] == '#')
{
// cout << i << " " << j << " " << tx << " " << ty << "\n";
merge(get(i, j), get(tx, ty));
}
}
}
}
}
}
set<int> st;
for (int i = 1; i <= 7; i++)
{
for (int j = 0; j < n; j++)
{
if (a[i][j] == '#')
{
int t = get(i, j);
st.insert(fi(t));
}
}
}
assert(st.size() == 1);
};
check();
cout << "Yes\n";
for (int i = 1; i <= 7; i++)
{
cout << a[i] << "\n";
}
}
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: 3624kb
input:
5 4 #..# .##. 5 ##.#. .#.## 6 ###### .####. 27 .######.######.####.#.##### .####...####..#.......##### 10 ########## ##########
output:
Yes #..# .##. #... #... .#.. #..# .##. Yes ##.#. ..#.# .#... .#... .#... #.#.. .#.## No Yes .######.######.####.#.##### #......#......#....#.#..... .#......................... .#......................... .#......................... #....###....##.#######..... .####...####..#.......##### Yes ########...
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 27ms
memory: 4096kb
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: 31ms
memory: 4232kb
input:
10000 41 #######.#######.######################### ################.###.#######.############ 6 ..#..# #..##. 6 #.#... #...#. 6 .#.##. ....## 6 ...#.# ##..#. 33 #####.########################### ###########.##################### 6 .##.## .##.#. 5 ..##. ####. 17 #.###.##########. ####.##.#####.##. 5 ....
output:
Yes #######.#######.######################### .......#.......#......................... ......#.................................. .......########.......................... ...............#......................... ................#...#.......#............ ################.###.#######.############ Ye...
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 35ms
memory: 4016kb
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: 28ms
memory: 4024kb
input:
10000 5 ...#. ##### 6 ###... ##..#. 9 .#.###### #.#..#### 49 ######.########################################## ########.#############.########################## 41 ###########.#######.##################### ##############.########################## 6 ###..# ###.## 49 #################################...
output:
No Yes ###... ...### ..#... ..#... .#.... ..##.# ##..#. Yes .#.###### #.#...... .#....... .#....... #........ .#.##.... #.#..#### Yes ######.########################################## ......#.......................................... .....#........................................... ......#............
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 30ms
memory: 10292kb
input:
2 100000 ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.#...
output:
Yes ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 30ms
memory: 10532kb
input:
2 100000 ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##...
output:
Yes ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........
result:
ok Correct.