QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#842994#9965. Game MPOucup-team6275#WA 0ms3824kbC++142.2kb2025-01-04 16:18:202025-01-04 16:18:20

Judging History

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

  • [2025-01-04 16:18:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2025-01-04 16:18:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define all(a) begin(a), end(a)
#define len(a) (int)((a).size())

const int SZ = 11;
string grid[SZ];

vector<pair<int, int>> dir = { {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1} };
int n;

int score(pair<int, int> a, pair<int, int> b) {
    if (b.first >= 0 && b.second >= 0 && b.first < n && b.second < n) {
        if (grid[a.first][a.second] == 'M' && grid[b.first][b.second] == 'P') return 1;
        if (grid[a.first][a.second] == 'P' && grid[b.first][b.second] == 'M') return 1;
        if (grid[a.first][a.second] == 'O' && grid[b.first][b.second] == 'O') return 1;
        return 0;
    } else {
        return 0;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;

    for (int i = 0; i < n; ++i) cin >> grid[i];

    int cur = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (auto d : dir) {
                pair<int, int> to = {i + d.first, j + d.second};
                cur += score({i, j}, to);
            }
            cur += (grid[i][j] == 'M' || grid[i][j] == 'O' || grid[i][j] == 'P') * 2;
        }
    }
    cur /= 2;


    while (true) {
        bool inc = false;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                int old_score = cur;
                char sv = grid[i][j];
                if (grid[i][j] == 'm' || grid[i][j] == 'o' || grid[i][j] == 'p') {
                    grid[i][j] += ('M' - 'm');
                    for (auto d : dir) {
                        pair<int, int> to = {i + d.first, j + d.second};
                        cur += score({i, j}, to);
                    }
                    ++cur;

                    if (cur < old_score + 2) {
                        grid[i][j] = sv;
                        cur = old_score;
                    } else {
                        inc = true;
                    }
                }
            }
        }
        if (!inc) break;
    }

    cout << n << " " << cur << "\n";
    for (int i = 0; i < n; ++i) cout << grid[i] << "\n";

    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok 5 lines

Test #2:

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

input:

2
.P
P.

output:

2 2
.P
P.

result:

ok 3 lines

Test #3:

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

input:

3
...
.pp
.m.

output:

3 0
...
.pp
.m.

result:

wrong answer 1st lines differ - expected: '0 0', found: '3 0'