結果
| 問題 |
No.3317 ワロングアンサーロングアンサーンスワロンガー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-31 22:11:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 330 ms / 2,000 ms |
| コード長 | 2,285 bytes |
| コンパイル時間 | 3,237 ms |
| コンパイル使用メモリ | 262,340 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-01 09:59:38 |
| 合計ジャッジ時間 | 13,084 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 63 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using i64 = long long;
using i128 = __int128_t;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using f64 = long double;
using mint = atcoder::modint998244353;
void _main();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(18);
_main();
}
i64 pow(i64 a, i64 n) {
i64 res = 1;
i64 x = a;
while (n > 0) {
if (n & 1) res *= x;
x *= x;
n >>= 1;
}
return res;
}
void _main() {
i64 n, q;
cin >> n >> q;
string S;
cin >> S;
vector<i64> cnt(n + 1, 0);
for (i64 i = 0; i < n; i++) {
cnt[i + 1] = cnt[i];
if (S[i] == 'a' || S[i] == 'w') cnt[i + 1]++;
}
vector<i128> dp(61, 0);
dp[0] = 1;
for (i64 i = 1; i < dp.size(); i++) {
dp[i] = dp[i - 1] + (5ll << (i - 1));
}
map<char, string> mpn;
mpn['a'] = "answer";
mpn['w'] = "warong";
for (;q--;) {
i64 t, x;
cin >> t >> x;
i64 l = 0, r = n;
x--;
while (r - l > 1) {
i64 mid = (l + r) / 2;
i64 d = mid - cnt[mid];
if (cnt[mid] == 0) {
if (mid <= x) l = mid;
else r = mid;
continue;
}
if (t >= dp.size()) {
r = mid;
continue;
}
i128 left = d + cnt[mid] * dp[t];
if (left <= i128(x)) l = mid;
else r = mid;
}
{
i64 d = l - cnt[l];
i64 left = d;
if (cnt[l] > 0) left += cnt[l] * dp[t];
x -= left;
}
char now = S[l];
if (now == 'a' || now == 'w') {
t = min(t, (i64)dp.size() - 1);
}
while (true) {
if (x == 0) {
cout << now;
break;
}
assert(mpn.count(now));
assert(t >= 1);
string s = mpn[now];
t--;
vector<i64> cnt(s.size() + 1, 0);
for (i64 i = 0; i < s.size(); i++) {
cnt[i + 1] = cnt[i];
if (s[i] == 'a' || s[i] == 'w') cnt[i + 1]++;
}
i64 idx = 0;
while (idx < s.size()) {
if (x == 0) break;
if (s[idx] != 'a' && s[idx] != 'w') {
x--;
idx++;
continue;
}
if (t >= dp.size() || x < dp[t]) {
break;
}
x -= dp[t];
idx++;
}
now = s[idx];
}
}
cout << "\n";
}