QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181628#5480. New Year FestivalSolitaryDream#WA 302ms25796kbC++202.6kb2023-09-16 21:35:392023-09-16 21:35:39

Judging History

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

  • [2023-09-16 21:35:39]
  • 评测
  • 测评结果:WA
  • 用时:302ms
  • 内存:25796kb
  • [2023-09-16 21:35:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int N = 11;
const int M = 60;
const int S = 1 << N;
const int INF = 1e11;
int n, m, dur[N];
vector<pii> w[N];
vector<int> ev;
int g[2][M][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;
    if (w[who].size() == 1) return w[who].front().second;
    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];
signed main() {
    scanf("%lld", &n);
    for (int i = 0, k; i < n; ++i) {
        scanf("%lld%lld", &k, dur + i);
        w[i].resize(k);
        for (int j = 0; j < k; ++j) {
            scanf("%lld%lld", &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] = INF;
                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 s = 1; s < (1 << n); ++s) f[0][s] = INF;
    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("%lld\n", f[m - 1][(1 << n) - 1]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5828kb

input:

3
3 50
300 2500
350 0
400 3000
2 120
380 0
400 2400
4 160
0 800
400 0
450 100
950 4600

output:

1460

result:

ok single line: '1460'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3748kb

input:

4
2 160
384 0
1000 2464
3 280
0 2646
441 0
1000 2795
1 160
544 0
2 240
720 0
1220 2000

output:

2022

result:

ok single line: '2022'

Test #3:

score: -100
Wrong Answer
time: 302ms
memory: 25796kb

input:

11
6 192168
0 8547618
626988 33627138
706274 36560720
1103426 50858192
1399013 55291997
1418093 55559117
6 161415
0 58611901
321482 57647455
349707 57534555
550744 55524185
885629 50500910
1448846 27972230
6 195811
0 6825079
56106 8339941
78686 8836701
323216 12993711
525834 15627745
1414450 2095944...

output:

100000000000

result:

wrong answer 1st lines differ - expected: '629407685', found: '100000000000'