QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#553574 | #7185. Poor Students | lsj2009 | WA | 8ms | 6376kb | C++17 | 2.5kb | 2024-09-08 15:40:22 | 2024-09-08 15:40:23 |
Judging History
answer
#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
#define int long long
#define i128 __int128
#define ll long long
#define ull unsigned long long
#define ld double
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define rep(k,l,r) for(int k=l;k<=r;++k)
#define per(k,r,l) for(int k=r;k>=l;--k)
#define cl(f,x) memset(f,x,sizeof(f))
#define pcnt(x) __builtin_popcount(x)
using namespace std;
void file_IO() {
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
bool M1;
const int N=5e4+5,M=15;
int match[N],c[N][M],a[M];
struct del_heap {
priority_queue<PII,vector<PII>,greater<PII>> heap;
void push(PII val) {
heap.push(val);
}
void pop(int x=0) {
while(!heap.empty()&&match[heap.top().second]!=x)
heap.pop();
}
PII top() {
if(heap.empty())
return make_pair(-1,-1);
return heap.top();
}
}; del_heap f[M][M],g[M];
int d[M][M],dis[M],pre[M];
bool inq[M];
queue<int> q;
void spfa(int n) {
while(!q.empty()) {
int u=q.front(); q.pop();
inq[u]=false;
rep(v,1,n) {
int w=d[u][v];
if(dis[v]>dis[u]+w) {
dis[v]=dis[u]+w;
pre[v]=u;
if(!inq[v]) {
q.push(v);
inq[v]=true;
}
}
}
}
}
void solve() {
int n,k;
scanf("%lld%lld",&n,&k);
rep(i,1,n) {
rep(j,1,k) {
scanf("%lld",&c[i][j]);
g[j].push(make_pair(c[i][j],i));
}
}
rep(i,1,k)
scanf("%lld",&a[i]);
int testcase=n,res=0;
while(testcase--) {
cl(dis,0x3f);
cl(d,0x3f);
cl(inq,false);
cl(pre,0);
while(!q.empty())
q.pop();
rep(i,1,k) {
g[i].pop();
int x=g[i].top().first;
if(x!=-1) {
dis[i]=x;
q.push(i);
inq[i]=true;
}
}
rep(i,1,k) {
rep(j,1,k) {
if(i!=j) {
f[i][j].pop(i);
int x=f[i][j].top().first;
if(x!=-1)
d[i][j]=x;
}
}
}
spfa(k);
int u=0;
rep(i,1,k) {
if(a[i]&&dis[u]>dis[i])
u=i;
}
--a[u];
res+=dis[u];
while(u) {
int v=pre[u],x=v? f[v][u].top().second:g[u].top().second;
match[x]=u;
rep(j,1,k) {
if(j!=u)
f[u][j].push(make_pair(c[x][j]-c[x][u],x));
}
u=v;
}
}
printf("%lld\n",res);
}
bool M2;
signed main() {
//file_IO();
int testcase=1;
//scanf("%d",&testcase);
while(testcase--)
solve();
cerr<<"used time = "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
cerr<<"used memory = "<<(&M1-&M2)/1024/1024<<"MB\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
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: 4104kb
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: 3ms
memory: 4616kb
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: 8ms
memory: 6376kb
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'