Submission #70440798
Source Code Expand
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = std::forward<U>(y), true); }
template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = std::forward<U>(y), true); }
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
#include <atcoder/segtree>
using namespace std;
using ll = long long;
using T = array<array<int, 3>, 3>;
constexpr int INF = 1e9;
constexpr T id = {array<int, 3>{-1, INF, INF}, array<int, 3>{INF, -1, INF}, array<int, 3>{INF, INF, -1}};
T gen(vector<bool> v) {
T res;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
res[i][j] = INF;
}
}
for (int i = 0; i < 3; i++) {
if (not v[i]) {
continue;
}
res[i][i] = 0;
for (int j : {1, 2}) {
if (i + j >= 3 or not v[i + j]) {
break;
}
res[i][i + j] = j;
}
for (int j : {1, 2}) {
if (i - j < 0 or not v[i - j]) {
break;
}
res[i][i - j] = j;
}
}
return res;
}
T op(T l, T r) {
T res;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
res[i][j] = INF;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
chmin(res[i][k], l[i][j] + 1 + r[j][k]);
}
}
}
return res;
};
T e() { return id; }
void solve() {
int N;
cin >> N;
vector<string> S(3);
for (int i = 0; i < 3; i++) {
cin >> S[i];
}
vector<T> init;
for (int i = 0; i < N; i++) {
vector<bool> v(3);
for (int j = 0; j < 3; j++) {
v[j] = (S[j][i] == '.');
}
init.emplace_back(gen(v));
}
atcoder::segtree<T, op, e> seg(init);
auto query = [&](int r, int c) -> int {
S[r][c] = (S[r][c] == '#' ? '.' : '#');
vector<bool> v(3);
for (int i = 0; i < 3; i++) {
v[i] = (S[i][c] == '.');
}
seg.set(c, gen(v));
auto prod = seg.all_prod();
return prod[0][2];
};
int Q;
cin >> Q;
for (; Q--;) {
int r, c;
cin >> r >> c;
auto ans = query(--r, --c);
cout << (ans == INF ? -1 : ans) << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
solve();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Shortest Path Query |
| User |
rniya |
| Language |
C++ 23 (gcc 12.2) |
| Score |
525 |
| Code Size |
2973 Byte |
| Status |
AC |
| Exec Time |
273 ms |
| Memory |
29484 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
525 / 525 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3420 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3404 KiB |
| 01_random_00.txt |
AC |
42 ms |
3316 KiB |
| 01_random_01.txt |
AC |
43 ms |
3432 KiB |
| 01_random_02.txt |
AC |
42 ms |
3432 KiB |
| 01_random_03.txt |
AC |
42 ms |
3436 KiB |
| 01_random_04.txt |
AC |
171 ms |
15892 KiB |
| 01_random_05.txt |
AC |
152 ms |
9936 KiB |
| 01_random_06.txt |
AC |
109 ms |
3704 KiB |
| 01_random_07.txt |
AC |
200 ms |
27348 KiB |
| 01_random_08.txt |
AC |
145 ms |
9128 KiB |
| 01_random_09.txt |
AC |
208 ms |
29400 KiB |
| 01_random_10.txt |
AC |
208 ms |
29408 KiB |
| 01_random_11.txt |
AC |
212 ms |
29324 KiB |
| 01_random_12.txt |
AC |
209 ms |
29464 KiB |
| 01_random_13.txt |
AC |
209 ms |
29408 KiB |
| 01_random_14.txt |
AC |
221 ms |
29324 KiB |
| 01_random_15.txt |
AC |
213 ms |
29408 KiB |
| 01_random_16.txt |
AC |
248 ms |
29320 KiB |
| 01_random_17.txt |
AC |
249 ms |
29388 KiB |
| 01_random_18.txt |
AC |
247 ms |
29460 KiB |
| 01_random_19.txt |
AC |
237 ms |
29464 KiB |
| 01_random_20.txt |
AC |
241 ms |
29344 KiB |
| 01_random_21.txt |
AC |
237 ms |
29344 KiB |
| 01_random_22.txt |
AC |
244 ms |
29388 KiB |
| 01_random_23.txt |
AC |
246 ms |
29484 KiB |
| 01_random_24.txt |
AC |
248 ms |
29368 KiB |
| 01_random_25.txt |
AC |
273 ms |
29348 KiB |
| 01_random_26.txt |
AC |
255 ms |
29480 KiB |
| 01_random_27.txt |
AC |
236 ms |
29352 KiB |