QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#637744#1809. Find the MST for GridbrendonwWA 2ms5712kbC++143.4kb2024-10-13 13:58:192024-10-13 13:58:20

Judging History

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

  • [2024-10-13 13:58:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5712kb
  • [2024-10-13 13:58:19]
  • 提交

answer

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/* NAMESPACE */

using namespace std;
using namespace __gnu_pbds;

/* HASH */

struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

template<class K, class V> using safe_map = unordered_map<K, V, custom_hash>;
template<class K, class V> using safe_ht = gp_hash_table<K, V, custom_hash>;
template<class K> using safe_set = unordered_set<K, custom_hash>;
template<class K> using safe_htset = gp_hash_table<K, null_type, custom_hash>;

/* CLASSES */

using ll = long long;
using pii = pair<int, int>;
template<class T> using pp = pair<T, T>;
using pll = pp<ll>;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using greater_pq = priority_queue<T, vector<T>, greater<>>;
template<class T> using V = vector<T>;
using vi = V<int>;
using vvi = V<vi>;
using vvvi = V<vvi>;
using vll = V<ll>;

/* FUNCTIONS */

template<class T, class U>
T max(T a, U b) {
	return (a > b) ? a : b;
}

template<class T, class U>
T min(T a, U b) {
	return (a < b) ? a : b;
}

template<class T>
T power(T x, T y) {
	T res = 1;
	for (T i = 0; i < y; i++) {
		res *= x;
	}
	return res;
}



/* MACROS */
#define filln(arr, n, val) fill(arr, arr + n, val)
#define clearall(arr) memset(arr, 0, sizeof arr)
#define clearn(arr, n) memset(arr, 0, n * sizeof arr[0])
#define resetall(arr) memset(arr, -1, sizeof arr)
#define resetn(arr, n) memset(arr, -1, n * sizeof arr[0])
#define YESNO(condition) cout << ((condition) ? "YES" : "NO")
#define sfunc(a, b, c) a = c((a), (b))
#define smin(a, b) sfunc((a), (b), min)
#define smax(a, b) sfunc((a), (b), max)
#define all(x) begin(x), end(x)
#define sz(a) (int)(a).size()
#define readall(arr, n) for (int i = 0; i < n; i++) cin >> arr[i];
#define printall(arr, n) for (int i = 0; i < n; i++) cout << arr[i] << " ";

/* CONSTANTS */
const int inf = 2e9;
const ll infl = 4e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 1e5 + 5;

int a[MAXN], b[MAXN], c[MAXN], d[MAXN];
int d1[MAXN], d2[MAXN];
int cnt[MAXN];

int solve() {
	int h, w;
	cin >> h >> w;
	for (int i = 1; i < h; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < w; ++i) {
		cin >> b[i];
	}
	for (int i = 0; i < h; ++i) {
		cin >> c[i];
	}
	for (int i = 1; i < w; ++i) {
		cin >> d[i];
	}
	ll ans = 0;
	for (int i = 1; i < w; ++i) {
		ans += c[0] + d[i];
		ans += b[i] * (h - 1);
		d2[i] = b[i] - d[i];
	}
	for (int i = 1; i < h; ++i) {
		ans += a[i] + b[0];
		ans += a[i] * (w - 1);
		d1[i] = c[i] - a[i];
	}
	sort(d1 + 1, d1 + h);
	sort(d2 + 1, d2 + w);
	int j = 1;
	for (int i = 1; i < h; ++i) {
		while (d2[j] <= d1[i] && j < w) {
			j++;
		}
		ans += d1[i] * (w - j);
		cnt[j]++;
	}
	for (int i = 1; i < w; ++i) {
		cnt[i] += cnt[i - 1];
		ans -= d2[i] * cnt[i];
	}
	cout << ans;
	return 0;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T = 1;
//	cin >> T;
	while (T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3
1
1 3 6
1 4
1 2

output:

17

result:

ok answer is '17'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

4 3
1 13 15
3 6 11
3 6 6 11
9 17

output:

173

result:

ok answer is '173'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

2 3
968418
431416 672770 680574
552160 624114
892963 920468

output:

7379244

result:

ok answer is '7379244'

Test #4:

score: 0
Accepted
time: 0ms
memory: 5636kb

input:

3 2
118689 499942
45109 920606
327638 468788 633079
149844

output:

2587886

result:

ok answer is '2587886'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

3 3
171815 356177
228641 395286 978617
702666 792511 913883
169671 180825

output:

6127710

result:

ok answer is '6127710'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

3 4
7184 620183
79780 130738 487556 848611
232818 371375 944380
216990 936022 983989

output:

8438293

result:

ok answer is '8438293'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5712kb

input:

4 3
51985 136713 427919
188504 312899 371141
145631 227550 731171 833357
160747 573726

output:

5493218

result:

ok answer is '5493218'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

7 5
175926 428984 582661 582839 820907 920776
322080 633264 798688 811692 823441
54339 220390 250291 330054 371881 842806 885846
441838 703407 941999 978043

output:

37806417

result:

ok answer is '37806417'

Test #9:

score: 0
Accepted
time: 1ms
memory: 5628kb

input:

9 8
128346 182079 277192 434166 657634 823595 853129 940474
707 292710 363361 404369 494504 600358 796392 872568
95548 456201 544335 582372 695261 827770 860026 928632 994917
160921 262851 319385 402844 959489 982420 982699

output:

69150796

result:

ok answer is '69150796'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

7 7
390088 456793 662796 811369 863901 997123
174627 272343 294065 376553 692154 797046 972456
76702 401950 405513 470226 553463 682122 826908
106803 293625 306370 544706 575270 828264

output:

44304980

result:

ok answer is '44304980'

Test #11:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

7 7
270291 358878 423424 570235 772251 986431
45308 139839 229024 246723 264432 343181 778141
74325 203070 240656 330399 549696 621374 856760
57300 464802 541216 680595 915767 928652

output:

38909585

result:

ok answer is '38909585'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

9 8
255312 314659 435326 436128 464484 507292 727368 807464
103501 293849 414270 474996 838635 874511 965537 971583
204709 230699 251434 494013 570649 664454 741866 906547 910970
419608 622510 678766 703125 809137 903338 923781

output:

76479411

result:

ok answer is '76479411'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

90 15
1569 7812 15560 17225 19225 21440 63872 67763 73422 92647 98398 106522 110109 112693 114487 122224 154052 155699 158235 174012 175798 176730 177959 187239 190924 206750 217783 229076 247986 249130 260497 265264 269052 285315 291931 327499 331976 337424 338165 352012 363333 370568 370943 373038...

output:

1149258768

result:

ok answer is '1149258768'

Test #14:

score: 0
Accepted
time: 1ms
memory: 5712kb

input:

573 762
3338 5419 5645 6157 7116 8262 8393 8399 8717 13114 13179 15879 16350 18675 18777 20835 21329 23456 25635 25875 26218 27153 27503 27953 28438 30788 32050 35179 35273 35416 44186 47640 48200 49720 51545 51756 52851 52886 53427 56462 56541 57087 58701 61500 63233 63449 63650 64330 71582 72299 7...

output:

425651347739

result:

ok answer is '425651347739'

Test #15:

score: -100
Wrong Answer
time: 2ms
memory: 5692kb

input:

5523 5571
187 355 377 524 572 593 624 947 957 973 1147 1287 1861 1911 2165 2436 2560 2806 2875 2924 3028 3035 3090 3210 4339 4372 4520 4531 4580 5137 5395 5686 5710 5802 5994 6494 6816 6919 7012 7349 7609 7783 7833 7943 8016 8242 8327 8422 8475 8489 8608 8619 8659 8686 8709 8738 9353 9423 9651 9692 ...

output:

1462956024256

result:

wrong answer expected '30844827296192', found '1462956024256'