| Task: | Island |
| Sender: | MRiekasius |
| Submission time: | 2026-04-16 10:51:27 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:21:25: warning: comparison of integer expressions of different signedness: 'int' and 'const std::__cxx11::basic_string<char>::size_type' {aka 'const long unsigned int'} [-Wsign-compare]
21 | if(firstHashtag == RowRepr.npos) continue;
input/code.cpp:25:34: error: 'nextDot' was not declared in this scope
25 | rows[i] = {firstHashtag, nextDot};
| ^~~~~~~
input/code.cpp:25:41: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and '<brace-enclosed initializer list>')
25 | rows[i] = {firstHashtag, nextDot};
| ^
In file included from /usr/include/c++/13/bits/stl_algobase.h:64,
from /usr/include/c++/13/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/13/bits...Code
#include <bits/stdc++.h>
using namespace std;
bool withinRange(pair<int, int> theRange, int theNum){
return (theNum >= theRange.first && theNum <= theRange.second);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<pair<int, int>> rows;
for(int i = 0; i < n; i++){
string RowRepr;
cin >> RowRepr;
int firstHashtag = RowRepr.find('#');
//if(firstHashtag == RowRepr.npos) cout << "No\n";else cout << firstHashtag << "\n";
if(firstHashtag == RowRepr.npos) continue;
firstHashtag++;
int beforeNextDot = RowRepr.substr(firstHashtag).find('.') + firstHashtag;
cout << firstHashtag << " " << beforeNextDot << "\n";
rows[i] = {firstHashtag, nextDot};
}
for(int i = 0; i < q; i++){
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
r1--;
r2--;
if(r1 > r2){
swap(r1, r2);
swap(c1, c2);
}
int curC = c1;
int cost = 0;
for(int j = r1; j < r2; j--){
if(!withinRange(rows[j], curC)){
if(curC < rows[j].first){
cost += rows[j].first - curC;
curC = rows[j].first;
}
else{
cost += curC - rows[j].second;
curC = rows[j].second;
}
}
cost++;
}
cost += abs(curC - c2);
cout << cost;
}
}
