結果

問題 No.3317 ワロングアンサーロングアンサーンスワロンガー
コンテスト
ユーザー kwm_t
提出日時 2025-11-01 01:13:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 3,185 bytes
コンパイル時間 3,217 ms
コンパイル使用メモリ 284,492 KB
実行使用メモリ 59,680 KB
最終ジャッジ日時 2025-11-01 01:14:00
合計ジャッジ時間 13,111 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55 TLE * 1 -- * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:112:17: warning: control reaches end of non-void function [-Wreturn-type]
  112 |                 };
      |                 ^

ソースコード

diff #

#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; }
template <class T, class F>
T binarySearch(T ok, T ng, const F &f) {
	while (abs(ok - ng) > 1) {
		T mid = (ok + ng) / 2;
		(f(mid) ? ok : ng) = mid;
	}
	return ok;
}
long long c0[26][61];
long long c1[26][61];
long long c2[26][61];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, q; cin >> n >> q;
	string s; cin >> s;
	string ans;
	rep(i, 26) {
		if (i == ('a' - 'a') || i == ('w' - 'a'))c0[i][0] = 1;
		else c1[i][0] = 1;
		c2[i][0] = 1;
	}
	rep(i, 61) rep(c, 26) {
		int ni = i + 1;
		c0[c][ni] = min(LINF + 10, c0[c][i] * 2);
		c1[c][ni] = min(LINF + 10, c1[c][i] + c0[c][i] * 4);
		c2[c][ni] = min(LINF + 10, c0[c][ni] + c1[c][ni]);
	}

	vector prefix(61, vector<long long>(s.size()));
	{
		// 回数、x文字目まで
		rep(i, 61) {
			long long tmp = 0;
			rep(j, s.size()) {
				tmp = min(LINF + 10000, tmp + c2[s[j] - 'a'][i]);
				prefix[i][j] = tmp;
			}
		}

	}
	while (q--) {
		long long t, x; cin >> t >> x;
		x--;
		t = min(t, 60LL);
		auto from = [&](const long long target)->bool {
			return prefix[t][target] > x;
		};
		int index = binarySearch<int>(s.size() - 1, -1, from);
		// 不要分を計算する
		auto remove = [&](int index)->long long {
			long long c0 = 0, c1 = 0;
			rep(i, index) {
				if (s[i] == 'a' || s[i] == 'w')c0++;
				else c1++;
			}
			if (c0 == 0) {
				return c0 + c1;
			}
			for (long long i = 0; i < t; ++i) {
				c1 += c0 * 4;
				c0 *= 2;
			}
			return c0 + c1;
		};
		x -= remove(index);
		// cのn回後のx文字目
		auto solve = [&](auto &&self, char c, long long n, long long x)->char {
			//	cout << c << " " << n << " " << x << endl;
			if (c != 'a' && c != 'w')return c;
			string tmp;
			if (c == 'a') {
				tmp = "answer";
			}
			else if (c == 'w') {
				tmp = "warong";
			}
			if (n == 1)return tmp[x];
			long long pre = 0;
			rep(i, tmp.size()) {
				//	cout << tmp[i] - 'a' << "!" << n - 1 << endl;
				//	cout << c2[tmp[i] - 'a'][n - 1] << "!!" << count(tmp[i], n - 1) << endl;
				auto cnt = c2[tmp[i] - 'a'][n - 1];// count(tmp[i], n - 1);
				//auto cnt = count(tmp[i], n - 1);
				//	cout << cnt << endl;
				if (pre + cnt > x) {
					return self(self, tmp[i], n - 1, x - pre);
				}
				else {
					pre += cnt;
				}
			}
		};
		ans += solve(solve, s[index], t, x);
		//	cout << solve(solve, s[index], t, x) << endl;
	}
	cout << ans << endl;
	return 0;
}
0