QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#844456 | #9965. Game MPO | SorahISA | AC ✓ | 1ms | 3792kb | C++23 | 11.8kb | 2025-01-05 22:22:22 | 2025-01-05 22:22:23 |
Judging History
answer
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA
const vector<int> dx{1, 1, 0,-1};
const vector<int> dy{0, 1, 1, 1};
void solve() {
int N; cin >> N;
vector grid(N+2, string(N+2, '.'));
for (int i = 1; i <= N; ++i) {
cin >> grid[i], grid[i] = "." + grid[i] + ".";
}
auto calc = [&]() -> int {
int score = 0;
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) {
score += !!isupper(grid[i][j]);
for (int d : {0, 1, 2, 3}) {
if (grid[i][j] == 'M' and grid[i+dx[d]][j+dy[d]] == 'P') ++score;
if (grid[i][j] == 'P' and grid[i+dx[d]][j+dy[d]] == 'M') ++score;
if (grid[i][j] == 'O' and grid[i+dx[d]][j+dy[d]] == 'O') ++score;
}
}
return score;
};
int i_score = calc(), f_score = -1;
while (chmax(f_score, calc())) {
int flag = 1;
for (int i = 1; i <= N and flag; ++i) for (int j = 1; j <= N and flag; ++j) {
if (not islower(grid[i][j])) continue;
grid[i][j] ^= 32;
if (calc() > f_score + 1) flag = 0;
else grid[i][j] ^= 32;
}
}
print(i_score, f_score);
for (int i = 1; i <= N; ++i) print(grid[i].substr(1, N));
}
int32_t main() {
fastIO();
int t = 1; // cin >> t;
for (int _ = 1; _ <= t; ++_) {
// cout << "Case #" << _ << ": ";
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #include <bits/extc++.h>
// #include <tr2/dynamic_bitset>
using i64 = long long;
using i128 = __int128;
#define int i64
using f80 = long double;
using f128 = __float128;
#define double f80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#define popcnt(x) __builtin_popcountll(x)
// template <size_t D, typename T> struct Vec : vector<Vec<D-1, T>> {
// static_assert(D >= 1, "Vector dimension must be greater than zero!");
// template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D-1, T>>(n, Vec<D-1, T>(args...)) {}
// };
// template <typename T> struct Vec<1, T> : vector<T> {
// Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
// };
template <typename T> ostream& operator << (ostream &os, const vector<T> &vec)
{ for (size_t i = 0; i < size(vec); ++i) { if (i) os << " "; os << vec[i]; } return os; }
#ifdef local
#define fastIO() void()
#define debug(...) \
_color.emplace_back("\u001b[31m"), \
fprintf(stderr, "%sAt [%s], line %d: (%s) = ", _color.back().c_str(), __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), _color.pop_back(), \
fprintf(stderr, "%s", _color.back().c_str())
#define print(...) \
fprintf(stdout, "%s", "\u001b[36m"), \
_P(__VA_ARGS__), \
fprintf(stdout, "%s", "\u001b[0m")
deque<string> _color{"\u001b[0m"};
template <typename T> concept is_string = is_same_v<T, string&> or is_same_v<T, const string&>;
template <typename T> concept is_iterable = requires (T _t) { begin(_t); };
template <typename T> inline void _print_err(T &&_t);
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(const tuple<U...> &_t);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(tuple<U...> &_t);
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu);
inline void _do() { cerr << "\n"; }
template <typename T> inline void _do(T &&_t) { _print_err(_t), cerr << "\n"; }
template <typename T, typename ...U> inline void _do(T &&_t, U &&..._u) { _print_err(_t), cerr << ", ", _do(_u...); }
#else
#define fastIO() cin.tie(0)->sync_with_stdio(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#endif
inline void _P() { cout << "\n"; }
template <typename T> inline void _P(T &&_t) { cout << _t << "\n"; }
template <typename T, typename ...U> inline void _P(T &&_t, U &&..._u) { cout << _t << " ", _P(_u...); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int getRand(int L, int R) {
if (L > R) swap(L, R);
return (int)(rng() % ((uint64_t)R - L + 1) + L);
}
template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }
template <typename T> void make_unique(vector<T> &vec) {
if (not is_sorted(ALL(vec))) sort(ALL(vec));
vec.erase(unique(ALL(vec)), end(vec));
}
/// below are Fast I/O and _print_err templates ///
/*
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
#include <unistd.h>
const int S = 65536;
int OP = 0;
char OB[S];
inline char RC() {
static char buf[S], *p = buf, *q = buf;
return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++;
}
inline int RI() {
static char c;
int a;
while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1);
if (c == '-') {
a = 0;
while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0';
}
else {
a = c ^ '0';
while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0';
}
return a;
}
inline void WI(int n, char c = '\n') {
static char buf[20], p;
if (n == 0) OB[OP++] = '0';
p = 0;
if (n < 0) {
OB[OP++] = '-';
while (n) buf[p++] = '0' - (n % 10), n /= 10;
}
else {
while (n) buf[p++] = '0' + (n % 10), n /= 10;
}
for (--p; p >= 0; --p) OB[OP++] = buf[p];
OB[OP++] = c;
if (OP > S-20) write(1, OB, OP), OP = 0;
}
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
*/
#ifdef local
template <typename T> inline void _print_err(T &&_t) { cerr << _t; }
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back() << "[";
for (bool _first = true; auto &_x : _t) {
if (!_first) cerr << ", ";
_print_err(_x), _first = false;
}
cerr << "]" << (_color.pop_back(), _color.back());
}
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back() << "(";
_print_err(_tu.first), cerr << ", ", _print_err(_tu.second);
cerr << ")" << (_color.pop_back(), _color.back());
return os;
}
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &) {
cerr << ")" << (_color.pop_back(), _color.back());
}
template <size_t I = 0, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(const tuple<U...> &_t) {
if (!I) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back();
}
cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &) {
cerr << ")" << (_color.pop_back(), _color.back());
}
template <size_t I = 0, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(tuple<U...> &_t) {
if (!I) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back();
}
cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}
#endif
#endif
/**
*
*
*
* iiiiii iiiiiiiiii iiiiiiiiiiiiii
* iiiiiiiiiiiii iiiiiii iiii iiiiiiiiiiiiiii ii iiii
* iiiiiiii iiiiiiiii iiii iiii iii iii iiiiiiiiii
* iiiiiii iiiiii iiii iiii ii iiiiiiiiii iiii iiii
* iiiiii iiiii iiii iiii iii iiii iiiiiiiiiiiiiiiii ii
* iiiiii iiiiiii iiiiiii iiiiiiii iii iiiiiiiiiiiiii iii iiii
* iiiiii iiiiiii iiiii ii iiii iiiiiiiiiii iiii iii iiii iiii iii
* iiiii iiiiiiii ii iiiii iiii iiiiiiiii iii iii iii iii ii iiii
* iiiiii iiiiiiii iiiii iiiii iiiiiiiiiiiiiiii iii iii ii iii iii iiii
* iiiii iiiiii iiii iiiiii iiiiiii iii iii iiii ii i ii iii iii
* iiiiii iiii iiiiiiiiiiiiiii iii iiii iiiii iii ii iii iii ii
* iiiii iiiiiiii iiiiiiiiii iiii iiiiiiiii ii iii ii
* iiiii iiiiii iiii iiiii iii ii ii i
* iiiiii iiiiiiii iiiii iiiii ii ii ii
* iiiii iiii iiii iiiiiiiiiiii ii
* iii iiii iiii iiiiiiii
* iiiii iiii
* iiii iiii
* iiii iiiii
* iii iiiii
* iii iiiii
* iii iiiiii
* iiiiiiiii
* iiiiii
*
*
*
**/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 3632kb
input:
2 .P P.
output:
2 2 .P P.
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
3 ... .pp .m.
output:
0 0 ... .pp .m.
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
4 .... .... .... ....
output:
0 0 .... .... .... ....
result:
ok 5 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3600kb
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: 3604kb
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: 3556kb
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: 3792kb
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: 3632kb
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: 3608kb
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: 3672kb
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: 3620kb
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: 3620kb
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: 3604kb
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: 3556kb
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: 1ms
memory: 3600kb
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: 3604kb
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