提出 #70444183


ソースコード 拡げる

#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; }

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, m; cin >> n >> m;
	vector to(n, vector<int>());
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	string s; cin >> s;
	vector dp(n, vector<P>(2, { INF,-1 }));// dist,from
	queue<P>que;
	rep(i, n)if (s[i] == 'S') {
		dp[i][0] = { 0,i };
		que.push({ i,0 });
	}
	auto update = [&](int dist, int from, int v)->void {
		if (dp[v][0].second == from)return;
		if (dp[v][1].second == from)return;
		if (dp[v][0].first == INF) {
			dp[v][0] = { dist,from };
			que.push({ v,0 });
		}
		else if (dp[v][1].first == INF) {
			dp[v][1] = { dist,from };
			que.push({ v,1 });
		}
	};
	while (!que.empty()) {
		auto[v, idx] = que.front();
		que.pop();
		auto[dist, from] = dp[v][idx];
		for (auto nv : to[v]) {
			update(dist + 1, from, nv);
		}
	}
	rep(i, n) if (s[i] == 'D') {
		auto[d0, f0] = dp[i][0];
		auto[d1, f1] = dp[i][1];
		//	cout << d0 << " " << f0 << " " << d1 << " " << f1 << endl;
		int ans = d0 + d1;
		cout << ans << endl;
	}
	return 0;
}

提出情報

提出日時
問題 E - Hit and Away
ユーザ kwm_t
言語 C++ 23 (gcc 12.2)
得点 450
コード長 1963 Byte
結果 AC
実行時間 273 ms
メモリ 28272 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 54
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3472 KiB
example_01.txt AC 1 ms 3604 KiB
hand_00.txt AC 273 ms 25180 KiB
hand_01.txt AC 168 ms 26352 KiB
hand_02.txt AC 70 ms 27264 KiB
hand_03.txt AC 154 ms 28196 KiB
hand_04.txt AC 248 ms 27644 KiB
hand_05.txt AC 17 ms 6104 KiB
hand_06.txt AC 21 ms 5916 KiB
hand_07.txt AC 272 ms 25272 KiB
hand_08.txt AC 134 ms 16560 KiB
hand_09.txt AC 17 ms 5176 KiB
hand_10.txt AC 250 ms 25268 KiB
hand_11.txt AC 150 ms 26012 KiB
hand_12.txt AC 152 ms 26084 KiB
hand_13.txt AC 60 ms 26772 KiB
hand_14.txt AC 153 ms 28268 KiB
hand_15.txt AC 153 ms 28272 KiB
random_00.txt AC 261 ms 25692 KiB
random_01.txt AC 247 ms 25720 KiB
random_02.txt AC 236 ms 25668 KiB
random_03.txt AC 259 ms 25652 KiB
random_04.txt AC 242 ms 25916 KiB
random_05.txt AC 236 ms 25536 KiB
random_06.txt AC 261 ms 25120 KiB
random_07.txt AC 256 ms 25084 KiB
random_08.txt AC 236 ms 25400 KiB
random_09.txt AC 266 ms 25244 KiB
random_10.txt AC 251 ms 25304 KiB
random_11.txt AC 227 ms 25456 KiB
random_12.txt AC 268 ms 25052 KiB
random_13.txt AC 252 ms 25072 KiB
random_14.txt AC 234 ms 25556 KiB
random_15.txt AC 269 ms 25108 KiB
random_16.txt AC 251 ms 25360 KiB
random_17.txt AC 251 ms 25156 KiB
random_18.txt AC 12 ms 4500 KiB
random_19.txt AC 13 ms 4844 KiB
random_20.txt AC 17 ms 5440 KiB
random_21.txt AC 16 ms 5420 KiB
random_22.txt AC 16 ms 5100 KiB
random_23.txt AC 13 ms 4620 KiB
random_24.txt AC 50 ms 6992 KiB
random_25.txt AC 31 ms 6964 KiB
random_26.txt AC 43 ms 6932 KiB
random_27.txt AC 29 ms 6920 KiB
random_28.txt AC 54 ms 7760 KiB
random_29.txt AC 37 ms 6948 KiB
random_30.txt AC 250 ms 24404 KiB
random_31.txt AC 57 ms 17268 KiB
random_32.txt AC 171 ms 18268 KiB
random_33.txt AC 92 ms 25948 KiB
random_34.txt AC 161 ms 16660 KiB
random_35.txt AC 117 ms 17736 KiB