QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#843792#9965. Game MPOucup-team3608#WA 0ms3804kbC++202.8kb2025-01-05 02:26:132025-01-05 02:26:13

Judging History

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

  • [2025-01-05 02:26:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2025-01-05 02:26:13]
  • 提交

answer

#include"bits/stdc++.h"

using namespace std;

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



int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int n; cin>>n;
    vector<string> g(n);
    for(auto & s: g) cin>>s;

    vector<vector<bool>> vis(n, vector<bool>(n));
    auto inGrid = [&](int i, int j) -> bool {
        if(i < 0 || i >= n) return false;
        if(j < 0 || j >= n) return false;
        return true;
    };
    auto cntNei = [&](int i, int j, char x) -> int {
        int c = 0;
        for(auto [da, db] : dir){
            int a = i + da;
            int b = j + db;
            if(inGrid(a, b) && g[a][b] == x) c++;
        }
        return c;
    };

    auto calc = [&]()->int{
        int a = 0, b=0;
        for(int i =0; i < n; i++){
            for(int j =0; j <n; j++){
                if(g[i][j] == 'O'){
                    a++;
                    b += cntNei(i, j, 'O');
                }
                if(g[i][j] == 'M'){
                    a++;
                    b += cntNei(i, j, 'P');
                }
                if(g[i][j] == 'P'){
                    a++;
                    b += cntNei(i, j, 'M');
                }

            }
        }
        return a + b/2;
    };
    cout<<calc()<<" ";

    vector<pii> bfs;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++){
            if(g[i][j] == 'o' && cntNei(i, j, 'O')){
                vis[i][j] = true;
                bfs.emplace_back(i, j);
            }
            else if(g[i][j] == 'm' && cntNei(i, j, 'P')){
                vis[i][j] = true;
                bfs.emplace_back(i, j);
            }
            else if(g[i][j] == 'p' && cntNei(i, j, 'M')){
                vis[i][j] = true;
                bfs.emplace_back(i, j);
            }
        }
    for(int _ = 0; _ < bfs.size(); _++){
        auto [i, j] = bfs[_];
        g[i][j] += 'A' - 'a';
        for(auto [da, db] : dir){
            int a = i + da;
            int b = j + db;
            if(!inGrid(a,b)) continue;
            if(vis[a][b]) continue;
            if(g[a][b] == '.') continue;
            if(g[a][b] == 'o' && g[i][j] == 'O'){
                vis[a][a] = true;
                bfs.emplace_back(a, b);            
            }
            if(g[a][b] == 'm' && g[i][j] == 'P'){
                vis[a][a] = true;
                bfs.emplace_back(a, b);                 
            }
            if(g[a][b] == 'p' && g[i][j] == 'M'){
                vis[a][a] = true;
                bfs.emplace_back(a, b);               
            }
        }
    }
    cout<<calc()<<"\n";
    for(auto s : g){
        cout<<s<<"\n";
    }
    return 0;
}

详细

Test #1:

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

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

input:

2
.P
P.

output:

2 2
.P
P.

result:

ok 3 lines

Test #3:

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

input:

3
...
.pp
.m.

output:

0 0
...
.pp
.m.

result:

ok 4 lines

Test #4:

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

input:

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

output:

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

result:

ok 5 lines

Test #5:

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

input:

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

output:

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

result:

ok 6 lines

Test #6:

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

input:

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

output:

12 23
Mo..Op
..P.p.
P.MOpP
MMPO.P
..-P.p
OM.Mo.

result:

wrong answer 1st lines differ - expected: '12 26', found: '12 23'