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 "vision.h"
#include <bits/stdc++.h>
struct Case {
int i, j;
std::vector <std::pair <int, int>> can;
};
constexpr const int di[4] = { 1, -1, 0, 0 };
constexpr const int dj[4] = { 0, 0, 1, -1 };
constexpr bool ok(int i, int j, int n, int m) {
return i >= 0 && j >= 0 && i < n && j < m;
}
std::vector <std::pair <int, int>> get(int n, int m, int k, int si, int sj) {
std::vector <std::pair <int, int>> res;
std::queue <std::pair <int, std::pair <int, int>>> q;
std::vector <std::vector <bool>> vis(n, std::vector <bool> (m, false));
q.push({ 0, { si, sj } });
while (q.size()) {
int w = q.front().first;
int i = q.front().second.first;
int j = q.front().second.second;
q.pop();
if (!ok(i, j, n, m) || vis[i][j]) {
continue;
}
vis[i][j] = true;
if (w == k) {
res.emplace_back(i, j);
}
if (w < k) {
for (int d = 0; d < 4; d++) {
q.push({ w + 1, { i + di[d], j + dj[d] } });
}
}
}
return res;
}
std::vector <int> conv(int m, const std::vector <std::pair <int, int>>& a) {
std::vector <int> res(a.size());
for (int i = 0; i < (int) a.size(); i++) {
res[i] = a[i].first * m + a[i].second;
}
return res;
}
void construct_network(int n, int m, int k) {
std::vector <std::vector <Case>> cas(n, std::vector <Case> (m));
std::vector <int> or_last;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cas[i][j].i = i;
cas[i][j].j = j;
cas[i][j].can = get(n, m, k, i, j);
if (cas[i][j].can.empty()) {
continue;
}
int ind1 = add_or(conv(m, cas[i][j].can));
int ind2 = add_and({ ind1 , i * m + j });
or_last.push_back(ind2);
}
}
assert(or_last.size());
add_or(or_last);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |