QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#772610 | #9621. 连方 | candy34# | AC ✓ | 16ms | 4808kb | C++20 | 4.1kb | 2024-11-22 20:43:26 | 2024-11-22 20:43:30 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define ph push_back
#define pp pop_back
using namespace std;
const int N=2e5+5;
int T,n;
string a,b,ans[10];
string fa,fb;
bool jing(const string &str)
{
for(auto ch:str)
if(ch=='.') return 0;
return 1;
}
bool dian(const string &str)
{
for(auto ch:str)
if(ch=='#') return 0;
return 1;
}
bool check(const string &a,const string &b)
{
// string str;
// int pos=-1;
// for(int i=0;i<n;i++)
// {
// if(a[i]=='.'&&b[i]=='.')
// {
// int cnta=0,cntb=0;
// if(i>0&&a[i-1]=='#') cnta++;
// if(i>0&&b[i-1]=='#') cntb++;
// if(i<n-1&&a[i+1]=='#') cnta++;
// if(i<n-1&&b[i+1]=='#') cntb++;
// if()
// }
// }
// ans[4]=str;
string str; str.resize(n+1);
for(int i=0;i<n;i++)
if(a[i]=='.'&&b[i]=='.') str[i]='#';
else str[i]='.';
bool f1 = false;
bool f2 = false;
bool f = false;
for(int i=0;i<n;i++)
{
if(str[i]=='#'){
if(i>0&&a[i-1]=='#') f1=true;
if(i<n-1&&a[i+1]=='#') f1 = true;
if(i>0&&b[i-1]=='#') f2=true;
if(i<n-1&&b[i+1]=='#') f2 = true;
}else{
f1 = f2 = false;
}
if(f1&&f2){
f = true;
break;
}
}
if(f) ans[4]=str;
return f;
}
bool solve()
{
if(jing(a)&&jing(b))
{
for(int i=1;i<=7;i++) ans[i]=a;
return 1;
}
if(dian(a)||dian(b))
{
if(a==b)
{
for(int i=1;i<=7;i++) ans[i]=a;
return 1;
}
if(dian(a)&&jing(b))
{
for(int i=1;i<=6;i++) ans[i]=a;
ans[7]=b;
}
if(dian(a)&&!jing(b))
{
ans[7]=b; ans[6]=fb;
for(int i=1;i<=5;i++) ans[i]=a;
}
if(jing(a)&&dian(b))
{
ans[1]=a;
for(int i=2;i<=7;i++) ans[i]=b;
}
if(!jing(a)&&dian(b))
{
ans[1]=a; ans[2]=fa;
for(int i=3;i<=7;i++) ans[i]=b;
}
return 1;
}
if(!jing(a)&&!jing(b))
{
if(fa==b)
{
ans[1]=a;
for(int i=2;i<=7;i++) ans[i]=b;
return 1;
}
ans[1]=a; ans[2]=fa; ans[7]=b; ans[6]=fb;
if(check(a,b))
{
ans[3]=a; ans[5]=b;
return 1;
}
if(check(a,fb))
{
ans[3]=a; ans[5]=fb;
return 1;
}
if(check(fa,b))
{
ans[3]=fa; ans[5]=b;
return 1;
}
if(check(fa,fb))
{
ans[3]=fa; ans[5]=fb;
return 1;
}
// vector<bool>pd(n+5);
// bool fg=0;
// for(int i=0;i<n;i++)
// if(a[i]=='.'&&b[i]=='.') fg=1,pd[i]=1;
// if(!fg)
// {
// ans[3]=fa; ans[5]=fb;
// ans[4].resize(n+1);
// for(int i=0;i<n;i++)
// if(fa[i]=='.'&&fb[i]=='.') ans[4][i]='#';
// else ans[4][i]='.';
// }
// else
// {
// ans[3]=a; ans[5]=b;
// ans[4].resize(n+1);
// for(int i=0;i<n;i++)
// if(pd[i]) ans[4][i]='#';
// else ans[4][i]='.';
// }
return 1;
}
return 0;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>T;
while(T--)
{
cin>>n>>a>>b;
fa.clear(); fb.clear();
for(int i=0;i<n;i++)
{
if(a[i]=='#') fa.ph('.');
else fa.ph('#');
if(b[i]=='#') fb.ph('.');
else fb.ph('#');
}
if(!solve()) cout<<"No\n";
else
{
cout<<"Yes\n";
for(int i=1;i<=7;i++)
{
for(int j=0;j<n;j++) cout<<ans[i][j];
cout<<endl;
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
5 4 #..# .##. 5 ##.#. .#.## 6 ###### .####. 27 .######.######.####.#.##### .####...####..#.......##### 10 ########## ##########
output:
Yes #..# .##. .##. .##. .##. .##. .##. Yes ##.#. ..#.# ##.#. ..#.. .#.## #.#.. .#.## No Yes .######.######.####.#.##### #......#......#....#.#..... .######.######.####.#.##### #......#...........#.#..... .####...####..#.......##### #....###....##.#######..... .####...####..#.......##### Yes ########...
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 12ms
memory: 3676kb
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: 15ms
memory: 3672kb
input:
10000 41 #######.#######.######################### ################.###.#######.############ 6 ..#..# #..##. 6 #.#... #...#. 6 .#.##. ....## 6 ...#.# ##..#. 33 #####.########################### ###########.##################### 6 .##.## .##.#. 5 ..##. ####. 17 #.###.##########. ####.##.#####.##. 5 ....
output:
Yes #######.#######.######################### .......#.......#......................... #######.#######.######################### .......#.......#......................... ................#...#.......#............ ................#...#.......#............ ################.###.#######.############ Ye...
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 15ms
memory: 3680kb
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: 16ms
memory: 3968kb
input:
10000 5 ...#. ##### 6 ###... ##..#. 9 .#.###### #.#..#### 49 ######.########################################## ########.#############.########################## 41 ###########.#######.##################### ##############.########################## 6 ###..# ###.## 49 #################################...
output:
No Yes ###... ...### ###... ...#.# ##..#. ..##.# ##..#. Yes .#.###### #.#...... .#.###### #.#...... .#.##.... .#.##.... #.#..#### Yes ######.########################################## ......#.......................................... ......#.......................................... ######.#.#######...
result:
ok Correct.
Test #6:
score: 0
Accepted
time: 10ms
memory: 4576kb
input:
2 100000 ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.#...
output:
Yes ###.#...#..####...#####..####.#.######.##.##..#..#..####...###.#..##.#.##.####.#.#.###...#.##...####.#.#.####...####.#..##.##.#.#.....####..####..#...#..#.##..#.##.#.....#..#.#.###.#....####...####..##.#.#####..####.##.#.###.#.#....#.##.##...#.######.#..##..##...#.....#....#.####...#...##.##.#.....
result:
ok Correct.
Test #7:
score: 0
Accepted
time: 13ms
memory: 4808kb
input:
2 100000 ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##...
output:
Yes ##.####.#..#..#.##..#.#..###..##..#####.....#..##.##.#...#.###..##..#...##...####..#...##...##.......#.#..##.##..###.#.###.##.#########..#...###.####.##...#..#.....#####.....#.####.#####..#.#....#..###.#.##..#..#.##.......#.###.##...####.....######..#.##....#.#.###.#.###.#..#.....####....##........
result:
ok Correct.