QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#793277#9621. 连方happy_lazier#AC ✓17ms4444kbC++202.0kb2024-11-29 18:12:332024-11-29 18:12:39

Judging History

你现在查看的是最新测评结果

  • [2024-11-29 18:12:39]
  • 评测
  • 测评结果:AC
  • 用时:17ms
  • 内存:4444kb
  • [2024-11-29 18:12:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(ll i=l;i<=r;++i)
#define rep_(i,r,l) for(ll i=r;i>=l;--i)
const ll N = 2e5 + 7;
const ll P = 998244353;
ll qpow(ll x, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)res = (res * x) % P;
		x = x * x % P;
		b >>= 1ll;
	}
	return res;
}
ll inv(ll x) { return qpow(x, P - 2); }


void solve() {
	ll n; cin >> n;
	string s[8];
	cin >> s[1] >> s[7];
	s[1] = '.' + s[1] + '.', s[7] = '.' + s[7] + '.';
	rep(i, 2, 6) {
		s[i] = "";
		rep(j, 1, n + 2) s[i] += '.';
	}
	int f1 = 0, f2 = 0;
	int p1 = 0, p2 = 0;
	rep(i, 1, n) {
		if (s[1][i] != '#')f1 = 1;
		if (s[1][i] != '.')p1 = 1;
		if (s[7][i] != '#')f2 = 1;
		if (s[7][i] != '.')p2 = 1;
	}
	if (f1 == 0 && f2 == 0) {
		cout << "Yes" << endl;
		rep(i, 1, 7) {
			rep(j, 1, n) {
				cout << "#";
			}
			cout << endl;
		}
	}
	else if (f1 == 1 && f2 == 1) {
		cout << "Yes" << endl;
		rep(i, 1, n) {
			if (p1&&s[1][i] == '.') s[2][i] = '#';
			if (!p1)s[2][1] = '#';
			if (p2&&s[7][i] == '.') s[6][i] = '#';
			if (!p2)s[6][1] = '#';
		}
		ll pos1 = 0, pos2 = 0;
		rep(i, 1, n) {
			if (s[2][i] == '.' && (s[2][i - 1] == '#' || s[2][i + 1] == '#')) {
				s[3][i] = '#';
				pos1 = i;
				break;
			}
		}
		rep(i, 1, n) {
			if (s[6][i] == '.' && (s[6][i - 1] == '#' || s[6][i + 1] == '#')) {
				s[5][i] = '#';
				pos2 = i;
				break;
			}
		}
		if (pos1 == pos2) s[4][pos1] = '#';
		else if (abs(pos1 - pos2) == 1) {
			s[4][pos1] = '#';
		}
		else {
			rep(i, min(pos1, pos2) + 1, max(pos1, pos2) - 1) s[4][i] = '#';
		}
		rep(i, 1, 7) {
			rep(j, 1, n) cout << s[i][j];
			cout << endl;
		}
	}
	else {
		if ((p1 == 0 && f2 == 0) || (p2 == 0 && f1 == 0)) {
			cout << "Yes" << endl;
			rep(i, 1, 7) {
				rep(j, 1, n) cout << s[i][j];
				cout << endl;
			}
			return;
		}
		cout << "No" << endl;
		return;
	}

}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T(1);
	cin >> T;
	while (T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3856kb

input:

5
4
#..#
.##.
5
##.#.
.#.##
6
######
.####.
27
.######.######.####.#.#####
.####...####..#.......#####
10
##########
##########

output:

Yes
#..#
.##.
#...
#...
.#..
#..#
.##.
Yes
##.#.
..#.#
.#...
.#...
.#...
#.#..
.#.##
No
Yes
.######.######.####.#.#####
#......#......#....#.#.....
.#.........................
.#.........................
.#.........................
#....###....##.#######.....
.####...####..#.......#####
Yes
########...

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 16ms
memory: 3712kb

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: 13ms
memory: 3700kb

input:

10000
41
#######.#######.#########################
################.###.#######.############
6
..#..#
#..##.
6
#.#...
#...#.
6
.#.##.
....##
6
...#.#
##..#.
33
#####.###########################
###########.#####################
6
.##.##
.##.#.
5
..##.
####.
17
#.###.##########.
####.##.#####.##.
5
....

output:

Yes
#######.#######.#########################
.......#.......#.........................
......#..................................
.......########..........................
...............#.........................
................#...#.......#............
################.###.#######.############
Ye...

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 16ms
memory: 3904kb

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: 17ms
memory: 3640kb

input:

10000
5
...#.
#####
6
###...
##..#.
9
.#.######
#.#..####
49
######.##########################################
########.#############.##########################
41
###########.#######.#####################
##############.##########################
6
###..#
###.##
49
#################################...

output:

No
Yes
###...
...###
..#...
..#...
.#....
..##.#
##..#.
Yes
.#.######
#.#......
.#.......
.#.......
#........
.#.##....
#.#..####
Yes
######.##########################################
......#..........................................
.....#...........................................
......#............

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 16ms
memory: 4444kb

input:

2
100000
###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.#...

output:

Yes
###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 16ms
memory: 4208kb

input:

2
100000
##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##...

output:

Yes
##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........

result:

ok Correct.