Submission #41008266


Source Code Expand

#include <bits/stdc++.h>

namespace {
    using Num = long long int;
}

void solve(std::istream& is, std::ostream& os) {
    using Num = long long int;
    Num h {0};
    Num w {0};
    is >> h >> w;

    std::vector<std::string> strs;
    for(decltype(h) y{0}; y<h; ++y) {
        std::string s {0};
        is >> s;
        strs.push_back(s);
    }

    std::vector<std::vector<Num>> rows(h+2);
    std::vector<std::vector<Num>> columns(w+2);
    for(decltype(h) y{0}; y<=(h+1); ++y) {
        rows[y].push_back(0);
    }

    for(decltype(w) x{0}; x<=(w+1); ++x) {
        columns[x].push_back(0);
    }

    for(decltype(h) y{0}; y<h; ++y) {
        for(decltype(w) x{0}; x<w; ++x) {
            if (strs[y][x] == '#') {
                rows[y+1].push_back(x+1);
                columns[x+1].push_back(y+1);
            }
        }
    }

    for(decltype(h) y{0}; y<=(h+1); ++y) {
        rows[y].push_back(w+1);
    }

    for(decltype(w) x{0}; x<=(w+1); ++x) {
        columns[x].push_back(h+1);
    }

    Num answer {0};
    for(decltype(h) y{1}; y<=h; ++y) {
        for(decltype(w) x{1}; x<=w; ++x) {
            if (strs[y-1][x-1] == '#') {
                continue;
            }

            auto& row = rows.at(y);
            auto it_row = std::upper_bound(row.begin(), row.end(), x);
            auto right = *it_row;
            --it_row;
            auto left = *it_row;
            const Num n_row = right - left - 1;

            auto& column = columns.at(x);
            auto it_column = std::upper_bound(column.begin(), column.end(), y);
            auto bottom = *it_column;
            --it_column;
            auto top = *it_column;
            const Num n_column = bottom - top - 1;

            const auto n = n_row + n_column - 1;
            answer = std::max(answer, n);
        }
    }

    os << answer << "\n";
    return;
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task D - Lamp
User zettsut
Language C++ (GCC 9.2.1)
Score 400
Code Size 2007 Byte
Status AC
Exec Time 342 ms
Memory 74340 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 17
Set Name Test Cases
Sample 01.txt, 02.txt
All 01.txt, 02.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt
Case Name Status Exec Time Memory
01.txt AC 6 ms 3444 KiB
02.txt AC 2 ms 3592 KiB
11.txt AC 90 ms 7816 KiB
12.txt AC 165 ms 74340 KiB
13.txt AC 279 ms 72032 KiB
14.txt AC 302 ms 22520 KiB
15.txt AC 126 ms 7680 KiB
16.txt AC 225 ms 11864 KiB
17.txt AC 342 ms 42068 KiB
18.txt AC 294 ms 69960 KiB
19.txt AC 163 ms 8224 KiB
20.txt AC 4 ms 3676 KiB
21.txt AC 2 ms 3532 KiB
22.txt AC 6 ms 4304 KiB
23.txt AC 151 ms 71704 KiB
24.txt AC 3 ms 3636 KiB
25.txt AC 3 ms 3728 KiB