QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#843071#9965. Game MPOucup-team3670#RE 0ms3700kbC++171.8kb2025-01-04 16:38:282025-01-04 16:38:31

Judging History

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

  • [2025-01-04 16:38:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3700kb
  • [2025-01-04 16:38:28]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;   

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

int n;
vector<string> p;

bool read()
{
	if (!(cin >> n))
		return false;
	p.resize(n);
	fore (i, 0, n)
		cin >> p[i];
	return true;
}

int dx[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };

int check(char a, char b) {
	if (a == '.' || b == '.')
		return 0;
	if (islower(a) || islower(b))
		return 0;
	if (a == 'O' && b == 'O')
		return 1;
	if (a == 'M' && b == 'P')
		return 1;
	if (a == 'P' && b == 'M')
		return 1;
	return 0;	
}

bool inside(int x, int y) {
	return 0 <= x && x < n && 0 <= y && y < n;
}

void solve()
{
	int init = 0;
	fore (x, 0, n) fore (y, 0, n) fore (k, 0, 4) {
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (inside(nx, ny))
			init += check(p[x][y], p[nx][ny]);
	}
	fore (x, 0, n) fore (y, 0, n)
		if (p[x][y] != '.' && isupper(p[x][y]))
			init++;
	cout << init;
	
	while (true) {
		int mx = -1;
		int cx = -1, cy = -1;
		fore (x, 0, n) fore (y, 0, n) {
			if (p[x][y] == '.' || isupper(p[x][y]))
				continue;
			p[x][y] = toupper(p[x][y]);
			int cur = 0;
			fore (k, 0, 8) {
				int nx = x + dx[k];
				int ny = y + dy[k];
				if (inside(nx, ny))
					cur += check(p[x][y], p[nx][ny]);
			}
			if (mx < cur) {
				mx = cur;
				cx = x, cy = y;
			}
			p[x][y] = tolower(p[x][y]);
		}
		if (mx == 0)
			break;
		
		init += 1 + mx;
		p[cx][cy] = toupper(p[cx][cy]);
	}
	
	cout << " " << init << endl;
	fore (i, 0, n)
		cout << p[i] << endl;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	forn(i, t)
	{
	 	read();
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
.pm.
Mom.
OOm.
p..p

output:

4 13
.PM.
MOM.
OOm.
p..p

result:

ok 5 lines

Test #2:

score: -100
Runtime Error

input:

2
.P
P.

output:


result: