QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#774300#9621. 连方Magical_Kingdom#AC ✓15ms4400kbC++172.3kb2024-11-23 12:54:082024-11-23 12:54:10

Judging History

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

  • [2024-11-23 12:54:10]
  • 评测
  • 测评结果:AC
  • 用时:15ms
  • 内存:4400kb
  • [2024-11-23 12:54:08]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
char s[10][100005];

void init() {
    for (int i = 1; i <= 7; i++) {
        for (int j = 1; j <= n; j++) {
            s[i][j] = '.';
        }
    }
}

void solve() {
    cin >> n;
    init();
    cin >> (s[1] + 1);
    // s[1] = " " + s[1];
    cin >> (s[7] + 1);
    // s[7] = " " + s[7];

    int cnt1 = 0;
    int cnt7 = 0;
    for (int i = 1; i <= n; i++) {
        cnt1 += s[1][i] == '#';
        cnt7 += s[7][i] == '#';
    }
    if ((cnt1 == n && cnt7 != n) || (cnt1 != n && cnt7 == n)) {
        cout << "No" << '\n';
        return;
    }
    if (cnt1 == n && cnt7 == n) {
        cout << "Yes" << '\n';
        for (int i = 1; i <= 7; i++) {
            for (int j = 1; j <= n; j++) {
                cout << '#';
            }
            cout << '\n';
        }
        return;
    }

    for (int i = 1; i <= n; i++) {
        if (s[1][i] == '#') {
            s[2][i] = '.';
        } else {
            s[2][i] = '#';
        }
        if (s[7][i] == '#') {
            s[6][i] = '.';
        } else {
            s[6][i] = '#';
        }
    }
    int y1 = 0, y2 = 0;
    for (int i = 1; i <= n; i++) {
        if (s[2][i] == '#' && i >= 2 && s[2][i - 1] != '#') {
            y1 = i - 1;
            break;
        }
        if (s[2][i] == '#' && i <= n - 1 && s[2][i + 1] != '#') {
            y1 = i + 1;
            break;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (s[6][i] == '#' && i >= 2 && s[6][i - 1] != '#') {
            y2 = i - 1;
            break;
        }
        if (s[6][i] == '#' && i <= n - 1 && s[6][i + 1] != '#') {
            y2 = i + 1;
            break;
        }
    }

    s[3][y1] = '#';
    s[5][y2] = '#';
    if (y1 == y2) {
        s[4][y1] = '#';
    } else if (abs(y1 - y2) == 1) {
        s[4][y1] = '#';
    } else {
        for (int i = min(y1, y2) + 1; i <= max(y1, y2) - 1; i++) {
            s[4][i] = '#';
        }
    }
    cout << "Yes\n";
    for (int i = 1; i <= 7; i++) {
        for (int j = 1; j <= n; j++) {
            cout << s[i][j];
        }
        cout << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;

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

input:

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

output:

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

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 15ms
memory: 3796kb

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

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

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

input:

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

output:

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

result:

ok Correct.

Test #6:

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

input:

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

output:

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

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 10ms
memory: 4400kb

input:

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

output:

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

result:

ok Correct.