QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751741#9621. 连方CirnoNineAC ✓24ms4536kbC++234.8kb2024-11-15 20:24:222024-11-15 20:24:22

Judging History

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

  • [2024-11-15 20:24:22]
  • 评测
  • 测评结果:AC
  • 用时:24ms
  • 内存:4536kb
  • [2024-11-15 20:24:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define ll long long

int n;

bool check(string ans[]) {
    auto checkUp = [&](int x) -> bool {
        if (x == 0) {
            return ans[2][x+1] == '#';
        }
        if (x == n-1) {
            return ans[2][x-1] == '#';
        }
        return ans[2][x+1] == '#' || ans[2][x-1] == '#';
    };
    auto checkDown = [&](int x) -> bool {
        if (x == 0) {
            return ans[4][x+1] == '#';
        }
        if (x == n-1) {
            return ans[4][x-1] == '#';
        }
        return ans[4][x+1] == '#' || ans[4][x-1] == '#';
    };
    int i = 0;
    while (i < n) {
        if (ans[3][i] == '#') {
            int j = i+1;
            while (j < n && ans[3][j] == '#') {
                j++;
            }
            //[i,j)
            bool a = checkUp(i);
            bool b = checkDown(i);
            for (int k = i+1; k < j; k++) {
                a |= checkUp(k);
                b |= checkDown(k);
            }
            if (a && b) {
                //cout << n << " " << i << " " << j << endl;
                return true;
            }
            i = j;
        }else {
            i++;
        } 
    }
    return false;
}

void solve() {
    cin >> n;
    string a,b;
    cin >> a >> b;
    bool flagA = 1,flagB = 1;
    for (int i = 0; i < n; i++) {
        if (a[i]=='.') flagA = 0;
        if (b[i]=='.') flagB = 0;
    }
    if (flagA && flagB) {
        cout << "Yes" << endl;
        for (int i = 0; i < 7; i++) {
            cout << a << endl;
        }
        return;
    }
    if (flagA || flagB) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    string ans[7];
    ans[0] = a;
    ans[6] = b;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < 6; j++) {
            ans[j]+='.';
        }
    }
    bool flag = 0;
    for (int i = 0; i < n; i++) {
        if (ans[0][i] == '.') {
            ans[1][i] = '#';
            ans[2][i] = '#';
        }else {
            ans[1][i] = '.';
            ans[2][i] = '.';    
        }
        if (ans[6][i] == '.') {
            ans[5][i] = '#';
            ans[4][i] = '#';
        }else {
            ans[5][i] = '.';
            ans[4][i] = '.';    
        }
        if (ans[4][i] == '.' && ans[2][i] == '.') {
            ans[3][i] = '#';
        }else {
            ans[3][i] = '.';
        }
    }
    flag = check(ans);
    if (!flag) {
        for (int i = 0; i < n; i++) {
            if (ans[0][i] == '.') {
                ans[1][i] = '#';
                ans[2][i] = '.';
            }else {
                ans[1][i] = '.';
                ans[2][i] = '#';    
            }
            if (ans[6][i] == '.') {
                ans[5][i] = '#';
                ans[4][i] = '#';
            }else {
                ans[5][i] = '.';
                ans[4][i] = '.';    
            }
            if (ans[4][i] == '.' && ans[2][i] == '.') {
                ans[3][i] = '#';
            }else {
                ans[3][i] = '.';
            }
        }
    }
    flag = check(ans);
    if (!flag) {
        for (int i = 0; i < n; i++) {
            if (ans[0][i] == '.') {
                ans[1][i] = '#';
                ans[2][i] = '#';
            }else {
                ans[1][i] = '.';
                ans[2][i] = '.';    
            }
            if (ans[6][i] == '.') {
                ans[5][i] = '#';
                ans[4][i] = '.';
            }else {
                ans[5][i] = '.';
                ans[4][i] = '#';    
            }
            if (ans[4][i] == '.' && ans[2][i] == '.') {
                ans[3][i] = '#';
            }else {
                ans[3][i] = '.';
            }
        }
    }
    flag = check(ans);
    if (!flag) {
        for (int i = 0; i < n; i++) {
            if (ans[0][i] == '.') {
                ans[1][i] = '#';
                ans[2][i] = '.';
            }else {
                ans[1][i] = '.';
                ans[2][i] = '#';    
            }
            if (ans[6][i] == '.') {
                ans[5][i] = '#';
                ans[4][i] = '.';
            }else {
                ans[5][i] = '.';
                ans[4][i] = '#';    
            }
            if (ans[4][i] == '.' && ans[2][i] == '.') {
                ans[3][i] = '#';
            }else {
                ans[3][i] = '.';
            }
        }
    }
    flag = check(ans);
    //cout << flag << endl;
    for (int i = 0; i < 7; i++) {
        cout << ans[i] << endl;
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}

详细

Test #1:

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

input:

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

output:

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

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 24ms
memory: 3664kb

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

input:

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

output:

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

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 19ms
memory: 3656kb

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

input:

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

output:

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

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 5ms
memory: 4536kb

input:

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

output:

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

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 3ms
memory: 4500kb

input:

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

output:

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

result:

ok Correct.