QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#219515 | #7185. Poor Students | ucup-team198 | WA | 2ms | 3820kb | C++17 | 2.5kb | 2023-10-19 15:51:11 | 2023-10-19 15:51:11 |
Judging History
answer
#include<iostream>
#include<cmath>
#include<cstring>
#include<cassert>
#include<string>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<vector>
#include<set>
#include<unordered_set>
#include<bitset>
#include<climits>
#include<numeric>
#include<functional>
#include<iomanip>
#ifdef YJL
#include<debug.h>
#else
#define debug(args...)0
#define debug_n(a,n)0
#endif
#define ALL(a) a.begin(),a.end()
using namespace std;
using ll=long long;
using PQ = priority_queue<pair<int,int>,vector<pair<int,int>>, greater<>>;
PQ pq[11][10];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n,k;
cin>>n>>k;
constexpr int inf = 0x3f3f3f3f;
vector c(n,vector<int>(k+1));
for(int i=0; i<n; ++i) {
for(int j=0; j<k; ++j) {
cin>>c[i][j];
}
c[i][k] = inf;
}
vector<int> a(k+1);
for(int i=0; i<k; ++i) {
cin>>a[i];
}
ll ans = 1ll*inf*n;
vector<int> place(n, k);
for(int i=0; i<n; ++i) {
for(int j=0; j<k; ++j) {
pq[j][k].emplace(c[i][j] - c[i][k], i);
}
}
vector<int> vis(k+1);
for(int turn=0; turn<n; ++turn) {
// find shortest path
vector<ll> dis(k+1, 1e18);
vector<int> pre(k+1, -1);
queue<int> q;
for(int i=0; i<k; ++i) {
if(a[i]) {
q.push(i), dis[i] = 0, vis[i] = true;
}
}
while(q.size()) {
int u = q.front(); q.pop();
vis[u] = false;
for(int v=0; v<=k; ++v) {
if(v==u) continue;
while(pq[u][v].size() and place[pq[u][v].top().second] != v)
pq[u][v].pop();
if(pq[u][v].empty())
continue;
if(dis[v] > dis[u]+pq[u][v].top().first) {
dis[v] = dis[u]+pq[u][v].top().first;
pre[v] = u;
if(!vis[v]) {
q.push(v), vis[v] = true;
}
}
}
}
ans += dis[k];
for(int j=k; pre[j]!=-1; j=pre[j]) {
int p = pre[j];
int u = pq[p][j].top().second;
place[u] = p;
a[j]++;
a[p]--;
for(int i=0; i<k; ++i)
if(i!=p)
pq[i][p].emplace(c[u][i] - c[u][p], u);
}
}
cout << ans;
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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: 3624kb
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: 3820kb
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:
2875821079732670170
result:
wrong answer expected '92039', found '2875821079732670170'