# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091166 | Izzy | Advertisement 2 (JOI23_ho_t2) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n;
vector<int> visited;
vector<pair<int, int>> res;
//just count how many graphs there are
void traverse(int start) {
queue<int> q;
q.push(start);
visited[start] = false;
int a;
while (!q.empty()) {
a = q.front();
q.pop();
for (int i = -1 * res[i].second; i <= res[i].second; i++) {
if (a + i >= 0 && a + i < n) {
if (!visited[a + i] && abs(res[a].first - res[a + i].first) <= res[a].second - res[a + i].second) {
visited[a + i] = true;
q.push(a + i)
}
else {
continue;
}
}
else {
break;
}
}
}
}
int main() {
cin >> n;
pair<int, int> temp;
for (int i = 0; i < n; i++) {
cin >> temp.first;
cin >> temp.second;
res.push_back(temp);
visited.push_back(false);
}
int count = 0;
for (int i = 0; i < n; i++) {
if (!visited[i]) {
traverse(i);
count++;
}
}
cout << count;
}