QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#761234#9621. 连方KeeperHihiAC ✓17ms7732kbC++231.8kb2024-11-18 21:36:082024-11-18 21:36:09

Judging History

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

  • [2024-11-18 21:36:09]
  • 评测
  • 测评结果:AC
  • 用时:17ms
  • 内存:7732kb
  • [2024-11-18 21:36:08]
  • 提交

answer

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

void solve() {
    int n;
    cin >> n;
    string x, y;
    cin >> x >> y;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        a[i] = x[i] == '#';
        b[i] = y[i] == '#';
    }
    int aa = accumulate(a.begin(), a.end(), 0);
    int bb = accumulate(b.begin(), b.end(), 0);
    if (aa == n && bb == n) {
        cout << "YES\n";
        for (int i = 0; i < 7; i++) {
            cout << x << "\n";
        }
        return;
    } 
    if (aa == n || bb == n) {
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
    vector<vector<int>> adj(7, vector<int>(n));
    adj[0] = a, adj[6] = b;

    for (int i = 0; i < n; i++) {
        adj[1][i] = adj[0][i] ^ 1;
        adj[5][i] = adj[6][i] ^ 1;
    }

    auto print = [&]() {
        for (int i = 0; i < 7; i++) {
            for (int j = 0; j < n; j++) {
                cout << (adj[i][j] ? '#' : '.');
            }
            cout << "\n";
        }
    };

    int s = -1, t = -1;
    for (int i = 0; i < n; i++) {
        if (adj[1][i] == 0 && (i + 1 < n && adj[1][i + 1] == 1 || i - 1 >= 0 && adj[1][i - 1] == 1)) s = i;
        if (adj[5][i] == 0 && (i + 1 < n && adj[5][i + 1] == 1 || i - 1 >= 0 && adj[5][i - 1] == 1)) t = i;
    }
    adj[2][s] = adj[4][t] = 1;
    if (s == t) {
        adj[3][s] = 1;
    } else if (abs(s - t) > 1) {
        for (int i = min(s, t) + 1; i < max(s, t); i++) {
            adj[3][i] = 1;
        }
    } else {
        adj[3][s] = 1;
    }
    print();
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

YES
#..#
.##.
...#
...#
..#.
#..#
.##.
YES
##.#.
..#.#
...#.
...#.
...#.
#.#..
.#.##
NO
YES
.######.######.####.#.#####
#......#......#....#.#.....
......................#....
......................#....
......................#....
#....###....##.#######.....
.####...####..#.......#####
YES
########...

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 17ms
memory: 3720kb

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

input:

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

output:

YES
#######.#######.#########################
.......#.......#.........................
................#........................
.................############............
.............................#...........
................#...#.......#............
################.###.#######.############
YE...

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 17ms
memory: 3668kb

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

input:

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

output:

NO
YES
###...
...###
..#...
...#..
....#.
..##.#
##..#.
YES
.#.######
#.#......
...#.....
....#....
.....#...
.#.##....
#.#..####
YES
######.##########################################
......#..........................................
.......#.........................................
........########...

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 13ms
memory: 7732kb

input:

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

output:

YES
###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 8ms
memory: 7516kb

input:

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

output:

YES
##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........

result:

ok Correct.