QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#618299 | #7185. Poor Students | Godzilla | WA | 9ms | 5904kb | C++14 | 3.2kb | 2024-10-06 20:39:40 | 2024-10-06 20:39:43 |
Judging History
answer
#include <bits/stdc++.h>
#define file_in(x) (freopen(#x".in", "r", stdin))
#define file_out(x) (freopen(#x".out", "w", stdout))
#define ll long long
#define ull unsigned long long
#define vi vector
#define pb push_back
#define db long double
#define pr pair <int, int>
#define mk make_pair
#define fi first
#define se second
#define lb(x) (x & (-x))
using namespace std;
char _c; bool _f; template <class T> void IN(T &x) {
_f = x = 0; while (_c = getchar(), !isdigit(_c)) {if (_c == '-') _f = 1;}
while (isdigit(_c)) {x = x * 10 + _c - '0', _c = getchar();} if (_f) x = -x;
}
template <class T> void _write(T x) {
if (x < 0) return putchar('-'), _write(-x), void();
if (x > 9) _write(x / 10);
putchar('0' + x % 10);
}
template <class T> void write(T x) {_write(x), putchar('\n');}
template <class T> void write_s(T x) {_write(x), putchar(' ');}
template <class first, class... rest> void write(first fir, rest... res) {
write_s(fir), write(res...);
}
#define debug(...) (_debug(#__VA_ARGS__, __VA_ARGS__))
template <class T> void _debug(const char *format, T x) {
cerr << format << " = " << x << endl;
}
template <class first, class... rest>
void _debug(const char *format, first fir, rest... res) {
while (*format != ',') cerr << *format++;
cerr << " = " << fir << ',', _debug(format + 1, res...);
}
bool START;
const int N = 5e4 + 5, M = 11, inf = 1e9 + 5;
int n, K, c[N][M], mtc[N], dis[M], d[M][M], pre[M], ans, a[N];
bool vis[M];
queue <int> q;
struct heap {
priority_queue <pr, vi <pr>, greater <pr> > q;
void push(pr t) {q.push(t);}
void pop(int t = 0) {
while (!q.empty() && mtc[q.top().se] != t) q.pop();
}
pr top() {
if (q.empty()) return mk(-1, -1);
return q.top();
}
} f[M][M], g[M];
bool END;
void spfa(int n) {
while (!q.empty()) {
int x = q.front(); q.pop();
vis[x] = 0;
for (int y = 1; y <= n; ++y)
if (dis[x] + d[x][y] < dis[y]) {
dis[y] = dis[x] + d[x][y], pre[y] = x;
if (!vis[y]) vis[y] = 1, q.push(y);
}
}
}
signed main() {
//仔细检查,边界,特殊情况 ! ! !
cerr << (&END - &START) / 1024.0 / 1024.0 << endl;
IN(n), IN(K);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= K; ++j)
IN(c[i][j]), g[j].push(mk(c[i][j], i));
for (int i = 1; i <= K; ++i) IN(a[i]);
int num = n;
while (num--) {
for (int i = 1; i <= K; ++i) dis[i] = inf, vis[i] = pre[i] = 0;
for (int i = 1; i <= K; ++i) for (int j = 1; j <= K; ++j) d[i][j] = inf;
for (int i = 1; i <= K; ++i) {
g[i].pop();
if (g[i].top().fi != -1) dis[i] = g[i].top().fi, vis[i] = 1, q.push(i);
}
for (int i = 1; i <= K; ++i)
for (int j = 1; j <= K; ++j)
if (i != j) {
f[i][j].pop(i);
if (f[i][j].top().fi != -1)
d[i][j] = f[i][j].top().fi;
}
spfa(K);
int p = 0; dis[0] = inf;
for (int i = 1; i <= K; ++i) if (a[i] && dis[i] < dis[p]) p = i;
a[p]--, ans += dis[p];
while (p) {
int x = pre[p], y = x ? f[x][p].top().se : g[p].top().se;
mtc[y] = p;
for (int i = 1; i <= K; ++i)
if (i != p)
f[p][i].push(mk(c[y][i] - c[y][p], y));
p = x;
}
}
write(ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4036kb
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: 0ms
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: 0
Accepted
time: 0ms
memory: 4180kb
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:
92039
result:
ok answer is '92039'
Test #4:
score: -100
Wrong Answer
time: 9ms
memory: 5204kb
input:
5000 10 14 114 254 832 38 904 25 147 998 785 917 694 750 372 379 887 247 817 999 117 802 15 799 515 316 42 69 247 95 144 727 398 509 725 682 456 369 656 693 955 923 1 681 631 962 826 233 963 289 856 165 491 488 832 111 950 853 791 929 240 509 843 667 970 469 260 447 477 161 431 514 903 627 236 144 3...
output:
461881
result:
wrong answer expected '461878', found '461881'