提交记录 14066


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah 2003. 【NOI2020】美食家(加强版) Accepted 100 1.25 s 222800 KB C++ 3.18 KB
提交时间 评测时间
2020-08-28 22:34:12 2020-08-28 22:34:47
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int MAXN = 100;
const int MAXM = 1000;
const int MAXW = 100;
const int MAXK = 10002;

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

static int n, m, c[MAXN];
struct Edge {
    char u, v, w;
} e[MAXM];
struct Event {
    int t, x, y;
    bool operator <(const Event& rhs) const {
        return t < rhs.t;
    }
} q[MAXK];
static ll pool[500000][MAXN];
static ll (*buf)[MAXN] = &pool[0];
static int xjj;
struct Pre {
    ll (*dp)[MAXN];
    int orig, anot; ll dx;
    void init(int s) {
        dp = buf;
        memset(dp, 0xcc, sizeof(*dp) * MAXW);
        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 + MAXW && !memcmp(hs.data() + i - xjj - MAXW, hs.data() + i - MAXW, MAXW * sizeof(ull))) {
                    orig = i - xjj;
                    anot = i;
                    break;
                }
            } else {
                for (int j = MAXW; j + MAXW < i; j++)
                    if (!memcmp(hs.data() + i - MAXW, hs.data() + j - MAXW, MAXW * sizeof(ull))) {
                        orig = j;
                        anot = i;
                        goto ok;
                    }
            }

            memset(dp + i + MAXW, 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;
        // fprintf(stderr, "pre %d, orig %d, anot %d, dx %lld\n", s, orig, anot, dx);
    }
    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[MAXN];

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

int main() {
// #ifdef ONLINE_JUDGE
//     freopen("delicacy.in", "r", stdin);
//     freopen("delicacy.out", "w", stdout);
// #endif
    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);
    
    cerr << "Loop length " << xjj << ", weight " << pre[0].dx << endl;

    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[MAXK];
    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;

    cerr << buf - pool << endl;

    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #1714.471 ms30 MB + 36 KBAcceptedScore: 0

Subtask #1 Testcase #2880.298 ms75 MB + 144 KBAcceptedScore: 0

Subtask #1 Testcase #3809.133 ms57 MB + 44 KBAcceptedScore: 100

Subtask #1 Testcase #4723.375 ms32 MB + 60 KBAcceptedScore: 0

Subtask #1 Testcase #5727.123 ms34 MB + 260 KBAcceptedScore: 0

Subtask #1 Testcase #61.211 s186 MB + 576 KBAcceptedScore: 0

Subtask #1 Testcase #71.033 s153 MB + 344 KBAcceptedScore: 0

Subtask #1 Testcase #8887.528 ms42 MB + 848 KBAcceptedScore: 0

Subtask #1 Testcase #9715.162 ms28 MB + 544 KBAcceptedScore: 0

Subtask #1 Testcase #10747.43 ms32 MB + 540 KBAcceptedScore: 0

Subtask #1 Testcase #11976.213 ms73 MB + 60 KBAcceptedScore: 0

Subtask #1 Testcase #12740.108 ms30 MB + 832 KBAcceptedScore: 0

Subtask #1 Testcase #13727.749 ms26 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #141.102 s153 MB + 896 KBAcceptedScore: 0

Subtask #1 Testcase #15706.236 ms30 MB + 736 KBAcceptedScore: 0

Subtask #1 Testcase #16846.694 ms39 MB + 104 KBAcceptedScore: 0

Subtask #1 Testcase #17720.167 ms28 MB + 592 KBAcceptedScore: 0

Subtask #1 Testcase #181.191 s217 MB + 592 KBAcceptedScore: 0

Subtask #1 Testcase #19736.585 ms29 MB + 28 KBAcceptedScore: 0

Subtask #1 Testcase #20711.521 ms31 MB + 340 KBAcceptedScore: 0

Subtask #1 Testcase #21734.422 ms29 MB + 24 KBAcceptedScore: 0

Subtask #1 Testcase #22732.036 ms30 MB + 380 KBAcceptedScore: 0

Subtask #1 Testcase #23725.292 ms34 MB + 568 KBAcceptedScore: 0

Subtask #1 Testcase #24767.929 ms36 MB + 968 KBAcceptedScore: 0

Subtask #1 Testcase #25720.919 ms31 MB + 1020 KBAcceptedScore: 0

Subtask #1 Testcase #26774.633 ms33 MB + 760 KBAcceptedScore: 0

Subtask #1 Testcase #27824.429 ms53 MB + 240 KBAcceptedScore: 0

Subtask #1 Testcase #28722.402 ms35 MB + 900 KBAcceptedScore: 0

Subtask #1 Testcase #29824.285 ms55 MB + 588 KBAcceptedScore: 0

Subtask #1 Testcase #30772.556 ms34 MB + 220 KBAcceptedScore: 0

Subtask #1 Testcase #31786.375 ms32 MB + 704 KBAcceptedScore: 0

Subtask #1 Testcase #32752.555 ms30 MB + 300 KBAcceptedScore: 0

Subtask #1 Testcase #33738.147 ms29 MB + 968 KBAcceptedScore: 0

Subtask #1 Testcase #341.25 s181 MB + 84 KBAcceptedScore: 0

Subtask #1 Testcase #35893.165 ms44 MB + 352 KBAcceptedScore: 0

Subtask #1 Testcase #36829.534 ms38 MB + 84 KBAcceptedScore: 0

Subtask #1 Testcase #37739.813 ms29 MB + 896 KBAcceptedScore: 0

Subtask #1 Testcase #38723.028 ms31 MB + 980 KBAcceptedScore: 0

Subtask #1 Testcase #39753.21 ms32 MB + 600 KBAcceptedScore: 0

Subtask #1 Testcase #40892.497 ms40 MB + 36 KBAcceptedScore: 0

Subtask #1 Testcase #41816.538 ms36 MB + 736 KBAcceptedScore: 0

Subtask #1 Testcase #42749.232 ms32 MB + 688 KBAcceptedScore: 0

Subtask #1 Testcase #43744.46 ms29 MB + 304 KBAcceptedScore: 0

Subtask #1 Testcase #44796.375 ms39 MB + 48 KBAcceptedScore: 0

Subtask #1 Testcase #45743.728 ms31 MB + 48 KBAcceptedScore: 0

Subtask #1 Testcase #46809.998 ms34 MB + 864 KBAcceptedScore: 0

Subtask #1 Testcase #47742.525 ms28 MB + 272 KBAcceptedScore: 0

Subtask #1 Testcase #48723.759 ms33 MB + 192 KBAcceptedScore: 0

Subtask #1 Testcase #49915.318 ms48 MB + 820 KBAcceptedScore: 0

Subtask #1 Testcase #50828.149 ms61 MB + 664 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-21 20:34:40 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠