QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553778#8935. Puzzle: Easy as Scrabbleucup-team191#WA 0ms3816kbC++235.6kb2024-09-08 20:09:552024-09-08 20:09:55

Judging History

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

  • [2024-09-08 20:09:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-09-08 20:09:55]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=3010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int n,m;
string h[N];
char cl[N],cr[N],cu[N],cd[N];
bool el[N],er[N],eu[N],ed[N];

bool hand(int i,int j,char clot,char clh,bool&ok)
{
	//cout<<i<<' '<<j<<' '<<clot<<' '<<clh<<en;
	if (h[i][j]==clh)
	{
		ok=1;
		return 1;
	}
	if (h[i][j]=='x') return 0;
	if (h[i][j]=='.')
	{
		if (clot=='.' || clot==clh)
		{
			h[i][j]=clh;
			ok=1;
			return 1;
		}
		h[i][j]='x';
		return 0;
	}
	else return 1;
}

void no()
{
	cout<<"NO\n";
	exit(0);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	for (int i=0;i<=n+1;++i) cin>>h[i];
	for (int i=1;i<=n;++i)
	{
		cl[i]=h[i][0];
		cr[i]=h[i][m+1];
	}
	for (int i=1;i<=m;++i)
	{
		cu[i]=h[0][i];
		cd[i]=h[n+1][i];
	}
	int n1=n,m1=m,off=0;
	bool ruined=0;
	while (n1>0 && m1>0)
	{
		//first up
		bool ok;
		int i;
		if (cu[off+1]!='.')
		{
			ok=0;
			for (i=1;i<=n1;++i) if (hand(off+i,off+1,cl[i+off],cu[off+1],ok)) break;
			if (!ok && !(i==n1+1 && eu[off+1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"first up"<<en;
		if (m1>1 && cu[off+m1]!='.')
		{
			//last up
			ok=0;
			for (i=1;i<=n1;++i) if (hand(off+i,off+m1,cr[i+off],cu[off+m1],ok)) break;
			if (!ok && !(i==n1+1 && eu[off+m1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"last up"<<en;
		//first down
		if (cd[off+1]!='.')
		{
			ok=0;
			for (i=n1;i>=1;--i) if (hand(off+i,off+1,cl[i+off],cd[off+1],ok)) break;
			if (!ok && !(i==0 && ed[off+1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"first down"<<en;
		//last down
		if (m1>1 && cd[off+m1]!='.')
		{
			ok=0;
			for (i=n1;i>=1;--i) if (hand(off+i,off+m1,cr[i+off],cd[off+m1],ok)) break;
			if (!ok && !(i==0 && ed[off+m1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"last down"<<en;
		//first left
		if (cl[off+1]!='.')
		{
			ok=0;
			for (i=1;i<=m1;++i) if (hand(off+1,off+i,cu[i+off],cl[off+1],ok)) break;
			if (!ok && !(i==m1+1 && el[off+1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"first left"<<en;
		//last left
		if (n1>1 && cl[off+n1]!='.')
		{
			ok=0;
			for (i=1;i<=m1;++i) if (hand(off+n1,off+i,cd[i+off],cl[off+n1],ok)) break;
			if (!ok && !(i==m1+1 && el[off+n1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"last left"<<en;
		//first right
		if (cr[off+1]!='.')
		{
			ok=0;
			for (i=m1;i>=1;--i) if (hand(off+1,off+i,cu[i+off],cr[off+1],ok)) break;
			if (!ok && !(i==0 && er[off+1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"first right"<<en;
		//last right
		if (n1>1 && cr[off+n1]!='.')
		{
			ok=0;
			for (i=m1;i>=1;--i) if (hand(off+n1,off+i,cd[i+off],cr[off+n1],ok)) break;
			if (!ok && !(i==0 && er[off+n1]))
			{
				ruined=1;
				break;
			}
		}
		//cout<<"last right"<<en;
		//others up
		for (i=2;i<m1;++i) if ((h[off+1][off+i]=='.' || h[off+1][off+i]==cu[i+off]) && cu[i+off]!='.')
		{
			h[off+1][off+i]=cu[i+off];
			cu[i+off]='.';
		}
		//others down
		for (i=2;i<m1;++i) if ((h[off+n1][off+i]=='.' || h[off+n1][off+i]==cd[i+off]) && cd[i+off]!='.')
		{
			h[off+n1][off+i]=cd[i+off];
			cd[i+off]='.';
		}
		//others left
		for (i=2;i<n1;++i) if ((h[off+i][off+1]=='.' || h[off+i][off+1]==cl[i+off]) && cl[i+off]!='.')
		{
			h[off+i][off+1]=cl[i+off];
			cl[i+off]='.';
		}
		//others right
		for (i=2;i<n1;++i) if ((h[off+i][off+m1]=='.' || h[off+i][off+m1]==cr[i+off]) && cr[i+off]!='.')
		{
			h[off+i][off+m1]=cr[i+off];
			cr[i+off]='.';
		}
		//part 2
		//others up
		for (i=2;i<m1;++i) if ((h[off+n1][off+i]=='.' || h[off+n1][off+i]==cu[i+off]) && cu[i+off]!='.')
		{
			h[off+n1][off+i]=cu[i+off];
			eu[i+off]=1;
		}
		//others down
		for (i=2;i<m1;++i) if ((h[off+1][off+i]=='.' || h[off+1][off+i]==cd[i+off]) && cd[i+off]!='.')
		{
			h[off+1][off+i]=cd[i+off];
			ed[i+off]=1;
		}
		//others left
		for (i=2;i<n1;++i) if ((h[off+i][off+m1]=='.' || h[off+i][off+m1]==cl[i+off]) && cl[i+off]!='.')
		{
			h[off+i][off+m1]=cl[i+off];
			el[i+off]=1;
		}
		//others right
		for (i=2;i<n1;++i) if ((h[off+i][off+1]=='.' || h[off+i][off+1]==cr[i+off]) && cr[i+off]!='.')
		{
			h[off+i][off+1]=cr[i+off];
			er[i+off]=1;
		}
		++off;
		n1-=2;
		m1-=2;
	}
	//cout<<n1<<' '<<m1<<' '<<off<<en;
	//for (int i=1;i<=n;++i,cout<<en) for (int j=1;j<=n;++j) cout<<h[i][j];
	if (ruined) no();
	for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) if (h[i][j]=='x') h[i][j]='.';
	//try up
	for (int j=1;j<=m;++j)
	{
		char prv='.';
		for (int i=1;i<=n;++i) if (h[i][j]!='.')
		{
			prv=h[i][j];
			break;
		}
		if (prv!=cu[j] && cu[j]!='.')
		{
			cout<<"U"<<prv<<' '<<cu[j]<<en;
			no();
		}
	}
	//try down
	for (int j=1;j<=m;++j)
	{
		char prv='.';
		for (int i=n;i>=1;--i) if (h[i][j]!='.')
		{
			prv=h[i][j];
			break;
		}
		if (prv!=cd[j] && cd[j]!='.')
		{
			cout<<"D"<<prv<<' '<<cd[j]<<en;
			no();
		}
	}
	//try left
	for (int i=1;i<=n;++i)
	{
		char prv='.';
		for (int j=1;j<=m;++j) if (h[i][j]!='.')
		{
			prv=h[i][j];
			break;
		}
		if (prv!=cl[i] && cl[i]!='.') no();
	}
	//try right
	for (int i=1;i<=n;++i)
	{
		char prv='.';
		for (int j=m;j>=1;--j) if (h[i][j]!='.')
		{
			prv=h[i][j];
			break;
		}
		if (prv!=cr[i] && cr[i]!='.') no();
	}
	cout<<"YES\n";
	for (int i=1;i<=n;++i,cout<<en) for (int j=1;j<=n;++j) cout<<h[i][j];
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3736kb

input:

5 5
.CBA...
....x..
..x...C
A.....B
B..x..A
C......
.......

output:

YES
CBA..
....C
A...B
B...A
C....

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

1 2
....
Nx..
..O.

output:

NO

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

5 5
.U.N.X.
U....xX
Ox....X
M...xxN
Vx....S
Ix.x..X
..IBHX.

output:

YES
U.NX.
.O..X
MNN..
.VB.S
.I.HX

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

10 10
.BAZEMIEKUJ.
A..........K
B..x.x.x..x.
K.........xT
A.x..x.....J
Hx....x....B
Q..x....x.xW
S...x......W
S...x.xxx..Z
...x......xZ
I..x..x.x.xR
.QKO.ID..RW.

output:

YES
.AZEMIEK..
B.......U.
K.......T.
A........J
.H.......B
Q.......W.
S........W
S.O.....Z.
QK...D..Z.
...II...R.

result:

ok Correct.

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3660kb

input:

5 10
.PTWIVVISPY.
T...x.x....Y
Xx.x.xx..x.K
P.x.xx.....K
S..........A
E.........xS
.SPEASDCYSA.

output:

YES
.TW.V
.X.I.
P....
SP...
..EAS

result:

wrong answer Token parameter [name=row] equals to ".TW.V", doesn't correspond to pattern "[A-Z.]{10}"