Submission #17836742


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int main(){
    int W, H;
    cin >> W >> H;
    vector<vector<int>> building(H+2, vector<int>(W+2));
    for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) cin >> building[i][j];

    vector<vector<int>> outside(H+2, vector<int>(W+2));

    auto inside = [&](int i, int j){ return 0<=i && i<=H+1 && 0<=j && j<=W+1; };
    auto neighbor = [&](int i, int j){
        vector<pair<int, int>> cand, res;
        if(i%2){
            cand = {{i-1, j}, {i-1, j+1}, {i, j-1}, {i, j+1}, {i+1, j}, {i+1, j+1}};
        }else{
            cand = {{i-1, j-1}, {i-1, j}, {i, j-1}, {i, j+1}, {i+1, j-1}, {i+1, j}};
        }
        for(auto [x, y] : cand) if(inside(x, y)) res.emplace_back(x, y);
        return res;
    };

    queue<pair<int, int>> que;
    que.emplace(0, 0);
    outside[0][0] = 1;
    while(que.size()){
        auto [i, j] = que.front(); que.pop();
        for(auto [x, y] : neighbor(i, j)) if(!building[x][y] && !outside[x][y]){
            outside[x][y] = 1;
            que.emplace(x, y);
        }
    }

    int ans = 0;
    for(int i=0; i<=H+1; i++) for(int j=0; j<=W+1; j++) if(outside[i][j]){
        for(auto [x, y] : neighbor(i, j)) if(!outside[x][y]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task E - イルミネーション (Illumination)
User betrue12
Language C++ (GCC 9.2.1)
Score 100
Code Size 1311 Byte
Status AC
Exec Time 10 ms
Memory 3652 KB

Judge Result

Set Name set01 set02 set03 set04 set05
Score / Max Score 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
Case Name Status Exec Time Memory
data1 AC 10 ms 3616 KB
data2 AC 5 ms 3460 KB
data3 AC 10 ms 3580 KB
data4 AC 9 ms 3584 KB
data5 AC 7 ms 3652 KB