QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#553720#8935. Puzzle: Easy as Scrabbleucup-team191#WA 0ms3784kbC++234.7kb2024-09-08 19:00:242024-09-08 19:00:25

Judging History

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

  • [2024-09-08 19:00:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2024-09-08 19:00:24]
  • 提交

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 hand(int i,int j,char clot,char clh,bool&ok)
{
	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;
		if (cu[off+1]!='.')
		{
			ok=0;
			for (int i=1;i<=n1;++i) if (hand(off+i,off+1,cl[i+off],cu[off+1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		if (m1>1 && cu[off+m1]!='.')
		{
			//last up
			ok=0;
			for (int i=1;i<=n1;++i) if (hand(off+i,off+m1,cr[i+off],cu[off+m1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		//first down
		if (cd[off+1]!='.')
		{
			ok=0;
			for (int i=n1;i>=1;--i) if (hand(off+i,off+1,cl[i+off],cd[off+1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		//last down
		if (m1>1 && cd[off+m1]!='.')
		{
			ok=0;
			for (int i=n1;i>=1;--i) if (hand(off+i,off+m1,cr[i+off],cd[off+m1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		//first left
		if (cl[off+1]!='.')
		{
			ok=0;
			for (int i=1;i<=m1;++i) if (hand(off+1,off+i,cu[i+off],cl[off+1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		//last left
		if (n1>1 && cl[off+n1]!='.')
		{
			ok=0;
			for (int i=1;i<=m1;++i) if (hand(off+n1,off+i,cd[i+off],cl[off+n1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		//first right
		if (cr[off+1]!='.')
		{
			ok=0;
			for (int i=m1;i>=1;--i) if (hand(off+1,off+i,cu[i+off],cr[off+1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		//last right
		if (n1>1 && cr[off+n1]!='.')
		{
			ok=0;
			for (int i=m1;i>=1;--i) if (hand(off+n1,off+i,cd[i+off],cr[off+n1],ok)) break;
			if (!ok)
			{
				ruined=1;
				break;
			}
		}
		//others up
		for (int i=2;i<m1;++i) if (h[off+1][off+i]=='.' && cu[i+off]!='.')
		{
			h[off+1][off+i]=cu[i+off];
			cu[i+off]='.';
		}
		//others down
		for (int i=2;i<m1;++i) if (h[off+n1][off+i]=='.' && cd[i+off]!='.')
		{
			h[off+n1][off+i]=cd[i+off];
			cd[i+off]='.';
		}
		//others left
		for (int i=2;i<n1;++i) if (h[off+i][off+1]=='.' && cl[i+off]!='.')
		{
			h[off+i][off+1]=cl[i+off];
			cl[i+off]='.';
		}
		//others right
		for (int i=2;i<n1;++i) if (h[off+i][off+m1]=='.' && cr[i+off]!='.')
		{
			h[off+i][off+m1]=cr[i+off];
			cr[i+off]='.';
		}
		//part 2
		//others up
		for (int i=2;i<m1;++i) if (h[off+n1][off+i]=='.' && cu[i+off]!='.')
		{
			h[off+n1][off+i]=cu[i+off];
		}
		//others down
		for (int i=2;i<m1;++i) if (h[off+1][off+i]=='.' && cd[i+off]!='.')
		{
			h[off+1][off+i]=cd[i+off];
		}
		//others left
		for (int i=2;i<n1;++i) if (h[off+i][off+m1]=='.' && cl[i+off]!='.')
		{
			h[off+i][off+m1]=cl[i+off];
		}
		//others right
		for (int i=2;i<n1;++i) if (h[off+i][off+1]=='.' && cr[i+off]!='.')
		{
			h[off+i][off+1]=cr[i+off];
		}
		++off;
		n1-=2;
		m1-=2;
	}
	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];
}

详细

Test #1:

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

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

input:

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

output:

NO

result:

ok Correct.

Test #3:

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

input:

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

output:

NO

result:

wrong answer Jury has answer but participant has not.