結果
| 問題 |
No.3317 ワロングアンサーロングアンサーンスワロンガー
|
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2025-10-31 22:24:35 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 350 ms / 2,000 ms |
| コード長 | 2,257 bytes |
| コンパイル時間 | 927 ms |
| コンパイル使用メモリ | 105,636 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-01 10:00:32 |
| 合計ジャッジ時間 | 13,308 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 63 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
const long long mal = (long long)1e18 + 1;
int n, q;
cin >> n >> q;
string s;
cin >> s;
const int mat = 59;
vector<long long> len(mat);
for (int i = 0; i < mat; ++i) len[i] = (5LL << i) - 4;
vector<int> sum(n + 1);
for (int i = 0; i < n; ++i) sum[i + 1] = sum[i] + (s[i] == 'a' || s[i] == 'w');
const string w = "warong", a = "answer";
auto dfs = [&](auto dfs, char c, long long v, int t) -> char
{
if (v == 0 || t < 0) return c;
if (c == 'w')
{
for (int i = 0; i < 6; ++i)
{
if (w[i] == 'w')
{
if (v < len[t])
{
return dfs(dfs, 'w', v, t - 1);
}
else v -= len[t];
}
else if (w[i] == 'a')
{
if (v < len[t])
{
return dfs(dfs, 'a', v, t - 1);
}
else v -= len[t];
}
else
{
if (v <= 0) return w[i];
--v;
}
}
}
else if (c == 'a')
{
for (int i = 0; i < 6; ++i)
{
if (a[i] == 'w')
{
if (v < len[t])
{
return dfs(dfs, 'w', v, t - 1);
}
else v -= len[t];
}
else if (a[i] == 'a')
{
if (v < len[t])
{
return dfs(dfs, 'a', v, t - 1);
}
else v -= len[t];
}
else
{
if (v <= 0) return a[i];
--v;
}
}
}
return c;
};
while (q--)
{
long long t, x;
cin >> t >> x;
t = min(t, mat - 1LL);
int l = 0, r = n;
while (r - l > 1)
{
int mid = (l + r) / 2;
long long tmp;
if (sum[mid] > mal / len[t]) tmp = x + 1;
else tmp = sum[mid] * len[t] + (mid - sum[mid]);
(tmp < x ? l : r) = mid;
}
// cout << t << ',' << x << endl;
// cout << l << endl;
x -= (l - sum[l]) + sum[l] * len[t];
// cout << l << ',' << x << endl;
// cout << "ans: ";
--x;
if (x == 0) cout << s[l];
else if (s[l] != 'a' && s[l] != 'w') cout << s[l];
else cout << dfs(dfs, s[l], x, t);
// cout << endl << endl;
}
cout << endl;
}
テナガザル