QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#171455#7185. Poor Studentsucup-team206#RE 1ms5904kbC++142.1kb2023-09-09 17:00:542023-09-09 17:01:15

Judging History

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

  • [2023-09-09 17:01:15]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5904kb
  • [2023-09-09 17:00:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int K = 11;
const int N = 50010;
int n, k, a[N];
int c[K][N];
int f[K], g[K];
multiset<pii> mp[K][K];
inline void Update(int lesson, int who, int ty) {
    for (int i = 1; i <= k; ++i) if (i != lesson) {
        if (ty == 1) {
            mp[lesson][i].insert(pii(c[who][i] - c[who][lesson], who));
        } else {
            mp[lesson][i].erase(mp[lesson][i].find(pii(c[who][i] - c[who][lesson], who)));
        }
    }
}
signed main() {
    scanf("%lld%lld", &n, &k);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= k; ++j) 
            scanf("%lld", &c[i][j]);
    for (int i = 1; i <= k; ++i) scanf("%lld", a + i);
    int ans = 0;
    for (int ip = 1; ip <= n; ++ip) {
        for (int i = 1; i <= k; ++i) {
            f[i] = c[ip][i];
            g[i] = 0;
        }
        for (int i = 1; i <= k; ++i) {
            for (int j = 1; j <= k; ++j)
                for (int l = 1; l <= k; ++l) {
                    if (mp[j][l].empty()) continue;
                    auto [x, y] = *mp[j][l].begin();
                    if (f[l] > f[j] + x) {
                        f[l] = f[j] + x;
                        g[l] = j;
                    }
                }
        }
        int cur = 0; f[0] = 1e12;
        for (int i = 1; i <= k; ++i) {
            if (a[i] && f[i] < f[cur]) cur = i;
        }
        // printf("Match %lld->%lld %lld\n", ip, cur, f[cur]);
        // for (int i = 1; i <= k; ++i) printf("%lld ", f[i]);
        // puts("");
        // for (int i = 1; i <= k; puts(""), ++i)
        //     for (int j = 1; j <= k; ++j) {
        //         printf("%lld ", mp[i][j].empty() ? 100000 : mp[i][j].begin()->first);
        //     }
        ans += f[cur];
        --a[cur];
        while (g[cur]) {
            int nxt = g[cur];
            int who = mp[nxt][cur].begin()->second;
            Update(nxt, who, -1);
            Update(cur, who, 1);
            cur = nxt;
        }
        Update(cur, ip, 1);
    }
    printf("%lld\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5844kb

input:

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

output:

12

result:

ok answer is '12'

Test #2:

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

input:

3 3
1 2 3
2 4 6
6 5 4
1 1 1

output:

8

result:

ok answer is '8'

Test #3:

score: -100
Runtime Error

input:

1000 10
734 303 991 681 755 155 300 483 702 442
237 256 299 675 671 757 112 853 759 233
979 340 288 377 718 199 935 666 576 842
537 363 592 349 494 961 864 727 84 813
340 78 600 492 118 421 478 925 552 617
517 589 716 7 928 638 258 297 706 787
266 746 913 978 436 859 701 951 137 44
815 336 471 720 2...

output:


result: