QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397840#7185. Poor Studentszhangtx123WA 1ms3832kbC++143.6kb2024-04-24 17:33:532024-04-24 17:33:54

Judging History

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

  • [2024-04-24 17:33:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3832kb
  • [2024-04-24 17:33:53]
  • 提交

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 {
		if(dis == A.dis) return x < A.x; 
		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, b[N]; 
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; 
//	if(x == 112) debag("> 1\n"); 
	for(i = 1; i <= m; ++i) if(!a[i]) q.push({vis[i], i}); 
//	if(x == 112) debag("> 2\n"); 
	int cnt = 0; 
//	if(x == 5) 
	debug("### %d\n", s[1][2].size()); 
	while(!q.empty()) {
		auto t = q.top(); q.pop(); int u = t.se; 
//		++cnt; 
		b[u] = 0; 
//		assert(cnt <= 100); 
//		if(t.fi != vis[u]) continue; 
//		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(x == 5 && (it -> x) == 2) 
			if(x == 5) debug("[%lld]%lld --> %lld [%lld]\n", it -> x, u, v, (it -> dis)); 
			
			if(vis[u] + (it -> dis) < vis[v]) {
//				if(u == v) debag("%lld %lld %lld\n", u, vis[u], (it -> dis)); 
//				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] && b[v] == 0) q.push({vis[v], v}), b[v] = 1; 
			}
		}
	}
//	if(x == 112) debag("> 3\n"); 
	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); 
	if(x == 5) for(i = 1; i <= n; ++i) printf("%lld ", xuan[i]); 
	ans += vis[j]; --a[j]; 
//	if(x == 112) debag("> 4\n"); 
//	if(x == 5) {
//		for(i = 1; i <= m; ++i) debug("%lld ", vis[i]); debug("| %lld\n", j); 
//		for(i = 1; i <= m; ++i) debug("%lld ", lst[i]); debug("\n"); 
//		
//	}
	while(lst[j]) {
		set<node> :: iterator it = s[lst[j]][j].begin(); 
		y = (it -> x); 
		for(i = 1; i <= m; ++i) 
//			if(c[y][i] - c[y][xuan[y]] > 0)
			s[xuan[y]][i].erase({y, c[y][i] - c[y][xuan[y]]}); 
		xuan[y] = j; z.push(y); 
		j = lst[j]; 
	}
//	if(x == 112) debag("> 5\n"); 
	xuan[x] = j; z.push(x); 
//	debug("xuan[%lld] -> %lld\n", x, xuan[x]); 
//	assert(z.size() <= k + 5); 
//	assert(x <= 900); 
//	if(x % 10 == 0) debag("%lld\n" , x); 
	while(!z.empty()) {
		y = z.top(); z.pop(); 
		debug("adjust %lld to %lld\n", y, xuan[y]); 
		for(i = 1; i <= m; ++i) 
//			if(c[y][i] - c[y][xuan[y]] > 0)
				s[xuan[y]][i].insert({y, c[y][i] - c[y][xuan[y]]}); 
	}
}

signed main()
{
	#ifdef LOCAL
	  freopen("j2.in", "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[j] = 0; 
		spfa(i); 
	}
	for(i = 1; i <= n; ++i) debug("%lld ", xuan[i]); debug("\n"); 
//	for(i = 1, ans = 0; i <= n; ++i) ans += c[i][xuan[i]]; 
	printf("%lld", ans); 
	return 0;
}

详细

Test #1:

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

input:

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

output:

2 1 1 1 0 0 12

result:

wrong answer expected '12', found '2'