QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759014#9621. 连方5720226849#AC ✓7ms4028kbC++143.9kb2024-11-17 21:06:332024-11-17 21:06:34

Judging History

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

  • [2024-11-17 21:06:34]
  • 评测
  • 测评结果:AC
  • 用时:7ms
  • 内存:4028kb
  • [2024-11-17 21:06:33]
  • 提交

answer

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

#define x first
#define y second 
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ls u << 1
#define rs u << 1 | 1
#define all(x) x.begin(),x.end()
#define i128 __int128
#define int long long
#define Genshin_Impact return
#define Starts 0
#define _o_o_ return
#define o_o_o return

inline int gcd(int a, int b) {return b > 0 ? gcd(b, a % b) : a;}
inline int lowbit(int x) {return x & (-x);}
int qmi(int a, int b, int mod){int res = 1;while(b) {if(b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;}
// inline i128 read(){i128 x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}
// inline void print(i128 x){if(x < 0){putchar('-');x = -x;}if(x > 9)print(x / 10);putchar(x % 10 + '0');}

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, PII> PIII;



const int N = 5e5 + 10, logn = 21, inf = 1e18, mod = 998244353, M = 2e6 + 10;
const int P = 131;
#define ull unsigned long long


void solve()
{
    // 通过这些东西把底下的全部连接起来
    // #.#.###.....
    // .#.#...#....
    // ........#...
    // .........#..
    // ..........#.
    // ...........#
    // 如此即可
    // #...###.....
    // .###...####.
    // ...........#
    // ..........#.
    // ...........#
    // 最少5行就一定有解,除非一整行都是#
    // 中间部分的作用就是将同侧的.给连接起来
    // 并且把底部的连接起来
    // 对于同一侧的
    // 可以在第二行连接起来
    // 行数少如何实现
    // 三行,出去就没了,两行不能出去
    // 两行必须完全对应或者相邻不能有重
    // 三行不能重叠不完全
    // 距离远可以如上诉,相邻可以直接延伸一行
    // 四行
    // 题目给定8行
    int n; cin >> n;
    string s0, s1; cin >> s0 >> s1;
    
    auto check = [&](string s) {
        int cnt = 0;
        for(int i = 0; s[i]; i ++)
            cnt += (s[i] == '#');
        return cnt;
    };
    
    if(check(s0) == n && check(s1) == n) {
        cout << "Yes\n";
        for(int i = 0; i < 7; i ++) cout << s0 << '\n';
        return;
    }
    else if(check(s0) == n || check(s1) == n) {
        cout << "No\n";
        return;
    }
    // 第二、六行就是没有#的就是#号
    // 第三和第五就是如果侧边一行有,那就放到中间一点
    // 不然就直接上去
    // 第4行只要两端
    cout << "Yes\n";
    cout << s0 << '\n';
    string t0 = s0, t1 = s1;
    for(int i = 0; i < n; i ++) t0[i] = (t0[i] == '#' ? '.' : '#');
    for(int i = 0; i < n; i ++) t1[i] = (t1[i] == '#' ? '.' : '#');
    string t00 = s0, t11 = s1;
    int pos1 = -1, pos2 = -1;
    for(int i = 0, ok = 0; i < n; i ++) {
        t00[i] = '.';
        if(t0[i] == '.' && !ok && ((i > 0 && t0[i - 1] == '#') || (i < n - 1 && t0[i + 1] == '#'))) {
            t00[i] = '#';
            ok = 1;
            pos1 = i;
        }
    }
    for(int i = 0, ok = 0; i < n; i ++) {
        t11[i] = '.';
        if(t1[i] == '.' && !ok && ((i > 0 && t1[i - 1] == '#') || (i < n - 1 && t1[i + 1] == '#'))) {
            t11[i] = '#';
            ok = 1;
            pos2 = i;
        }
    }
    string t3 = s0;
    for(int i = 0; i < n; i ++) t3[i] = '.';
    int cnt = 0;
    for(int i = min(pos1, pos2) + 1; i < max(pos1, pos2); i ++) {
        t3[i] = '#';
        cnt ++;
    }
    if(cnt == 0) t3[pos1] = '#';
    cout << t0 << '\n' << t00 << '\n';
    cout << t3 << '\n';
    cout << t11 << '\n' << t1 << '\n';
    cout << s1 << '\n';
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    Genshin_Impact Starts;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct.

Test #2:

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

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

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

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

input:

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

output:

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

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 2ms
memory: 4008kb

input:

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

output:

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

result:

ok Correct.