Submission #1003388

# Submission time Handle Problem Language Result Execution time Memory
1003388 2024-06-20T09:35:55 Z Nailuj_217 Dijamant (COCI22_dijamant) C++17
70 / 70
159 ms 36352 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;


//i is current y
//k is the x
void update(l k, l j) {
    if (positions[k] == INF) return;
    if (rows[k].empty()) {
        positions[k] = INF;
        return;
    }
    while (rows[k][positions[k]] < j) {
        if (rows[k].size() > positions[k]+1) positions[k]++; 
        else {
            positions[k] = INF;
            return;
        }
    }
}

int main() {

    l n, m;
    cin >> n >> m;
    string row;
    if (n == 1 || m == 1) {
        cout << 0 << endl;
        return 0;
    }

    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 ++) 
            //     update(k, j);

            update(i, j);

            if (!positions[i]) continue;
            if (positions[i] == INF) continue;
            dist_to_left = j - rows[i][positions[i]-1];
            assert(dist_to_left >= 0);
            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;

            bool is_valid = true;

            if (!is_valid) continue;
            l c = 0;
            for (int k = i - dist_to_left; k < i; k++) {
                update(k, j);
                assert(k > 0);
                if (positions[k] == INF) {
                    is_valid = false;
                    break;
                }
                if (c == 0) {
                    if (rows[k][positions[k]] != j) {
                        is_valid = false;
                        break;
                    }
                } else {
                    if (positions[k] == 0 || rows[k][positions[k]-1] != j-c) {
                        is_valid = false;
                        break;
                    } 
                    if (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--) {
                update(k, j);
                assert(k <= n);
                if (positions[k] == INF) {
                    is_valid = false;
                    break;
                }
                if (c == 0) {
                    if (rows[k][positions[k]] != j) {
                        is_valid = false;
                        break;
                    }
                } else {
                    if (positions[k] == 0 || rows[k][positions[k]-1] != j-c) {
                        is_valid = false;
                        break;
                    } 
                    if (positions[k] == 0 || rows[k][positions[k]] != j+c) {
                        is_valid = false;
                        break;
                    } 
                }
                c++;
            }
            if (is_valid) {
                sum++;
             continue;}
        }
    }



    cout << sum << endl;





    return 0;
}

Compilation message

Main.cpp: In function 'void update(long long int, long long int)':
Main.cpp:21:28: 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]
   21 |         if (rows[k].size() > positions[k]+1) positions[k]++;
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int j = 0; j < row.size(); j++) {
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 48 ms 4044 KB Output is correct
15 Correct 71 ms 34384 KB Output is correct
16 Correct 105 ms 19024 KB Output is correct
17 Correct 67 ms 7508 KB Output is correct
18 Correct 101 ms 36352 KB Output is correct
19 Correct 50 ms 3820 KB Output is correct
20 Correct 61 ms 4584 KB Output is correct
21 Correct 50 ms 3932 KB Output is correct
22 Correct 119 ms 11604 KB Output is correct
23 Correct 103 ms 9360 KB Output is correct
24 Correct 101 ms 11344 KB Output is correct
25 Correct 48 ms 3664 KB Output is correct
26 Correct 159 ms 18504 KB Output is correct