QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#841992 | #9965. Game MPO | ucup-team6274# | AC ✓ | 1ms | 3860kb | C++23 | 6.1kb | 2025-01-04 09:30:05 | 2025-01-04 09:30:06 |
Judging History
answer
// Problem: G. Game MPO
// Contest: Universal Cup - The 3rd Universal Cup. Stage 24: Poland
// URL: https://contest.ucup.ac/contest/1890/problem/9965?locale=zh-cn
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Genshin Impact launch
// ZYB TXDY
//
// Powered by CP Editor (https://cpeditor.org)
//%^~
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <limits>
#include <climits>
#include <bitset>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <random>
// #include "ext/pb_ds/assoc_container.hpp"
// #include "ext/pb_ds/tree_policy.hpp"
// #include "ext/pb_ds/priority_queue.hpp"
// #include <ext/rope>
// #define PBDS __gnu_pbds
// #include <bits/extc++.h>
#define MAXN 200005
#define eps 1e-10
#define foru(a, b, c) for (int a = (b); (a) <= (c); (a)++)
#define ford(a, b, c) for (int a = (b); (a) >= (c); (a)++)
#define uLL unsigned long long
#define LL long long
#define LXF int
#define RIN Cap1taLDebug::read()
#define RSIN Cap1taLDebug::rdstr()
#define RCIN Cap1taLDebug::rdchar()
#define HH printf("\n")
#define All(x) (x).begin(), (x).end()
#define fi first
#define se second
#define CA const auto&
using namespace std;
// const int RANDOM = time(0);
// template<class T1,class T2>
// class tr1::hash<pair<T1,T2>>{
// public:
// size_t operator () (pair<T1,T2> x)const{
// tr1::hash<T1> H1;
// tr1::hash<T2> H2;
// return H1(x.fi)^H2(x.se)^RANDOM;
// }
// };
int ID;
class Cap1taLDebug{
#ifdef LXF
#define READTYPE LXF
#else
#define READTYPE int
#endif
#define DEBUGING
private:
ostream& buf;
#ifndef DEBUGING
static char fbuf[1<<21],*p1,*p2;
#define getchar() (Cap1taLDebug::p1==p2&&(p1=(p2=fbuf)+fread(fbuf,1,1<<21,stdin),p1==p2)?EOF:*p2++)
#endif
public:
Cap1taLDebug(ostream& out=cout):buf(out){}
~Cap1taLDebug(){
#ifdef DEBUGING
buf.flush();
#endif
}
static READTYPE read(){
READTYPE x=0,w=1;char ch=0;
while(!isdigit(ch)){
if(ch=='-') w=-1;
ch=getchar();
}
while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
return x*w;
}
static string rdstr(){
string s;char c=getchar();
while(c==' ' || c=='\r' || c=='\n') c=getchar();
while(c!=' ' && c!='\r' && c!='\n' && c!=EOF) s+=c,c=getchar();
return s;
}
static char rdchar(){
char c=getchar();
while(c==' ' || c=='\r' || c=='\n') c=getchar();
return c;
}
static string int128ToString(__int128 x){
if(x==0) return "0";
string s="",w="";
if(x<0) w="-",x*=-1;
while(x) s+=(char)('0'+(int)(x%10)),x/=10;
reverse(All(s));
return w+s;
}
Cap1taLDebug& operator<<(const string val){
#ifdef DEBUGING
buf<<val;
#endif
return *this;
}
template<typename T1,typename T2>
Cap1taLDebug& operator<<(const pair<T1,T2>& val){
#ifdef DEBUGING
(*this)<<"("<<val.first<<","<<val.second<<")";
#endif
return *this;
}
template<typename T,template<typename,typename...>class Container,typename...Args>
Cap1taLDebug& operator<<(const Container<T, Args...>& container){
#ifdef DEBUGING
buf<<"{";
bool fst=0;
for(const auto& val:container){
if(!fst) fst=true;
else buf<<",";
(*this)<<val;
}
buf<<"}";
#endif
return *this;
}
Cap1taLDebug& operator<<(const __int128& val){
#ifdef DEBUGING
buf<<int128ToString(val);
#endif
return *this;
}
template<typename T>
Cap1taLDebug& operator<<(const T& val){
#ifdef DEBUGING
buf<<val;
#endif
return *this;
}
Cap1taLDebug& operator<<(ostream& (*manip)(ostream&)){
#ifdef DEBUGING
buf<<manip;
#endif
return *this;
}
};
#ifndef DEBUGING
char Cap1taLDebug::fbuf[1<<21],*Cap1taLDebug::p1=nullptr,*Cap1taLDebug::p2=nullptr;
#endif
Cap1taLDebug cein(cout);
// Cap1taLDebug cein(cerr);
ostream& operator<<(ostream& os,__int128 val){
os<<Cap1taLDebug::int128ToString(val);
return os;
}
template<typename T>
class Stack : public stack<T>{
public:
void clear(){
while(!this->empty()) this->pop();
}
void popuntil(const function<bool(T)>& func){
while(!this->empty() && !func(this->top())) this->pop();
}
};
/*
*/
int n;
string s[12];
const int dx[8]={0,1,1,1,0,-1,-1,-1};
const int dy[8]={1,1,0,-1,-1,-1,0,1};
void solve(bool SPE){
n=RIN;
foru(i,1,n){
s[i]="."+RSIN+".";
}
foru(i,1,n+2){
s[0]+='.';
s[n+1]+='.';
}
int bg=0;
foru(i,1,n){
foru(j,1,n){
if(s[i][j]=='O' || s[i][j]=='M' || s[i][j]=='P'){
bg++;
char t=s[i][j];
for(int k=0;k<4;k++){
int u=i+dx[k];
int v=j+dy[k];
if(s[i][j]=='O' && s[u][v]=='O'){
bg++;
}
if(s[i][j]=='P' && s[u][v]=='M'){
bg++;
}
if(s[i][j]=='M' && s[u][v]=='P'){
bg++;
}
}
}
}
}
int tot=0;
while(1){
pair<int,pair<int,int>> Max(0,{0,0});
foru(i,1,n){
foru(j,1,n){
if(s[i][j]=='o' || s[i][j]=='m' || s[i][j]=='p'){
// char t=s[i][j]+'A'-'a';
int ct=1;
for(int k=0;k<8;k++){
int u=i+dx[k];
int v=j+dy[k];
if(s[i][j]=='o' && s[u][v]=='O'){
ct++;
}
if(s[i][j]=='p' && s[u][v]=='M'){
ct++;
}
if(s[i][j]=='m' && s[u][v]=='P'){
ct++;
}
}
Max=max(Max,make_pair(ct,make_pair(i,j)));
}
}
}
if(Max.fi<2) break;
s[Max.se.fi][Max.se.se]+='A'-'a';
tot+=Max.fi;
}
cout<<bg<<' '<<bg+tot<<endl;
foru(i,1,n){
cout<<s[i].substr(1,n)<<endl;
}
#ifdef DEBUGING
if(SPE){
}
#endif
return ;
}
/*
检查文件读写
检查多测清空
检查数组大小
*/
signed main()
{
// #define RFILE
// #define MULTITEST
// #define TESTCASEID
#ifdef RFILE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
#ifdef MULTITEST
int T=RIN;
#else
int T=1;
#endif
#ifdef TESTCASEID
ID=RIN;
#endif
for(int i=1;i<=T;i++) solve(i==0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
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: 3504kb
input:
2 .P P.
output:
2 2 .P P.
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
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: 3556kb
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: 3568kb
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: 3560kb
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: 3572kb
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: 1ms
memory: 3556kb
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: 3564kb
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: 3620kb
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: 3556kb
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: 3512kb
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: 3620kb
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: 3860kb
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: 3824kb
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