QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#860099 | #9965. Game MPO | Nightmare07 | WA | 0ms | 3840kb | C++14 | 1.9kb | 2025-01-18 10:20:03 | 2025-01-18 10:20:31 |
Judging History
answer
#include <bits/stdc++.h>
#define i64 long long
using namespace std;
const int N = 15;
int n;
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
char a[N][N];
queue<pair<int, int> > q;
int Get(int Fir, int Sec) {
int Res = 0;
for (int i = 0; i < 8; i ++) {
int x = Fir + dx[i], y = Sec + dy[i];
if (x < 1 || n < x || y < 1 || n < y) continue;
if (a[x][y] == 'O' && a[Fir][Sec] == 'O') Res ++;
if (a[x][y] == 'P' && a[Fir][Sec] == 'M') Res ++;
if (a[x][y] == 'M' && a[Fir][Sec] == 'P') Res ++;
}
return Res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i ++) scanf("%s", a[i] + 1);
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
if (a[i][j] == 'M' || a[i][j] == 'P' || a[i][j] == 'O') {
q.push(make_pair(i, j));
}
}
}
int Tmp = 0, Ans = 0;
while (q.size()) {
pair<int, int> Tp = q.front();
q.pop();
for (int i = 0; i < 8; i ++) {
int x = Tp.first + dx[i], y = Tp.second + dy[i];
if (x < 1 || n < x || y < 1 || n < y) continue;
if (a[x][y] != '.') {
if (a[Tp.first][Tp.second] == 'O' && a[x][y] == 'o') {
a[x][y] = 'O';
Tmp ++;
q.push(make_pair(x, y));
}
if (a[Tp.first][Tp.second] == 'M' && a[x][y] == 'p') {
a[x][y] = 'P';
Tmp ++;
q.push(make_pair(x, y));
}
if (a[Tp.first][Tp.second] == 'P' && a[x][y] == 'm') {
a[x][y] = 'M';
Tmp ++;
q.push(make_pair(x, y));
}
}
}
}
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
Ans += Get(i, j);
}
}
Ans /= 2;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
if (a[i][j] == 'O' || a[i][j] == 'P' || a[i][j] == 'M') Ans ++;
}
}
printf("%d %d\n", Tmp, Ans);
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
printf("%c", a[i][j]);
}
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
input:
4 .pm. Mom. OOm. p..p
output:
4 13 .PM. MOM. OOm. p..p
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3840kb
input:
2 .P P.
output:
0 2 .P P.
result:
wrong answer 1st lines differ - expected: '2 2', found: '0 2'