Submission #29702213


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)

std::vector<std::string> split(const std::string& text, const char delim);

using ll = long long int;
using llu = unsigned long long int;

const char B = '#';
const char W = '.';

void show(const vector<vector<char>>& table){
    for (const auto& line : table) {
        for (const auto& item : line) {
            cout << item;
        }
        cout << endl;
    }
}

enum class Direction{
    UP = 0,
    DOWN,
    LEFT,
    RIGHT,
    UP_LEFT,
    UP_RIGHT,
    DOWN_LEFT,
    DOWN_RIGHT
};

const vector<Direction> all_dir = {
    Direction::UP,
    Direction::DOWN,
    Direction::LEFT,
    Direction::RIGHT,
    Direction::UP_LEFT,
    Direction::UP_RIGHT,
    Direction::DOWN_LEFT,
    Direction::DOWN_RIGHT
};

// pair(Y, X)
const map<Direction, pair<int, int>> dir_map = {
    {Direction::UP, make_pair(-1, 0)},
    {Direction::DOWN, make_pair(+1, 0)},
    {Direction::LEFT, make_pair(0, -1)},
    {Direction::RIGHT, make_pair(0, +1)},
    {Direction::UP_LEFT, make_pair(-1, -1)},
    {Direction::UP_RIGHT, make_pair(-1, 1)},
    {Direction::DOWN_LEFT, make_pair(+1, -1)},
    {Direction::DOWN_RIGHT, make_pair(+1, +1)},
};

int count_b_line(const int N, const vector<vector<char>>& table, const int i, const int j){
    map<char, int> count;

    for (const auto& dir : all_dir) {
        count[B] = 0;
        count[W] = 0;
        int next_i = i;
        int next_j = j;

        for (int n = 0; n < 6; ++n) {
            count[table[next_i][next_j]]++;

            if (2 < count[W]) {
                count[W] = 2;
                break;
            }

            const auto& target_dir = dir_map.at(dir);
            next_i += target_dir.first;
            next_j += target_dir.second;

            if (next_i < 0 || N <= next_i) {
                break;
            }
            if (next_j < 0 || N <= next_j) {
                break;
            }
        }
        if (6 <= count[B] + count[W]) {
            return 6;
        }
    }

    return 0;
}

int main(){
    string buffer;
    getline(cin, buffer);
    const int N = stoi(buffer);

    vector<vector<char>> table;
    vector<pair<int, int>> b_point;

    table.resize(N);

    for (int i = 0; i < N; ++i) {
        table[i].reserve(N);
        getline(cin, buffer);

        for (int j = 0; j < N; ++j) {
            if (buffer[j] == B) {
                b_point.emplace_back(make_pair(i, j));
            }
            table[i].emplace_back(buffer[j]);
        }
    }

    for (const auto& p : b_point) {
        if (6 <= count_b_line(N, table, p.first, p.second)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

std::vector<std::string> split(const std::string& text, char delim) {
    std::vector<std::string> elems;
    std::stringstream ss(text);
    std::string item;
    while (std::getline(ss, item, delim)) {
    if (!item.empty()) {
            elems.emplace_back(item);
        }
    }
    return elems;
}

Submission Info

Submission Time
Task C - Connect 6
User low10603
Language C++ (GCC 9.2.1)
Score 300
Code Size 3200 Byte
Status AC
Exec Time 165 ms
Memory 12000 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 33
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt
Case Name Status Exec Time Memory
example_00.txt AC 8 ms 3416 KiB
example_01.txt AC 2 ms 3604 KiB
example_02.txt AC 2 ms 3588 KiB
hand_00.txt AC 29 ms 4484 KiB
hand_01.txt AC 29 ms 4636 KiB
hand_02.txt AC 28 ms 4596 KiB
hand_03.txt AC 22 ms 4492 KiB
hand_04.txt AC 23 ms 4644 KiB
hand_05.txt AC 24 ms 4604 KiB
hand_06.txt AC 28 ms 4592 KiB
hand_07.txt AC 28 ms 4556 KiB
hand_08.txt AC 165 ms 6040 KiB
hand_09.txt AC 37 ms 12000 KiB
hand_10.txt AC 24 ms 4612 KiB
hand_11.txt AC 3 ms 3476 KiB
random_00.txt AC 27 ms 4640 KiB
random_01.txt AC 27 ms 4308 KiB
random_02.txt AC 26 ms 4580 KiB
random_03.txt AC 30 ms 4544 KiB
random_04.txt AC 29 ms 4544 KiB
random_05.txt AC 3 ms 3500 KiB
random_06.txt AC 38 ms 4616 KiB
random_07.txt AC 33 ms 4580 KiB
random_08.txt AC 29 ms 4640 KiB
random_09.txt AC 32 ms 4548 KiB
random_10.txt AC 33 ms 4592 KiB
random_11.txt AC 31 ms 4260 KiB
random_12.txt AC 31 ms 4652 KiB
random_13.txt AC 29 ms 4484 KiB
random_14.txt AC 34 ms 4420 KiB
random_15.txt AC 33 ms 4572 KiB
random_16.txt AC 31 ms 4652 KiB
random_17.txt AC 2 ms 3624 KiB