CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Forest density
Sender:fabiank
Submission time:2024-09-23 16:42:09 +0300
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:18:13: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'char [n]')
   18 |         cin >> line;
      |         ~~~ ^~ ~~~~
      |         |      |
      |         |      char [n]
      |         std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from input/code.cpp:1:
/usr/include/c++/11/istream:168:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]' (near match)
  168 |       operator>>(bool& __n)
      |       ^~~~~~...

Code

#include <bits/stdc++.h>

using namespace std;

void print_vector(vector<int> &x);
void print_matrix(vector<vector<int>> &matrix);

int main()
{
    int n, q;
    cin >> n >> q;

    vector<vector<int>> forest(n, vector<int>(n, 0));

    for (int i = 0; i < n; i++)
    {
        char line[n];
        cin >> line;
        for (int j = 0; j < n; j++)
        {
            if (line[j] == '*')
            {
                forest[i][j] = 1;
            }
        }
    }

    vector<vector<int>> prefix_sum(n, vector<int>(n, 0));

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int upper_value = i > 0 ? prefix_sum[i - 1][j] : 0;
            int left_value = j > 0 ? prefix_sum[i][j - 1] : 0;
            int diagional_value = i > 0 && j > 0 ? prefix_sum[i - 1][j - 1] : 0;
            prefix_sum[i][j] = upper_value + left_value - diagional_value + (int)forest[i][j];
        }
    }

    // print_matrix(prefix_sum);

    for (int i = 0; i < q; i++)
    {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;

        int sum_a = y1 > 1 && x1 > 1 ? prefix_sum[y1 - 2][x1 - 2] : 0;
        int sum_b = y1 > 1 ? prefix_sum[y1 - 2][x2 - 1] : 0;
        int sum_c = x1 > 1 ? prefix_sum[y2 - 1][x1 - 2] : 0;
        int sum_d = prefix_sum[y2 - 1][x2 - 1];
        // cout << "A: " << sum_a << " B: " << sum_b << " c: " << sum_c << " D: " << sum_d << "\n";
        cout << sum_d - sum_b - sum_c + sum_a << "\n";
    }
}

void print_vector(vector<int> &x)
{
    for (int v : x)
    {
        cout << v << " ";
    }
    cout << "\n";
}

void print_matrix(vector<vector<int>> &matrix)
{
    cout << "\n"
         << "----------------" << "\n";
    for (vector<int> row : matrix)
    {
        print_vector(row);
    }
    cout << "\n"
         << "----------------" << "\n";
}