QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637709 | #1809. Find the MST for Grid | brendonw | WA | 1ms | 5760kb | C++14 | 3.4kb | 2024-10-13 13:53:08 | 2024-10-13 13:53:09 |
Judging History
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] + c[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: 1ms
memory: 5760kb
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: 3736kb
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: -100
Wrong Answer
time: 1ms
memory: 3604kb
input:
2 3 968418 431416 672770 680574 552160 624114 892963 920468
output:
7499988
result:
wrong answer expected '7379244', found '7499988'