提出 #70457812


ソースコード 拡げる

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using S = array<array<long long, 3>, 3>;
S op(S a, S b) {
	//if (a[0][0] == -1)return b;
	//if (b[0][0] == -1)return a;

	S ret;
	rep(i, 3)rep(j, 3) {
		ret[i][j] = INF;
	}
	rep(i, 3)rep(j, 3)rep(k, 3) {
		chmin(ret[i][j], a[i][k] + b[k][j]);
	}
	return ret;
}
S e() {
	S ret;
	rep(i, 3)rep(j, 3) ret[i][j] = INF;
	rep(i, 3)ret[i][i] = 0;
	return ret;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n; cin >> n;
	vector<string>s(3);
	rep(i, 3)cin >> s[i];
	auto init = [&](int type)->S {
		S ret;
		rep(i, 3)rep(j, 3) ret[i][j] = INF;
		if (type == 0) {//000
			ret[0] = { 0,1,2 };
			ret[1] = { 1,0,1 };
			ret[2] = { 2,1,0 };
		}
		else if (type == 1) {//100
			ret[0] = { INF,INF,INF };
			ret[1] = { INF,0,1 };
			ret[2] = { INF,1,0 };
		}
		else if (type == 2) {//010
			ret[0] = { 0,INF,INF };
			ret[1] = { INF,INF,INF };
			ret[2] = { INF,INF,0 };
		}
		else if (type == 3) {//110
			ret[0] = { INF,INF,INF };
			ret[1] = { INF,INF,INF };
			ret[2] = { INF,INF,0 };
		}
		else if (type == 4) {//001
			ret[0] = { 0,1,INF };
			ret[1] = { 1,0,INF };
			ret[2] = { INF,INF,INF };
		}
		else if (type == 5) {//101
			ret[0] = { INF,INF,INF };
			ret[1] = { INF,0,INF };
			ret[2] = { INF,INF,INF };
		}
		else if (type == 6) {//011
			ret[0] = { 0,INF,INF };
			ret[1] = { INF,INF,INF };
			ret[2] = { INF,INF,INF };
		}
		else if (type == 7) {//111
			ret[0] = { INF,INF,INF };
			ret[1] = { INF,INF,INF };
			ret[2] = { INF,INF,INF };
		}
		return ret;
	};
	auto bit = [&](int n)->int {
		int res = 0;
		if (s[0][n] == '#')res += 1;
		if (s[1][n] == '#')res += 2;
		if (s[2][n] == '#')res += 4;
		return res;
	};
	segtree<S, op, e>seg(n);
	rep(i, n) {
		auto b = bit(i);
		seg.set(i, init(b));
	}
	/*	rep(i, n) {
			auto get = seg.get(i);
			rep(i, 3) {
				rep(j, 3) {
					cout << get[i][j] << " ";
				}cout << endl;
			}cout << endl;
		}
		cout << endl;
		cout << endl;
		cout << endl;
		cout << endl;
		{
			auto all = seg.all_prod();
			rep(i, 3) {
				rep(j, 3) {
					cout << all[i][j] << " ";
				}cout << endl;
			}cout << endl;
		}*/
	int q; cin >> q;
	while (q--) {
		int r, c; cin >> r >> c;
		r--, c--;
		if (s[r][c] == '#')s[r][c] = '.';
		else s[r][c] = '#';

		auto b = bit(c);
		seg.set(c, init(b));
		/*rep(i, 3)cout << s[i] << endl;
		cout << endl;
		{
			auto all = seg.all_prod();
			rep(i, 3) {
				rep(j, 3) {
					cout << all[i][j] << " ";
				}cout << endl;
			}cout << endl;
		}*/

		auto get = seg.all_prod();
		auto ans = get[0][2] + n - 1;
		if (ans >= INF)ans = -1;
		cout << ans << endl;
	}
	return 0;
}

提出情報

提出日時
問題 F - Shortest Path Query
ユーザ kwm_t
言語 C++ 23 (gcc 12.2)
得点 525
コード長 3539 Byte
結果 AC
実行時間 638 ms
メモリ 55052 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 525 / 525
結果
AC × 2
AC × 30
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3560 KiB
00_sample_01.txt AC 1 ms 3444 KiB
01_random_00.txt AC 215 ms 3600 KiB
01_random_01.txt AC 213 ms 3584 KiB
01_random_02.txt AC 213 ms 3704 KiB
01_random_03.txt AC 213 ms 3472 KiB
01_random_04.txt AC 466 ms 28408 KiB
01_random_05.txt AC 386 ms 16584 KiB
01_random_06.txt AC 295 ms 3956 KiB
01_random_07.txt AC 538 ms 50980 KiB
01_random_08.txt AC 367 ms 14984 KiB
01_random_09.txt AC 590 ms 54976 KiB
01_random_10.txt AC 593 ms 54876 KiB
01_random_11.txt AC 584 ms 54924 KiB
01_random_12.txt AC 596 ms 54952 KiB
01_random_13.txt AC 583 ms 54828 KiB
01_random_14.txt AC 595 ms 54804 KiB
01_random_15.txt AC 586 ms 54872 KiB
01_random_16.txt AC 633 ms 54976 KiB
01_random_17.txt AC 629 ms 54996 KiB
01_random_18.txt AC 627 ms 54964 KiB
01_random_19.txt AC 604 ms 55052 KiB
01_random_20.txt AC 616 ms 54876 KiB
01_random_21.txt AC 613 ms 54824 KiB
01_random_22.txt AC 638 ms 54832 KiB
01_random_23.txt AC 637 ms 54948 KiB
01_random_24.txt AC 635 ms 54952 KiB
01_random_25.txt AC 617 ms 54904 KiB
01_random_26.txt AC 620 ms 54996 KiB
01_random_27.txt AC 615 ms 54868 KiB