QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#295847 | #7185. Poor Students | ckiseki | WA | 2ms | 4136kb | C++23 | 2.9kb | 2024-01-01 12:43:33 | 2024-01-01 12:43:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef local
#define safe cerr << __LINE__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
using lld = int64_t;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, k;
cin >> n >> k;
auto c = vector(n, vector(k, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++)
cin >> c[i][j];
}
vector<int> a(k);
for (int &x : a) cin >> x;
using PQ = min_heap<pair<lld, int>>;
auto aug_pq = vector(k, vector<PQ>(k));
// auto pq = vector<PQ>(k);
lld ans = 0;
for (int i = 0; i < n; i++) {
// tuple<lld, int, int> best(numeric_limits<lld>::max(), -1, -1);
const int S = k, T = k + 1;
const int tot = k + 2;
auto g = vector(tot, vector<pair<lld, int>>(tot, pair(numeric_limits<lld>::max(), -1)));
for (int x = 0; x < k; x++) {
g[S][x] = pair<lld, int>(c[i][x], -1);
}
for (int x = 0; x < k; x++) {
if (a[x] > 0)
g[x][T] = pair<lld, int>(0, -1);
}
for (int x = 0; x < k; x++) {
for (int y = 0; y < k; y++) {
if (!aug_pq[x][y].empty()) {
g[x][y] = aug_pq[x][y].top();
}
}
}
vector<lld> dis(tot, numeric_limits<lld>::max());
vector<pair<int,int>> prv(tot, pair(-1, -1));
vector<int> inque(tot);
queue<int> que;
dis[S] = 0;
que.emplace(S);
inque[S] = true;
while (!que.empty()) {
int x = que.front(); que.pop();
inque[x] = false;
for (int y = 0; y < tot; y++) {
if (g[x][y].first == numeric_limits<lld>::max()) continue;
if (dis[y] > dis[x] + g[x][y].first) {
dis[y] = dis[x] + g[x][y].first;
prv[y] = pair(x, g[x][y].second);
if (!inque[y]) {
que.emplace(y);
inque[y] = true;
}
}
}
}
ans += dis[T];
for (int y = T; y != S; y = prv[y].first) {
int x = prv[y].first;
if (x == S) {
for (int j = 0; j < k; j++)
if (j != y)
aug_pq[y][j].emplace(c[i][j] - c[i][y], i);
} else if (y == T) {
--a[x];
} else {
aug_pq[x][y].pop();
aug_pq[y][x].emplace(-g[x][y].first, g[x][y].second);
}
}
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3588kb
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
Wrong Answer
time: 2ms
memory: 4136kb
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:
91979
result:
wrong answer expected '92039', found '91979'