QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#842562#9965. Game MPOucup-team133#AC ✓0ms3752kbC++232.7kb2025-01-04 13:27:252025-01-04 13:27:25

Judging History

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

  • [2025-01-04 13:27:25]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3752kb
  • [2025-01-04 13:27:25]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

template <class T, class U = T> bool chmin(T& x, U&& y) {
    return y < x and (x = std::forward<U>(y), true);
}

template <class T, class U = T> bool chmax(T& x, U&& y) {
    return x < y and (x = std::forward<U>(y), true);
}

template <class T> void mkuni(std::vector<T>& v) {
    std::ranges::sort(v);
    auto result = std::ranges::unique(v);
    v.erase(result.begin(), result.end());
}

template <class T> int lwb(const std::vector<T>& v, const T& x) {
    return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}

using namespace std;

using ll = long long;

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

void solve() {
    int n;
    cin >> n;
    vector<string> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }

    auto isin = [&](int x, int y) { return 0 <= x and x < n and 0 <= y and y < n; };
    auto calc = [&](int x, int y) -> int {
        if (S[x][y] == '.') {
            return 0;
        }
        if (not isupper(S[x][y])) {
            return 0;
        }
        int res = 0;
        for (int i = 0; i < 8; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (not isin(nx, ny)) {
                continue;
            }
            res += (S[x][y] == 'O' and S[nx][ny] == 'O');
            res += (S[x][y] == 'M' and S[nx][ny] == 'P');
            res += (S[x][y] == 'P' and S[nx][ny] == 'M');
        }
        return res;
    };
    int score = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            score += calc(i, j);
        }
    }
    assert(~score & 1);
    score /= 2;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (isupper(S[i][j])) {
                score++;
            }
        }
    }
    int init = score;
    while (true) {
        int maxi = 0, X = -1, Y = -1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (not islower(S[i][j])) {
                    continue;
                }
                S[i][j] = toupper(S[i][j]);
                if (chmax(maxi, calc(i, j))) {
                    X = i, Y = j;
                }
                S[i][j] = tolower(S[i][j]);
            }
        }
        if (maxi == 0) {
            break;
        }
        score += maxi + 1;
        S[X][Y] = toupper(S[X][Y]);
    }

    cout << init << " " << score << "\n";
    for (int i = 0; i < n; i++) {
        cout << S[i] << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    solve();
    return 0;
}

詳細信息

Test #1:

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

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

input:

2
.P
P.

output:

2 2
.P
P.

result:

ok 3 lines

Test #3:

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

input:

3
...
.pp
.m.

output:

0 0
...
.pp
.m.

result:

ok 4 lines

Test #4:

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

input:

4
....
....
....
....

output:

0 0
....
....
....
....

result:

ok 5 lines

Test #5:

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

input:

5
m....
m.Mop
OOpoo
PMp..
Oo...

output:

8 15
m....
m.Mop
OOPoo
PMP..
OO...

result:

ok 6 lines

Test #6:

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

input:

6
Mo..Op
..P.p.
p.MopP
mMpO.P
..mp.p
OM.Mo.

output:

12 26
Mo..Op
..P.p.
P.MOpP
MMPO.P
..MP.p
OM.Mo.

result:

ok 7 lines

Test #7:

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

input:

7
.M.O.M.
.PM...M
MO.MMP.
O.O.P.P
POOOOM.
MO...MP
..MOP.O

output:

53 53
.M.O.M.
.PM...M
MO.MMP.
O.O.P.P
POOOOM.
MO...MP
..MOP.O

result:

ok 8 lines

Test #8:

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

input:

8
m.mm..p.
.oo.op.p
.op.pm..
...p.pmp
.o.ooo..
m.momo.o
omp.pmmo
mp.mmo..

output:

0 0
m.mm..p.
.oo.op.p
.op.pm..
...p.pmp
.o.ooo..
m.momo.o
omp.pmmo
mp.mmo..

result:

ok 9 lines

Test #9:

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

input:

9
pp...p.pP
...PmOM.o
.MOM.M.Mm
O.op.pppP
Oo..opMp.
.pPM..p.p
.m.M.o.m.
pPP.PO.O.
mopMooom.

output:

31 93
pp...P.PP
...PMOM.o
.MOM.M.MM
O.OP.PPPP
OO..oPMP.
.PPM..P.P
.M.M.O.M.
PPP.PO.O.
MoPMOOOm.

result:

ok 10 lines

Test #10:

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

input:

10
M.oMppo..p
Pp...pmMp.
o..mp.P.m.
OMm..M..M.
OPPmM.o.M.
.pO..mOm.p
O..o..P.m.
.m..OOp.m.
p..Oomm...
.p.oMpmmp.

output:

30 86
M.oMPPo..p
PP...PMMP.
O..MP.P.M.
OMM..M..M.
OPPMM.O.M.
.pO..MOM.P
O..O..P.M.
.m..OOP.m.
p..OOMM...
.p.OMPMmp.

result:

ok 11 lines

Test #11:

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

input:

10
P.o.OoP...
Mpm.PmPpMm
p.....O..M
MpOM..Ompp
.m.Oo.pM.P
....mOmmPo
Ppoo.mm...
..OM.o.P.p
OPO....M.P
P.ooo.mP.p

output:

36 89
P.o.OOP...
MPM.PMPPMm
P.....O..M
MPOM..OMPP
.M.OO.PM.P
....mOMMPo
PpOO.mM...
..OM.o.P.p
OPO....M.P
P.OOO.MP.p

result:

ok 11 lines

Test #12:

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

input:

10
.m..Oooomo
..........
MOMoomp.Pp
..........
mMP..omOoM
.........O
mmOmoOm.PM
m.........
PmM.O.Mpp.
.........o

output:

20 37
.m..OOOOmo
..........
MOMoomp.Pp
..........
mMP..omOOM
.........O
mmOmOOm.PM
M.........
PMM.O.MPp.
.........o

result:

ok 11 lines

Test #13:

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

input:

10
Oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo
oooooooooo

output:

1 442
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO
OOOOOOOOOO

result:

ok 11 lines

Test #14:

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

input:

10
Oooooooooo
.........o
oooooooooo
o.........
oooooooooo
.........o
oooooooooo
o.........
oooooooooo
.........o

output:

1 118
OOOOOOOOOO
.........O
OOOOOOOOOO
O.........
OOOOOOOOOO
.........O
OOOOOOOOOO
O.........
OOOOOOOOOO
.........O

result:

ok 11 lines

Test #15:

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

input:

10
Mm.Op.OM.m
oP.o..mO.m
..........
pm....oo.P
pm.mp..O.o
..........
.p.m.....M
Mm.M..pM.o
..........
OP.Mp.oP.P

output:

19 36
MM.Op.OM.m
oP.O..mO.m
..........
pm....OO.P
pm.mp..O.o
..........
.P.m.....M
MM.M..PM.o
..........
OP.MP.oP.P

result:

ok 11 lines

Test #16:

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

input:

10
mpm.mpmpmp
pmpmpm..pm
mpmpm.mpmp
.mpmpmpmpm
mpmpmpmpm.
pmpm..p.p.
mpmpmpmpmp
..pmpmpm.m
mpmpmpmpmp
pmpmpmpmpM

output:

1 224
MPM.MPMPMP
PMPMPM..PM
MPMPM.MPMP
.MPMPMPMPM
MPMPMPMPM.
PMPM..P.P.
MPMPMPMPMP
..PMPMPM.M
MPMPMPMPMP
PMPMPMPMPM

result:

ok 11 lines

Test #17:

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

input:

10
OM.op.MO.o
po.MO.op.O
..........
OP.om.po.O
mO.Po.OM.o
..........
PO.mo.pp.P
Om.oP.mm.m
........O.
Oo.oO.Mp.o

output:

25 63
OM.OP.MO.O
PO.MO.OP.O
..........
OP.oM.PO.O
MO.Po.OM.O
..........
PO.Mo.pp.P
OM.oP.mm.M
........O.
OO.OO.MP.O

result:

ok 11 lines

Extra Test:

score: 0
Extra Test Passed