QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#171348 | #7185. Poor Students | ucup-team1525# | WA | 1ms | 4308kb | C++17 | 2.1kb | 2023-09-09 16:50:42 | 2023-09-09 16:50:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5.1e4,K=10,M=2e6;
using ll=long long;
const ll inf=1ll<<60;
int n,k;
int c[N+5][K+5];
int a[11],use[11];
set<pair<int,int>> d[K+5][K+5];
int w[11][11];
int ver[11][11];
ll ans;
void del(int ri,int li){
for(int i=1;i<=k;i++){
if(i==ri) continue;
d[ri][i].erase(make_pair(-c[li][ri]+c[li][i],li));
}
}
void add(int ri,int li){
for(int i=1;i<=k;i++){
if(i==ri) continue;
d[ri][i].insert(make_pair(-c[li][ri]+c[li][i],li));
}
}
void make_w(){
for(int i=1;i<=k;i++)
for(int j=1;j<=k;j++){
if(!d[i][j].size()) w[i][j]=inf;
else{
auto it=*d[i][j].begin();
w[i][j]=it.first; ver[i][j]=it.second;
}
}
}
ll dis[11];
int pre[11];
int q[11],in[11];
int work(int x){
make_w();
int ql=0,qr=k-1;
for(int i=1;i<=k;i++){
dis[i]=c[x][i];
q[i-1]=i; in[i]=1;
pre[i]=0;
}
while(ql!=qr){
int u=q[ql]; ql++;
if(ql==k) ql-=k;
in[u]=0;
for(int v=1;v<=k;v++)
if(v!=u){
if(dis[v]>dis[u]+w[u][v]){
dis[v]=dis[u]+w[u][v]; pre[v]=u;
if(!in[v]){
++qr;
if(qr>=k) qr-=k;
q[qr]=v; in[v]=1;
}
}
}
}
ll res=inf;
for(int i=1;i<=k;i++)
if(use[i]<a[i]) res=min(res,dis[i]);
ans+=res;
for(int i=1;i<=k;i++)
if(use[i]<a[i]&&dis[i]==res) return i;
}
void update(int x,int en){
while(pre[en]){
int pr=pre[en];
int y=ver[pr][en];
del(pr,y); add(en,y);
en=pr;
}
add(en,x); use[en]++;
}
int main(){
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=k;j++)
scanf("%d",&c[i][j]);
for(int i=1;i<=k;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
int mt=work(i);
update(i,mt);
}
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: 3916kb
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: 3832kb
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: 1ms
memory: 4308kb
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:
91767
result:
wrong answer expected '92039', found '91767'