QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#553563#7185. Poor Studentslsj2009TL 1ms6104kbC++172.4kb2024-09-08 15:29:082024-09-08 15:29:09

Judging History

你现在查看的是最新测评结果

  • [2024-09-08 15:29:09]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:6104kb
  • [2024-09-08 15:29:08]
  • 提交

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);
	}
	PII top(int x=0) {
		while(!heap.empty()&&match[heap.top().second]!=x)
			heap.pop();
		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[N];
bool inq[M];
queue<int> q;
void spfa(int n) {
	cl(pre,0);
	while(!q.empty()) {
		int u=q.front(); q.pop();
		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);
		while(!q.empty())
			q.pop();
		rep(i,1,k) {
			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) {
					int x=f[i][j].top(i).first;
					if(x!=-1)
						d[i][j]=x;
				}
			}
		}
		spfa(k);
		int t=0;
		rep(i,1,k) {
			if(a[i]&&dis[t]>dis[i])
				t=i;
		}
		--a[t];
		res+=dis[t];
		while(t) {
			int v=pre[t],x=v? f[v][t].top(v).second:g[t].top().second;
			match[x]=t;
			rep(j,1,k) {
				if(j!=t)
					f[t][j].push(make_pair(c[x][j]-c[x][t],x));
			}
			t=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: 1ms
memory: 6104kb

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: 1ms
memory: 4300kb

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
Time Limit Exceeded

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:


result: