QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#811528#9621. 连方TosakaUCW#AC ✓7ms4372kbC++203.8kb2024-12-12 20:21:122024-12-12 20:21:17

Judging History

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

  • [2024-12-12 20:21:17]
  • 评测
  • 测评结果:AC
  • 用时:7ms
  • 内存:4372kb
  • [2024-12-12 20:21:12]
  • 提交

answer

#include <bits/stdc++.h>
using i64 = long long;
#define int i64
#define pb push_back
#define ep emplace
#define eb emplace_back
using std::cerr;
// using namespace std::views;
// using namespace std::ranges;
using std::max, std::min, std::swap, std::array;
using std::cin, std::cout, std::string, std::vector;
using std::ostream;
template <class T1, class T2> ostream &operator<<(ostream &os, const std::pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << '\n'; }
using pii = std::pair<int, int>;
#define fi first
#define se second

double eps = 1e-7;
const int inf = 1000;

void solve() {
    int n; cin >> n;
    
    string s, t;
    cin >> s >> t;

    int cnt1 = 0;
    int cnt2 = 0;
    for (auto ch : s) cnt1 += ch == '#';
    for (auto ch : t) cnt2 += ch == '#';

    // if (cnt1 < cnt2) swap(cnt1, cnt2);

    if (max(cnt1, cnt2) == n and cnt1 != cnt2) {
        cout << "No\n";
        return;
    }

    vector<string> a(7);
    // a[0] = s, a[6] = t;
    string sr = s;
    string tr = t;
    for (auto &ch : sr) ch = (ch == '.' ? '#' : '.');
    for (auto &ch : tr) ch = (ch == '.' ? '#' : '.');

    a[0] = s;
    a[1] = sr;
    a[5] = tr;
    a[6] = t;

    a[2].assign(n, '.');
    a[3].assign(n, '.');
    a[4].assign(n, '.');

    if (cnt1 == cnt2 and cnt1 == n) {
        cout << "Yes\n";
        for (int i = 0; i < 7; i++) {
            a[i].assign(n, '#');
            cout << a[i] << '\n';
        }
        return;
    }


    if (cnt1 == cnt2 and cnt1 == 0) {
        cout << "Yes\n";
        a[1].assign(n, '.');
        a[5].assign(n, '.');
        for (int i = 0; i < 7; i++) {
            cout << a[i] << '\n';
        }
        return;
    }

    // cerr << a << '\n';

    int p1 = -inf, p2 = -inf;

    for (int i = 0; i < n and p1 == -inf; i++) {
        // cout << i + 1 << '\n';
        if (a[1][i] == '#') {
            if (i + 1 < n and a[1][i + 1] != '#') {
                a[2][i + 1] = '#';
                p1 = i + 1;
                break;
            }
            if (i - 1 >= 0 and a[1][i - 1] != '#') {
                a[2][i - 1] = '#';
                p1 = i - 1;
                break;
            }
        }
    }
    // cout << 1 << '\n';
    for (int i = 0; i < n and p2 == -inf; i++) {
        if (a[5][i] == '#') {

            if (i + 1 < n and a[5][i + 1] != '#') {
                // cout << '9';
                a[4][i + 1] = '#';
                p2 = i + 1;
                break;
            }
            if (i - 1 >= 0 and a[5][i - 1] != '#') {
                a[4][i - 1] = '#';
                p2 = i - 1;
                // assert(0);
                break;
            }
        }
    }

    // cerr << a[4] << '\n';

    if (p1 != -inf and p2 != -inf) {
        if (abs(p1 - p2) <= 1) {
            a[3][p1] = '#';
        } else {
            if (p1 > p2) swap(p1, p2);
            for (int i = p1 + 1; i < p2; i++) {
                a[3][i] = '#';
            }
        }
    } else {
        if (cnt1 == 0)
            for (int i = 1; i < 5; i++) a[i] = s;
        else if (cnt2 == 0)
            for (int i = 2; i < 7; i++) a[i] = t;
    }
    

    cout << "Yes\n";
    for (int i = 0; i < 7; i++) {
        cout << a[i] << '\n';
    }
    // cerr << "----\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T; cin >> T;
    for (; T--; solve());
    // solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct.

Test #2:

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

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

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

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

input:

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

output:

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

result:

ok Correct.

Test #7:

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

input:

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

output:

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

result:

ok Correct.