QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555742#7185. Poor StudentsYansuan_HClWA 3ms6152kbC++203.0kb2024-09-10 09:00:112024-09-10 09:00:12

Judging History

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

  • [2024-09-10 09:00:12]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6152kb
  • [2024-09-10 09:00:11]
  • 提交

answer

#include <bits/stdc++.h>
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline)) static
#define U(i,l,r) for(int i(l),END##i(r);i<=END##i;++i)
#define D(i,r,l) for(int i(r),END##i(l);i>=END##i;--i)
using namespace std;
using ll = long long;

#define IC isdigit(c)
#define GC c=getchar()
void rd(auto &x) { x = 0; char GC; bool f = 0;
	for (; !IC; GC) f |= c == '-';
	for (; IC; GC) x = x * 10 + c - 48;
	if (f) x = -x;
}
void rd(auto &x, auto &...y) { rd(x); rd(y...); }
#define meow(...) fprintf(stderr, __VA_ARGS__)
#define Assert(e, v) if (!(e)) exit(v);

#define vc vector
#define pb push_back
#define eb emplace_back

const int N = 50005, M = 14;
int n, m;
ll c[N][M], f[M], g[N]; bool dir[N][M];

multiset<pair<ll, int>> e[M][M];
const ll INF = 0x3f3f3f3f'3f3f3f3f;

int main() {
//	freopen("ava.in", "r", stdin);
	
	rd(n, m);
	U (i, 1, n) U (j, 1, m) rd(c[i][j]);
	U (i, 1, m) rd(f[i]);
	U (i, 1, n) g[i] = 1;
	
	U (i, 1, m) U (k, 1, n)
		e[0][i].emplace(c[k][i], k);
	
	ll ans = 0;
	U (_, 1, n) {
		ll dis[M][M]; ms(dis, 0x3f);
		U (u, 1, m) U (v, 1, m) {
			if (u == v) dis[u][v] = 0;
			else dis[u][v] = e[u][v].size() ? e[u][v].begin()->first : INF;
		}
		U (u, 1, m) if (e[0][u].size()) {
			dis[m + 1][u] = e[0][u].begin()->first;
			assert(g[e[0][u].begin()->second]);
		}
		U (u, 1, m) if (f[u])
			dis[u][m + 2] = 0;
		
		int tr[M][M] {};
		U (w, 1, m + 2) U (u, 1, m + 2) U (v, 1, m + 2) if (dis[u][v] + dis[v][w] < dis[u][w]) {
			dis[u][w] = dis[u][v] + dis[v][w];
			tr[u][w] = v;
		}
		ll cur = dis[m + 1][m + 2];
		
		vc<int> path;
		auto get = [&](const auto &self, int u, int w)->void {
			int v = tr[u][w];
			if (!v) return;
			self(self, u, v);
			path.pb(v);
			self(self, v, w);
		};
		path.pb(m + 1);
		get(get, m + 1, m + 2);
		path.pb(m + 2);
		
		vc<pair<int, int>> flip;
		U (t, 0, path.size() - 2) {
			int u = path[t], v = path[t + 1];
			if (u == m + 1) {
				int w = e[0][v].begin()->second;
				assert(g[w]);
				g[w] = 0;
				U (i, 1, m) {
					auto it = e[0][i].find({c[w][i], w});
					if (it != e[0][i].end())
						e[0][i].erase(it);
				}
				flip.eb(w, v);
			} else if (v == m + 2) {
				assert(f[u] > 0);
				--f[u];
			} else {
				int w = e[u][v].begin()->second;
				flip.eb(w, u);
				flip.eb(w, v);
			}
		}
		for (auto [x, v] : flip) {
			if (dir[x][v]) {
				U (u, 1, m) if (!dir[x][u])
					e[v][u].erase({-c[x][v] + c[x][u], x});
				dir[x][v] = 0;
				U (u, 1, m) if (dir[x][u])
					e[u][v].insert({-c[x][u] + c[x][v], x});
				if (g[x])
					e[0][v].insert({c[x][v], x});
			} else { // x to v
				if (g[x]) {
					auto it = e[0][v].find({c[x][v], x});
					assert(it != e[0][v].end());
					e[0][v].erase({c[x][v], x});
				}
				U (u, 1, m) if (dir[x][u])
					e[u][v].erase({-c[x][u] + c[x][v], x});
				dir[x][v] = 1;
				U (u, 1, m) if (!dir[x][u])
					e[v][u].insert({-c[x][v] + c[x][u], x});
			}
		}
		ans += cur;
	}
	cout << ans << endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3488kb

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: 5636kb

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: 3ms
memory: 6152kb

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:

92017

result:

wrong answer expected '92039', found '92017'