QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#878488#9621. 连方galiyuuRE 1ms3712kbC++232.7kb2025-02-01 15:36:572025-02-01 15:36:57

Judging History

This is the latest submission verdict.

  • [2025-02-01 15:36:57]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3712kb
  • [2025-02-01 15:36:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n'
#define SZ(x) ((ll)(x).size())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
int rnd(int x){return mrand()%x;}
const ll mod=998244353;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int tc;
	cin>>tc;
	while (tc--) {
		int n;
		string a,b;
		cin>>n;
		cin>>a>>b;
		vector<vi> ans(7,vi(n));
		vi e_a,e_b;
		int cnt1=0,cnt2=0;
		int ok1=1,ok2=1;	
		for (int i=0,j=0;i<n;i++) {
			if (a[i]=='.') ok1=0;
			j=i;
			while (j<n&&a[i]==a[j]) j++;
			if (a[i]=='#') cnt1++;
			i=j-1;
		}
		for (int i=0,j=0;i<n;i++) {
			if (b[i]=='.') ok2=0;
			j=i;
			while (j<n&&b[i]==b[j]) j++;
			if (b[i]=='#') cnt2++;
			i=j-1;
		}
		if (ok1^ok2) {
			cout<<"No"<<endl;
			continue;
		}
		if (ok1==1&&ok2==1) {
			cout<<"Yes"<<endl;
			cout<<a<<endl;
			rep(i,0,5) {
				rep(j,0,n) cout<<"#";
				cout<<endl;
			}
			cout<<b<<endl;
			continue;
		}
		// cerr<<cnt1<<" "<<cnt2<<endl;
		int usd1=0,usd2=0;
		if (cnt1==1) {
			for (int i=0;i<n;i++) {
				if (a[i]=='.') e_a.pb(i);
			}
		} else {
			for (int i=0;i<n;i++) {
				if (a[i]=='.') ans[1][i]=1;
				else e_a.pb(i);
			}
			usd1=1;
		}
		if (cnt2==1) {
			for (int i=0;i<n;i++) {
				if (b[i]=='.') e_b.pb(i);
			}
		} else {
			for (int i=0;i<n;i++) {
				if (b[i]=='.') ans[5][i]=1;
				else e_b.pb(i);
			}
			usd2=1;
		}
		// for (auto x:e_a) cerr<<x<<" ";
		// cerr<<endl;
		// for (auto x:e_b) cerr<<x<<" ";
		// cerr<<endl<<endl;
		int sz1=SZ(e_a),sz2=SZ(e_b);
		int mnd=1E8,tp=-1,dw=-1;
		for (int i=0;i<sz1;i++) {
			auto it=lower_bound(all(e_b),e_a[i])-e_b.begin();
			if (SZ(e_b)&&it<SZ(e_b)) {
				int d=abs(e_a[i]-e_b[it]);
				if (d<mnd) {
					mnd=d;
					tp=e_a[i],dw=e_b[it];
				}
			}
			it++;
			if (SZ(e_b)&&it<SZ(e_b)) {
				int d=abs(e_a[i]-e_b[it]);
				if (d<mnd) {
					mnd=d;
					tp=e_a[i],dw=e_b[it];
				}
			}
		}
		// cerr<<tp<<" "<<dw<<endl;
		if (abs(tp-dw)>(4-usd1-usd2)) {
			cout<<"No"<<endl;
			continue;
		}
		int t=1+usd1,e=5-usd2;
		int nw=tp;
		for (int i=t;i<=e;i++) {
			ans[i][nw]=1;
			if (nw==dw) continue;
			else if (nw<dw) nw++;
			else nw--;
		}
		cout<<"Yes"<<endl;
		cout<<a<<endl;
		for (int i=1;i<=5;i++) {
			for (int j=0;j<n;j++) {
				if (ans[i][j]) cout<<"#";
				else cout<<".";
			}
			cout<<endl;
		}
		cout<<b<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct.

Test #2:

score: -100
Runtime Error

input:

10000
6
.#..##
..#...
5
#..#.
##...
6
.###.#
...###
17
.####..#######..#
###########.#####
6
..##.#
#.##.#
25
#.##.##############.####.
####################.##.#
9
##.#..##.
##..#####
6
.###.#
##.###
6
###..#
#.####
25
#####################.#.#
######.##################
6
.#.###
.##..#
6
..####
#......

output:

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

result: