Submission #70351506


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
template <typename T> bool chmin(T &x, T y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
using SS = array<int, 3>;
using S = array<SS, 3>;
array<S, 9> e8;
S op(S x, S y) {
	if (x[0][0] == -1)
		return y;
	if (y[0][0] == -1)
		return x;
	S res = e8[7];
	rep(i, 3) rep(j, 3) rep(k, 3) chmin(res[i][j], x[k][j] + y[i][k]);
	return res;
}
S e() { return e8[8]; }
constexpr int INF = 1e9;
int main() {
	e8[0] = S{SS{0, 1, 2}, SS{1, 0, 1}, SS{2, 1, 0}};
	e8[1] = S{SS{INF, INF, INF}, SS{INF, 0, 1}, SS{INF, 1, 0}};
	e8[2] = S{SS{0, INF, INF}, SS{INF, INF, INF}, SS{INF, INF, 0}};
	e8[3] = S{SS{INF, INF, INF}, SS{INF, INF, INF}, SS{INF, INF, 0}};
	e8[4] = S{SS{0, 1, INF}, SS{1, 0, INF}, SS{INF, INF, INF}};
	e8[5] = S{SS{INF, INF, INF}, SS{INF, 0, INF}, SS{INF, INF, INF}};
	e8[6] = S{SS{0, INF, INF}, SS{INF, INF, INF}, SS{INF, INF, INF}};
	e8[7] = S{SS{INF, INF, INF}, SS{INF, INF, INF}, SS{INF, INF, INF}};
	e8[8] = S{SS{-1, -1, -1}, SS{-1, -1, -1}, SS{-1, -1, -1}};
	int n;
	cin >> n;
	vector<int> s(n);
	rep(j, 3) {
		string ss;
		cin >> ss;
		rep(i, n) if (ss[i] == '#') s[i] |= 1 << j;
	}
	vector<S> to_seg(n);
	rep(i, n) to_seg[i] = e8[s[i]];
	atcoder::segtree<S, op, e> seg(to_seg);
	int que;
	cin >> que;
	while (que--) {
		int r, c;
		cin >> r >> c;
		r--, c--;
		s[c] ^= 1 << r;
		seg.set(c, e8[s[c]]);
		auto res = seg.all_prod();
		cout << (res[2][0] == INF ? -1 : n - 1 + res[2][0]) << '\n';
	}
}

Submission Info

Submission Time
Task F - Shortest Path Query
User sounansya
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1595 Byte
Status AC
Exec Time 522 ms
Memory 29756 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 2
AC × 30
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 4 ms 3580 KiB
00_sample_01.txt AC 1 ms 3536 KiB
01_random_00.txt AC 244 ms 3508 KiB
01_random_01.txt AC 243 ms 3656 KiB
01_random_02.txt AC 245 ms 3584 KiB
01_random_03.txt AC 244 ms 3732 KiB
01_random_04.txt AC 414 ms 16300 KiB
01_random_05.txt AC 388 ms 10300 KiB
01_random_06.txt AC 327 ms 3748 KiB
01_random_07.txt AC 455 ms 27556 KiB
01_random_08.txt AC 377 ms 9472 KiB
01_random_09.txt AC 468 ms 29572 KiB
01_random_10.txt AC 477 ms 29640 KiB
01_random_11.txt AC 476 ms 29588 KiB
01_random_12.txt AC 482 ms 29616 KiB
01_random_13.txt AC 482 ms 29600 KiB
01_random_14.txt AC 490 ms 29524 KiB
01_random_15.txt AC 468 ms 29564 KiB
01_random_16.txt AC 513 ms 29756 KiB
01_random_17.txt AC 520 ms 29604 KiB
01_random_18.txt AC 522 ms 29604 KiB
01_random_19.txt AC 505 ms 29580 KiB
01_random_20.txt AC 490 ms 29572 KiB
01_random_21.txt AC 499 ms 29620 KiB
01_random_22.txt AC 505 ms 29616 KiB
01_random_23.txt AC 506 ms 29620 KiB
01_random_24.txt AC 513 ms 29624 KiB
01_random_25.txt AC 499 ms 29656 KiB
01_random_26.txt AC 502 ms 29568 KiB
01_random_27.txt AC 496 ms 29572 KiB