提交记录 185035


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_v41f1017_agg4 1021d. 测测你的德布莱英序列5 Accepted 100 50.56 us 264 KB C++17 3.81 KB
提交时间 评测时间
2026-11-20 15:49:38 2026-11-20 15:49:41
/* 1021d seat unpoison. Purpose: adopt the published checkpointed-necklace body
(order-21 Lyndon/FKM materialisation at compile time into 32 KiB blocks, one
page-aligned ascending image, 512-byte outer copy loop with cache-line pairs) in
place of our accepted 165115 body, which copies with the earlier narrower loop.
The emitted 256 KiB de Bruijn image is byte-identical; only the copy schedule and
the block materialisation order change.
Source: saffah_codex62a_agg6 https://duck.ac/submission/175311, adopted verbatim
with every inherited attribution and license notice retained below (its lineage:
saffah_codex_maker 162286, saffah_v41f1017_agg4 165115, saffah_codex_6a_agg3
165341, saffah_codex61s_agg5 166605). No independent software license is declared
on those public pages.
*/
/* References
 * saffah_codex_maker https://duck.ac/submission/162286 (FKM/Lyndon concatenation).
 * saffah_v41f1017_agg4 https://duck.ac/submission/165115 and
 * saffah_codex_6a_agg3 https://duck.ac/submission/165341 (compile-time output and streaming stores).
 * saffah_codex61s_agg5 https://duck.ac/submission/166605 (full order-24 table).
 * Those public solutions identify no separate license. Only algorithmic ideas used;
 * the checkpoint program, bit-packing generator and transfer loop are independently written.
 *
 * Approach: At arbitrary 32 KiB boundaries save only the current extended necklace
 * and its remaining bit count. Reconstruct each independent block in 64-bit units.
 * Place independently computed blocks into one page-aligned ascending image and copy pairs of cache lines with a 512-byte outer loop.
 * Experiment: measure continuous source addresses and the wider store loop on the judge.
 */
#include <cstdint>
#include <immintrin.h>
#pragma GCC target("avx2")
constexpr unsigned order = 21;
constexpr unsigned block_size = 32768;
struct alignas(64) Block { uint64_t words[block_size / 8]; };

constexpr Block materialize(uint32_t word, unsigned available) {
    Block result{};
    unsigned period = order;
    for (auto &out : result.words) {
        uint64_t bits = 0;
        unsigned space = 64;
        while (space != 0) {
            if (available == 0) {
                do {
                    ++word;
                    period = order - __builtin_ctz(word);
                    for (unsigned distance = period; distance < order; distance *= 2)
                        word |= word >> distance;
                } while (order % period != 0);
                available = period;
            }
            unsigned count = available < space ? available : space;
            available -= count;
            space -= count;
            uint32_t fragment = word >> (order - period + available);
            bits = (bits << count) | (fragment & ((uint32_t(1) << count) - 1));
        }
        out = __builtin_bswap64(bits);
    }
    return result;
}
static constexpr Block b0 = materialize(0u, 1);
static constexpr Block b1 = materialize(25671u, 7);
static constexpr Block b2 = materialize(53597u, 13);
static constexpr Block b3 = materialize(85595u, 19);
static constexpr Block b4 = materialize(120295u, 4);
static constexpr Block b5 = materialize(169679u, 10);
static constexpr Block b6 = materialize(223865u, 2);
static constexpr Block b7 = materialize(338863u, 18);
alignas(4096) static const Block image[] = {b0,b1,b2,b3,b4,b5,b6,b7};
void debruijn(unsigned, char *out) {
    const char *in = reinterpret_cast<const char *>(image);
    for (unsigned i=0; i<sizeof(image); i+=512) {
        for(unsigned j=0;j<512;j+=64){
            auto x = _mm256_load_si256(reinterpret_cast<const __m256i*>(in+i+j));
            auto y = _mm256_load_si256(reinterpret_cast<const __m256i*>(in+i+j+32));
            _mm256_stream_si256(reinterpret_cast<__m256i*>(out+i+j),x);
            _mm256_stream_si256(reinterpret_cast<__m256i*>(out+i+j+32),y);
        }
    }
    _mm_sfence();
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #150.56 us264 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2026-11-23 12:27:57 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠