結果

問題 No.2868 Another String of yuusaan
ユーザー nono00nono00
提出日時 2024-08-30 23:00:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,341 bytes
コンパイル時間 2,870 ms
コンパイル使用メモリ 245,816 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-30 23:00:18
合計ジャッジ時間 3,526 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep(i, r, l) for (ll i = (r); i-- > (l);)
#define all(x) begin(x), end(x)
template <class T>
bool chmin(T& lhs, T rhs) {
    return lhs > rhs ? (lhs = rhs, true) : false;
}
template <class T>
bool chmax(T& lhs, T rhs) {
    return lhs < rhs ? (lhs = rhs, true) : false;
}
struct IOIO {
    IOIO() { cin.tie(0)->sync_with_stdio(0); }
} ioio;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    os << '{';
    rep(i, 0, (int)vs.size()) os << vs[i] << (i + 1 == (int)vs.size() ? "" : ", ");
    os << '}';
    return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& vs) {
    os << '{';
    for (auto it = vs.begin(); it != vs.end(); it++) {
        if (it != vs.begin()) { os << ", "; }
        os << *it;
    }
    os << '}';
    return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& vs) {
    os << '{';
    for (auto it = vs.begin(); it != vs.end(); it++) {
        if (it != vs.begin()) { os << ", "; }
        os << *it;
    }
    os << '}';
    return os;
}
#ifdef DEBUG
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) > 0) { cerr << ", "; }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" + string(#__VA_ARGS__) + "] ", dump_func(__VA_ARGS__)
#else
#define dump(...) static_cast<int>(0)
#endif
using i128 = __int128_t;
i128 memo[60];
i128 inf = 1e20;
i128 yuusaan_length(ll i) {
    if (i >= 60) return inf;
    if (memo[i] != 0) return memo[i];
    if (i == 0) return memo[i] = 1;
    if (i == 1) return memo[i] = 7;
    if (yuusaan_length(i - 1) == inf) return memo[i] = inf;
    memo[i] = 4 * yuusaan_length(i - 1) + 3;
    chmin(memo[i], inf);
    return memo[i];
}
int main() {
    ll n, k;
    cin >> n >> k;
    k--;
    auto dfs = [&](auto&& self, ll n, i128 k) -> char {
        if (n == 1) return "yuusaan"[k];
        if (k < n) return 'y';
        ll ok = n;
        ll ng = 1;
        while (ok - ng > 1) {
            ll key = (ok + ng) / 2;
            if (k < (i128)n - key + yuusaan_length(key)) ok = key;
            else ng = key;
        }
        if (ok == n) {
            k--;
            if (k < yuusaan_length(n - 1)) return self(self, n - 1, k);
            k -= yuusaan_length(n - 1);
            if (k < yuusaan_length(n - 1)) return self(self, n - 1, k);
            k -= yuusaan_length(n - 1);
            if (k == 0) return 's';
            k--;
            if (k < yuusaan_length(n - 1)) return self(self, n - 1, k);
            k -= yuusaan_length(n - 1);
            if (k < yuusaan_length(n - 1)) return self(self, n - 1, k);
            k -= yuusaan_length(n - 1);
            return 'n';
        } else {
            return self(self, ok, k - (n - ok));
        }
    };
    cout << dfs(dfs, n, k) << '\n';
}
0