QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879965 | #9965. Game MPO | turkhuu | TL | 1ms | 3712kb | C++20 | 1.5kb | 2025-02-02 19:08:48 | 2025-02-02 19:08:58 |
Judging History
answer
#include <bits/stdc++.h>
#define FOR(i, a, b) for (auto i = (a); i <= (b); i++)
#define ROF(i, a, b) for (auto i = (a); i >= (b); i--)
using namespace std;
using ll = long long;
char s[12][12];
int f(int a, int b) {
if (!isupper(s[a][b])) return 0;
int cnt = 2;
FOR(i, a - 1, a + 1) {
FOR(j, b - 1, b + 1) {
if (!isupper(s[i][j]) || i == a && j == b) continue;
if (tolower(s[a][b]) == 'o' && tolower(s[i][j]) == 'o') cnt++;
if (tolower(s[a][b]) == 'm' && tolower(s[i][j]) == 'p') cnt++;
if (tolower(s[a][b]) == 'p' && tolower(s[i][j]) == 'm') cnt++;
}
}
return cnt;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
FOR(i, 1, n) FOR(j, 1, n) cin >> s[i][j];
int initial = 0;
FOR(i, 1, n) FOR(j, 1, n) initial += f(i, j);
initial /= 2;
int final = initial;
while (1) {
int mx = 0, a = 0, b = 0;
FOR(i, 1, n) {
FOR(j, 1, n) {
if (islower(s[i][j])) {
s[i][j] += 'A' - 'a';
int cnt = f(i, j) - 1;
if (cnt > mx) mx = cnt, a = i, b = j;
s[i][j] -= 'A' - 'a';
}
}
}
if (mx == 1) break;
final += mx;
s[a][b] += 'A' - 'a';
}
cout << initial << " " << final << "\n";
FOR(i, 1, n) {
FOR(j, 1, n) cout << s[i][j];
cout << "\n";
}
return 6/22;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
4 .pm. Mom. OOm. p..p
output:
4 13 .PM. MOM. OOm. p..p
result:
ok 5 lines
Test #2:
score: -100
Time Limit Exceeded
input:
2 .P P.