惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
博客园 - 三生石上(FineUI控件)
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
V
Visual Studio Blog
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MongoDB | Blog
MongoDB | Blog
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
L
LangChain Blog
Martin Fowler
Martin Fowler
GbyAI
GbyAI
博客园 - 司徒正美

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔
NOI 2009
2023-02-14 · via 某岛

February 14, 2023

诗人小 G

啊。。我觉得这个还是挺难的。。。

#include <lastweapon/io>
using namespace lastweapon;

const int N = int(1e5) + 9;
long double f[N]; int pre[N];
char str[N][31]; int s[N];
PII Q[N]; int cz, op;
int n,l,p;

long double poww(long double x, int b) {
    long double z = 1;
    while (b) {
        if (b&1) z *= x;
        x *= x; b >>= 1;
    }
    return z;
}


long double calc(int a, int b) {
    return f[a] + poww(abs(s[b]-s[a]-l), p);
}

int left(int a, int b) {
    int l = a, r = n+1;
    while (l < r) {
        int m = (l + r) / 2;
        if (calc(b, m) <= calc(a, m)) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    return l;
}


int main(){

#ifndef ONLINE_JUDGE
     freopen("in.txt", "r", stdin);
#endif

    Rush {
        RD(n,l,p);++l;
        REP_1(i, n) s[i] = s[i-1] + strlen(RS(str[i])) + 1;

        cz = 0, op = 0; Q[0] = {0, n+1};

        REP_1(i, n) {
            //f[i] = OO; REP(j, i) if (checkMin(f[i], calc(j, i))) pre[i] = j;

            while (cz < op && Q[cz+1].se <= i) ++cz;
            f[i] = calc(pre[i] = Q[cz].fi, i);
            int j = left(Q[op].fi, i);
            while (cz < op && j <= Q[op].se) j = left(Q[--op].fi, i);

            Q[++op] = {i, j};
        }

        //REP_1(i, n) cout << f[i] << " "; cout << endl;
        //REP_1(i, n) cout << pre[i] << " "; cout << endl;

        if (f[n] > 1e18) puts("Too hard to arrange");
        else {
            printf("%.0Lf\n", f[n]);
            VI I; int x = n; I.PB(x);
            do I.PB(x = pre[x]); while (x);

            DWN(i, SZ(I), 1) {
                FOR(j, I[i]+1, I[i-1]) printf("%s ", str[j]);
                puts(str[I[i-1]]);
            }
        }
        puts("--------------------");
    }
}

Posted by xiaodao
Category: 日常