提交记录 14024


用户 题目 状态 得分 用时 内存 语言 代码长度
wlzhouzhuan 2003. 【NOI2020】美食家(加强版) Runtime Error 0 90.11 us 40 KB C++ 2.73 KB
提交时间 评测时间
2020-08-21 21:20:06 2020-08-21 21:20:16
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

static inline void upd(ll& x, const ll y) {
    if (y > x)
        x = y;
}

static int n, m, c[52];
struct Edge {
    char u, v, w;
} e[502];
struct Event {
    int t, x, y;
    bool operator <(const Event& rhs) const {
        return t < rhs.t;
    }
} q[205];
static ll pool[233333][52];
static ll (*buf)[52] = &pool[0];
static int xjj;
struct Pre {
    ll (*dp)[52];
    int orig, anot; ll dx;
    void init(int s) {
        dp = buf;
        memset(dp, 0xcc, sizeof(*dp) * 5);
        dp[0][s] = 0;
        vector<ull> hs;
        for (int i = 0;; i++) {
            for (int j = 0; j < n; j++)
                dp[i][j] += c[j];
            ull h = 0;
            for (int j = 0; j < n; j++)
                h ^= (j + 1) * (ull) (dp[i][j] - dp[i][s]);
            hs.push_back(h);

            if (xjj) {
                if (i > xjj + 5 && !memcmp(hs.data() + i - xjj - 5, hs.data() + i - 5, 5 * sizeof(ull))) {
                    orig = i - xjj;
                    anot = i;
                    break;
                }
            } else {
                for (int j = 5; j + 5 < i; j++)
                    if (!memcmp(hs.data() + i - 5, hs.data() + j - 5, 5 * sizeof(ull))) {
                        orig = j;
                        anot = i;
                        goto ok;
                    }
            }

            memset(dp + i + 5, 0xcc, sizeof(*dp));
            for (int j = 0; j < m; j++)
                upd(dp[i + e[j].w][e[j].v], dp[i][e[j].u]);
        }
        ok:;
        dx = dp[anot][s] - dp[orig][s];
        xjj = anot - orig;
        buf += anot;
    }
    ll query(int T, int t) {
        if (T < anot)
            return dp[T][t];
        return dp[orig + (T - orig) % xjj][t] + (T - orig) / xjj * dx;
    }
} pre[52];

static ll calc(int s, int t, int T) {
    return pre[s].query(T, t) - c[t];
}

int main() {
    int T, k;
    cin >> n >> m >> T >> k;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        e[i].u = u - 1; e[i].v = v - 1; e[i].w = w;
    }

    for (int i = 0; i < n; i++)
        pre[i].init(i);

    for (int i = 1; i <= k; i++) {
        cin >> q[i].t >> q[i].x >> q[i].y;
        q[i].x--;
    }
    sort(q + 1, q + k + 1);
    q[0].t = 0; q[0].x = 0; q[0].y = 0;
    q[k + 1].t = T; q[k + 1].x = 0; q[k + 1].y = c[0];

    static ll dp[205];
    memset(dp, 0xcc, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i <= k + 1; i++) {
        for (int j = 0; j < i; j++)
            upd(dp[i], dp[j] + calc(q[j].x, q[i].x, q[i].t - q[j].t));
        dp[i] += q[i].y;
    }
    upd(dp[k + 1], -1);
    cout << dp[k + 1] << endl;

    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #182.02 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #289.15 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #390.11 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #482.66 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #583.32 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #682.17 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #782.8 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #881.58 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #981.57 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1082.11 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1181.99 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1281.31 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1381.37 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1481.85 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1581.63 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1681.27 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1781.04 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1881.87 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #1981.48 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2081.06 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2181.95 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2281.51 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2382.11 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2481.55 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2581.79 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2681.74 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2782.47 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2881.78 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #2981.14 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3080.98 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3182.02 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3280.71 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3381.86 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3481.7 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3580.91 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3681.8 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3781.67 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3881.68 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #3982.26 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4081.09 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4181.22 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4280.57 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4380.94 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4481.38 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4581.94 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4681.35 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4781.46 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4881.27 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #4981.49 us40 KBRuntime ErrorScore: 0

Subtask #1 Testcase #5081.79 us40 KBRuntime ErrorScore: 0


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