QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397760#7185. Poor Studentszhangtx123WA 1ms5800kbC++142.6kb2024-04-24 16:46:562024-04-24 16:46:56

Judging History

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

  • [2024-04-24 16:46:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5800kb
  • [2024-04-24 16:46:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
 #define debug(...) fprintf(stdout, ##__VA_ARGS__)
 #define debag(...) fprintf(stderr, ##__VA_ARGS__)
#else
 #define debug(...) void(0)
 #define debag(...) void(0)
#endif
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
#define Z(x) (x)*(x)
#define pb push_back
#define fi first
#define se second
#define M 12
//#define mo
#define N 50010
struct node {
	int x, dis; 
	bool operator < (const node &A) const {
		return dis < A.dis; 
	}
}; 
set<node> s[M][M]; 
priority_queue< pair<int, int> >q; 
int vis[N], a[N], xuan[N], lst[N]; 
int c[N][M], ans; 
stack<int>z; 
int n, m, i, j, k, T;

void spfa(int x) {
	// s[u][v] k -> u ==> k -> v
//	debag("In %lld\n", x); 
	int i, v, y; 
	for(i = 1; i <= m; ++i) if(!a[i]) q.push({vis[i], i}); 
	while(!q.empty()) {
		auto t = q.top(); q.pop(); int u = t.se; 
//		debag("$ %lld\n", u); 
		for(v = 1; v <= m; ++v) {
			if(s[u][v].begin() == s[u][v].end()) continue; 
			set<node> :: iterator it = s[u][v].begin(); 
			if(vis[u] + (it -> dis) < vis[v]) {
//				debug("%lld == %lld(%lld) to %lld\n", u, (it -> dis), (it -> x), v); 
				vis[v] = vis[u] + (it -> dis); lst[v] = u; 
				if(!a[v]) q.push({vis[v], v}); 
			}
		}
	}
	for(i = 1, j = 0, vis[0] = 1e18; i <= m; ++i)
		if(a[i] && vis[i] < vis[j]) j = i; 
//	for(i = 1; i <= m; ++i) debug("%lld ", vis[i]); debug("| %lld\n", j); 
	ans += vis[j]; --a[j]; 
	while(lst[j]) {
		set<node> :: iterator it = s[lst[j]][j].begin(); 
		y = (it -> x); 
		for(i = 1; i <= m; ++i) 
			s[xuan[y]][i].erase({y, c[y][i] - c[y][xuan[y]]}); 
		xuan[y] = j; z.push(y); 
		j = lst[j]; 
	}
	xuan[x] = j; z.push(x); 
//	debug("xuan[%lld] -> %lld\n", x, xuan[x]); 
	assert(z.size() <= k + 5); 
	while(!z.empty()) {
		y = z.top(); z.pop(); 
//		debug("adjust %lld to %lld\n", y, xuan[y]); 
		for(i = 1; i <= m; ++i) 
			s[xuan[y]][i].insert({y, c[y][i] - c[y][xuan[y]]}); 
	}
}

signed main()
{
	#ifdef LOCAL
	  freopen("in.txt", "r", stdin);
	  freopen("out.txt", "w", stdout);
	#endif
//	srand(time(NULL));
//	T=read();
//	while(T--) {
//
//	}
	n = read(); m = read(); 
	for(i = 1; i <= n; ++i) for(j = 1; j <= m; ++j) c[i][j] = read(); 
	for(i = 1; i <= m; ++i) a[i] = read(); 
	for(i = 1; i <= n; ++i) {
		for(j = 1; j <= m; ++j) vis[j] = c[i][j], lst[i] = 0; 
//		spfa(i); 
	}
//	for(i = 1; i <= n; ++i) debug("%lld ", xuan[i]); debug("\n"); 
	printf("%lld", ans); 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5800kb

input:

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

output:

0

result:

wrong answer expected '12', found '0'