답안 #1003282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003282 2024-06-20T08:33:52 Z Nailuj_217 Dijamant (COCI22_dijamant) C++17
0 / 70
1 ms 604 KB
#include <bits/stdc++.h>
#define l long long
using namespace std;


const l INF = 1LL<<15;

array<vector<l>, 2005> rows;
array<l, 2005> positions;



int main() {

    l n, m;
    cin >> n >> m;
    string row;

    l sum = 0;

    for (int i = 1; i <= n; i++) {
        cin >> row;
        for (int j = 0; j < row.size(); j++) {
            if (row[j] == '#') rows[i].push_back(j+1);
        }
    }
    l dist_to_left;

    for (int i = 2; i <= n; i++) {
        positions.fill(0);
        for (int j = 1; j <= m; j++) {
            for (int k = 1; k <= n; k++) {
                if (positions[k] != INF && rows[k][positions[k]] < j) {
                    if (rows[k].size() > positions[k]+1) positions[k]++;
                    else positions[k] = INF;
                }
            }
            if (!positions[i]) continue;
            if (positions[i] == INF) continue;
            dist_to_left = j - rows[i][positions[i]-1];
            if (i-dist_to_left < 1 || i+dist_to_left > n || j + dist_to_left > m) continue;
            if (j+dist_to_left != rows[i][positions[i]]) continue;
            l c = 0;
            bool is_valid = true;
            for (int k = i - dist_to_left; k < i; k++) {
                if (c == 0) {
                    if (positions[k] == INF || rows[k][positions[k]] != j) {
                        is_valid = false;
                        break;
                    }
                } else {
                    if (positions[k] ==  INF || positions[k] == 0 || rows[k][positions[k]-1] != j-c) {
                        is_valid = false;
                        break;
                    } 
                    if (positions[k] ==  INF || positions[k] == 0 || rows[k][positions[k]] != j+c) {
                        is_valid = false;
                        break;
                    } 
                }
                c++;
            }
            c = 0;
            for (int k = i + dist_to_left; k > i; k--) {
                if (c == 0) {
                    if (positions[k] ==  INF || rows[k][positions[k]] != j) {
                        is_valid = false;
                        break;
                    }
                } else {
                    if (positions[k] ==  INF || positions[k] == 0 || rows[k][positions[k]-1] != j-c) {
                        is_valid = false;
                        break;
                    } 
                    if (positions[k] ==  INF || positions[k] == 0 || rows[k][positions[k]] != j+c) {
                        is_valid = false;
                        break;
                    } 
                }
                c++;
            }
            if (is_valid) {
                sum++;
            }

        }
    }

    cout << sum << endl;

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int j = 0; j < row.size(); j++) {
      |                         ~~^~~~~~~~~~~~
Main.cpp:34:40: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'std::array<long long int, 2005>::value_type' {aka 'long long int'} [-Wsign-compare]
   34 |                     if (rows[k].size() > positions[k]+1) positions[k]++;
      |                         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -