結果

問題 No.3317 ワロングアンサーロングアンサーンスワロンガー
コンテスト
ユーザー elphe
提出日時 2025-08-27 12:55:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,454 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 88,828 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-30 09:42:14
合計ジャッジ時間 9,614 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <array>
#include <vector>

// O(NQ) 解法
[[nodiscard]] static inline constexpr std::string solve([[maybe_unused]] const int_fast32_t N, const int_fast32_t Q, const std::string& S, std::vector<int_fast64_t>& T, std::vector<int_fast64_t>& X) noexcept
{
	std::string ans(Q, '?');
	for (int_fast32_t i = 0; i != Q; ++i)
	{
		--X[i];  // 1-indexed → 0-indexed
		T[i] = std::min<int_fast64_t>(T[i], 60);  // T[i] が 60 より大きい場合を考慮する必要はない(解説参照)

		const char* target = S.data();
		int_fast32_t cursor = 0;
		for (; X[i] != 0; --T[i])
		{
			for (cursor = 0; X[i] != 0; ++cursor)
			{
				if (target[cursor] != 'w' && target[cursor] != 'a') [[likely]]
					--X[i];
				else if (X[i] < 5 * (INT64_C(1) << T[i]) - 4) [[unlikely]]
				{
					if (target[cursor] == 'a')
						target = "answer";
					else if (target[cursor] == 'w')
						target = "warong";
					else [[unlikely]]
						return "!!! Error !!!";  // 異常終了
					break;
				}
				else
					X[i] -= 5 * (INT64_C(1) << T[i]) - 4;
			}
		}

		ans[i] = target[cursor];
	}

	return ans;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	int_fast32_t N, Q, i;
	std::string S;
	std::cin >> N >> Q;
	S.reserve(N), std::cin >> S;

	std::vector<int_fast64_t> T(Q), X(Q);
	for (i = 0; i != Q; ++i)
		std::cin >> T[i] >> X[i];

	std::cout << solve(N, Q, S, T, X) << '\n';
	return 0;
}
0