QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181605#5470. Hasty Santa ClausSolitaryDream#RE 0ms0kbC++202.5kb2023-09-16 21:16:072023-09-16 21:16:09

Judging History

你现在查看的是最新测评结果

  • [2023-09-16 21:16:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-09-16 21:16:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 11;
const int M = 60;
const int S = 1 << N;
const int INF = 1e9;
int n, m, dur[N];
vector<pii> w[N];
vector<int> ev;
int g[2][N][S], sdur[S], f[M][S];
inline int Get(int who, int tm) {
    if (tm < w[who].front().first || tm > w[who].back().first) return INF;
    for (int i = 0; ; ++i) {
        if (tm >= w[who][i].first && tm <= w[who][i + 1].first) {
            int k = (w[who][i + 1].second - w[who][i].second) / (w[who][i + 1].first - w[who][i].first);
            int dx = tm - w[who][i].first;
            return w[who][i].second + k * dx;
        }
    }
}
int h[M][M][S];
int main() {
    scanf("%d", &n);
    for (int i = 0, k; i < n; ++i) {
        scanf("%d%d", &k, dur + i);
        w[i].resize(k);
        for (int j = 0; j < k; ++j) {
            scanf("%d%d", &w[i][j].first, &w[i][j].second);
            ev.push_back(w[i][j].first);
        }
    }
    for (int i = 1; i < S; ++i) {
        int p = __builtin_ctz(i);
        sdur[i] = sdur[i ^ (1 << p)] + dur[p];
    } 
    sort(ev.begin(), ev.end());
    ev.erase(unique(ev.begin(), ev.end()), ev.end());
    m = ev.size();
    for (int d = 0; d < 2; ++d) 
        for (int s = 0; s < (1 << n); ++s) 
            for (int i = 0; i < m; ++i) {
                g[d][i][s] = INF;
                if (!s) g[d][i][s] = 0;
                for (int j = 0; j < n; ++j) if (s >> j & 1) {
                    int sum_dur = sdur[s];
                    g[d][i][s] = min(g[d][i][s], g[d][i][s ^ (1 << j)] + Get(j, d ? ev[i] + sum_dur - dur[j]: ev[i] - sum_dur));
                }
            }
    for (int i = 0; i < m; ++i)
        for (int j = i + 1; j < m; ++j) 
            for (int s = 0; s < (1 << n); ++s) {
                h[i][j][s] = 1e9;
                if (sdur[s] > ev[j] - ev[i]) continue;
                for (int t = s; ; t = ((t - 1) & s)) {
                    h[i][j][s] = min(h[i][j][s], g[1][i][t] + g[0][j][s ^ t]);
                    if (!t) break;
                }
            }
    for (int i = 1; i < m; ++i) 
        for (int s = 0; s < (1 << n); ++s) {
            f[i][s] = INF;
            for (int j = 0; j < i; ++j) 
                for (int t = s; ; t = ((t - 1) & s)) {
                    f[i][s] = min(f[i][s], f[j][t] + h[j][i][s ^ t]);
                    if (!t) break;
                }
        }
    printf("%d\n", f[m - 1][(1 << n) - 1]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

5 1
23 25
23 27
24 25
25 25
25 26

output:


result: