QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#659235#9478. Shift Puzzleucup-team3586#WA 0ms3592kbC++232.6kb2024-10-19 19:20:502024-10-19 19:20:52

Judging History

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

  • [2024-10-19 19:20:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-10-19 19:20:50]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n;
char A[88][88],B[88][88];
vector<pii> ans;
void row(int r)
{
	ans.pb(1,r+1);
	char ch=A[r][n-1];
	for(int i=n-1;i;i--)
		A[r][i]=A[r][i-1];
	A[r][0]=ch;
}
void col(int c)
{
	ans.pb(2,c+1);
	char ch=A[n-1][c];
	for(int i=n-1;i;i--)
		A[i][c]=A[i-1][c];
	A[0][c]=ch;
}
void rot1(int x1,int x2,int y1,int y2)
{
	int A=(y2-y1+n)%n;
	int B=(x1-x2+n)%n;
	for(int i=0;i<A;i++)
		row(x1);
	for(int i=0;i<B;i++)
		col(y2);
	for(int i=0;i<n-A;i++)
		row(x1);
	for(int i=0;i<n-B;i++)
		col(y2);
}
void rot2(int x1,int x2,int y1,int y2)
{
	int A=(y2-y1+n)%n;
	int B=(x1-x2+n)%n;
	for(int i=0;i<B;i++)
		col(y2);
	for(int i=0;i<A;i++)
		row(x1);
	for(int i=0;i<n-B;i++)
		col(y2);
	for(int i=0;i<n-A;i++)
		row(x1);
}
void swp(int x1,int y1,int x2,int y2)
{
	assert(A[x1][y1]!=A[x2][y2]);
	if(x1==x2)
	{
		int x3=(x2+1)%n;
		int y3=y2;
		if(A[x3][y3]==A[x1][y1])
			rot2(x1,x3,y1,y2);
		else
			rot1(x1,x3,y1,y2);
		return ;
	}
	if(y1==y2)
	{
		int x3=x1;
		int y3=(y1+n-1)%n;
		if(A[x3][y3]==A[x1][y1])
			rot2(x1,x2,y3,y1);
		else
			rot1(x1,x2,y3,y1);
		return ;
	}
	if(A[x1][y2]==A[x1][y1])
		rot2(x1,x2,y1,y2);
	else
		rot1(x1,x2,y1,y2);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%s",A[i]);
	for(int i=0;i<n;i++)
		scanf("%s",B[i]);
	int c=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(A[i][j]=='#')
				c++;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(B[i][j]=='#')
				c--;
	if(c) die("No");
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(A[i][j]!=B[i][j])
			{
				for(int i2=0;i2<n;i2++)
					for(int j2=0;j2<n;j2++)
						if(mp(i2,j2)>mp(i,j)&&A[i2][j2]==B[i][j]&&B[i2][j2]!=B[i][j])
						{
							swp(i,j,i2,j2);
							goto ok;
						}
				ok:;
			}
	cout<<"Yes\n";
	cout<<sz(ans)<<'\n';
	for(auto pr:ans)
		cout<<pr.first<<" "<<pr.second<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3592kb

input:

3
.#.
#.#
.#.
#.#
...
#.#

output:

Yes
24
2 2
2 2
1 1
2 2
1 1
1 1
1 1
2 1
2 1
1 1
1 1
2 1
2 1
2 1
1 2
2 1
1 2
1 2
1 2
2 3
2 3
1 2
1 2
2 3

result:

wrong answer WA S is not T