QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742781#9621. 连方aYi_7#AC ✓10ms4448kbC++233.2kb2024-11-13 17:18:312024-11-13 17:18:31

Judging History

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

  • [2024-11-13 17:18:31]
  • 评测
  • 测评结果:AC
  • 用时:10ms
  • 内存:4448kb
  • [2024-11-13 17:18:31]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

void solve() {
    int n;
    std::cin >> n;
    std::string a, b;
    std::cin >> a >> b;

    int cnt_a = 0, cnt_b = 0;

    std::string a1{};
    for (auto& i : a) {
        cnt_a += (i == '#');
        if (i == '#')
            a1.push_back('.');
        else
            a1.push_back('#');
    }
    std::string b1{};
    for (auto& i : b) {
        cnt_b += (i == '#');
        if (i == '#')
            b1.push_back('.');
        else
            b1.push_back('#');
    }

    std::vector<std::string> ans;

    if (cnt_a == n) {
        if (cnt_b == n || cnt_b == 0) {
            std::cout << "Yes" << '\n';
            for (int i = 0; i < 6; i++) std::cout << a << '\n';
            std::cout << b << '\n';

        } else {
            std::cout << "No" << '\n';
        }
        return;
    }

    if (cnt_b == n) {
        if (cnt_a == n || cnt_a == 0) {
            std::cout << "Yes" << '\n';
            for (int i = 0; i < 6; i++) std::cout << a << '\n';
            std::cout << b << '\n';
        } else {
            std::cout << "No" << '\n';
        }
        return;
    }

    if (cnt_a == 0 || cnt_b == 0) {
        std::cout << "Yes" << '\n';
        for (int i = 0; i < 6; i++) std::cout << a << '\n';
        std::cout << b << '\n';
    }

    ans.push_back(a);
    ans.push_back(a1);
    int idx3 = -1, idx5 = -1;
    for (int i = 0; i < n; i++) {
        if (a1[i] == '.') {
            if (i - 1 >= 0 && a1[i - 1] == '#') {
                idx3 = i;
                break;
            }
            if (i + 1 < n && a1[i + 1] == '#') {
                idx3 = i;
                break;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (b1[i] == '.') {
            if (i - 1 >= 0 && b1[i - 1] == '#') {
                idx5 = i;
                break;
            }
            if (i + 1 < n && b1[i + 1] == '#') {
                idx5 = i;
                break;
            }
        }
    }

    std::string t{};
    for (int i = 0; i < n; i++) {
        if (i == idx3)
            t.push_back('#');
        else
            t.push_back('.');
    }
    ans.push_back(t);
    t.clear();
    for (int i = 0; i < n; i++) t.push_back('.');
    int l3 = idx3, l5 = idx5;

    if (l3 > l5) std::swap(l3, l5);
    if (l5 - l3 > 1) {
        for (int i = l3 + 1; i < l5; i++) {
            t[i] = '#';
        }
    } else {
        t[l3] = '#';
    }

    ans.push_back(t);
    t.clear();
    for (int i = 0; i < n; i++) {
        if (i == idx5)
            t.push_back('#');
        else
            t.push_back('.');
    }
    ans.push_back(t);
    ans.push_back(b1);
    ans.push_back(b);

    std::cout << "Yes" << '\n';
    for (int i = 0; i < 7; i++) std::cout << ans[i] << '\n';
}

/*
4
4
#..#
.##.
5
##.#.
.#.##
6
######
.####.
27
.######.######.####.#.#####
.####...####..#.......#####
*/

/*
#..#
.##.
.#..
....
#...
#..#
.##.
*/

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0), std::cout.tie(0);

    int t = 1;
    std::cin >> t;

    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

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

output:

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

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 7ms
memory: 3860kb

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

input:

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

output:

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

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 7ms
memory: 3640kb

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: 10ms
memory: 3660kb

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: 4444kb

input:

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

output:

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

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 0ms
memory: 4448kb

input:

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

output:

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

result:

ok Correct.