Submission #62301207
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll = long long;
using ii = pair<uint32_t, uint32_t>;
#ifdef ONLINE_JUDGE
#define cerr \
if (false) cerr // Disable cerr output by making it an empty statement
#endif
#define dbg(v) cerr << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << '\n';
#define INT(...) \
int __VA_ARGS__; \
IN(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
IN(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
IN(__VA_ARGS__)
#define CHR(...) \
char __VA_ARGS__; \
IN(__VA_ARGS__)
#define DBL(...) \
long double __VA_ARGS__; \
IN(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void read(int &a) { cin >> a; }
void read(unsigned int &a) { cin >> a; }
void read(long long &a) { cin >> a; }
void read(char &a) { cin >> a; }
void read(double &a) { cin >> a; }
void read(long double &a) { cin >> a; }
void read(string &a) { cin >> a; }
template <class T, class S>
void read(pair<T, S> &p) {
read(p.first), read(p.second);
}
template <typename... Args>
void read(tuple<Args...> &t) {
apply([&](auto &...xs) { (read(xs), ...); }, t);
}
template <class T>
void read(vector<T> &a) {
for (auto &i : a) read(i);
}
template <class T>
void read(T &a) {
cin >> a;
}
void IN() {}
template <class Head, class... Tail>
void IN(Head &head, Tail &...tail) {
read(head);
IN(tail...);
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &A) {
os << A.first << " " << A.second;
return os;
}
template <typename... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
apply(
[&os](const auto &...xs) {
size_t n = 0;
((os << (n++ ? " " : "") << xs), ...);
},
t);
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &A) {
for (size_t i = 0; i < A.size(); i++) {
if (i) os << " ";
os << A[i];
}
return os;
}
class CoutInitializer {
public:
CoutInitializer() { std::cout << std::fixed << std::setprecision(15); }
};
static CoutInitializer cout_initializer;
void print() {
cout << "\n";
cout.flush();
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(Tail)) cout << " ";
print(forward<Tail>(tail)...);
}
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
ll safe_mul(int a, int b, int c) { return 1LL * a * b + 1LL * b * c + 1LL * a * c; }
std::string int128ToString(__int128 value) {
if (value == 0) return "0";
bool isNegative = value < 0;
if (isNegative) value = -value;
std::string result;
while (value > 0) {
result = char('0' + (value % 10)) + result;
value /= 10;
}
if (isNegative) result = '-' + result;
return result;
}
ll store(ll a, ll b, int c) { return (a << 40) | (b << 20) | c; }
tuple<int, int, int> retrieve(ll v) {
return {(v >> 40) & 0xFFFFF, (v >> 20) & 0xFFFFF, (v & 0xFFFFF)};
}
void solve() {
INT(n, k);
VV(ll, mat, 3, n);
for (int ctr1 = 0; ctr1 < 3; ++ctr1) ranges::sort(mat[ctr1]);
priority_queue<pair<ll, ll>> pq;
pq.emplace(safe_mul(mat[0][n - 1], mat[1][n - 1], mat[2][n - 1]), store(n - 1, n - 1, n - 1));
int order = 0;
set<ll> done;
while (!pq.empty()) {
auto [nxt, bm] = pq.top();
pq.pop();
if (++order == k) {
cout << nxt << '\n';
return;
}
auto [x, y, z] = retrieve(bm);
vector<int> cur = {x, y, z};
ll bm1 = store(x - 1, y, z);
if (x - 1 >= 0 && !done.count(bm1)) {
pq.emplace(safe_mul(mat[0][x - 1], mat[1][y], mat[2][z]), bm1);
done.insert(bm1);
}
bm1 = store(x, y - 1, z);
if (y - 1 >= 0 && !done.count(bm1)) {
pq.emplace(safe_mul(mat[0][x], mat[1][y - 1], mat[2][z]), bm1);
done.insert(bm1);
}
bm1 = store(x, y, z - 1);
if (z - 1 >= 0 && !done.count(bm1)) {
pq.emplace(safe_mul(mat[0][x], mat[1][y], mat[2][z - 1]), bm1);
done.insert(bm1);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
}
Submission Info
Submission Time |
|
Task |
F - K-th Largest Triplet |
User |
nasa |
Language |
C++ 20 (Clang 16.0.6) |
Score |
500 |
Code Size |
4892 Byte |
Status |
AC |
Exec Time |
849 ms |
Memory |
76272 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt, 01_test_44.txt, 01_test_45.txt, 01_test_46.txt, 01_test_47.txt, 01_test_48.txt, 01_test_49.txt, 01_test_50.txt, 01_test_51.txt, 01_test_52.txt, 01_test_53.txt, 01_test_54.txt, 01_test_55.txt, 01_test_56.txt, 01_test_57.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_00.txt |
AC |
1 ms |
3400 KB |
00_sample_01.txt |
AC |
1 ms |
3412 KB |
00_sample_02.txt |
AC |
1 ms |
3540 KB |
01_test_00.txt |
AC |
1 ms |
3480 KB |
01_test_01.txt |
AC |
37 ms |
6496 KB |
01_test_02.txt |
AC |
229 ms |
14844 KB |
01_test_03.txt |
AC |
298 ms |
18324 KB |
01_test_04.txt |
AC |
615 ms |
27736 KB |
01_test_05.txt |
AC |
637 ms |
30016 KB |
01_test_06.txt |
AC |
703 ms |
30824 KB |
01_test_07.txt |
AC |
506 ms |
26112 KB |
01_test_08.txt |
AC |
737 ms |
32580 KB |
01_test_09.txt |
AC |
702 ms |
30144 KB |
01_test_10.txt |
AC |
716 ms |
32352 KB |
01_test_11.txt |
AC |
468 ms |
59764 KB |
01_test_12.txt |
AC |
439 ms |
54640 KB |
01_test_13.txt |
AC |
475 ms |
68160 KB |
01_test_14.txt |
AC |
500 ms |
74852 KB |
01_test_15.txt |
AC |
622 ms |
62716 KB |
01_test_16.txt |
AC |
617 ms |
62564 KB |
01_test_17.txt |
AC |
590 ms |
61580 KB |
01_test_18.txt |
AC |
770 ms |
62712 KB |
01_test_19.txt |
AC |
807 ms |
62700 KB |
01_test_20.txt |
AC |
786 ms |
62664 KB |
01_test_21.txt |
AC |
849 ms |
57800 KB |
01_test_22.txt |
AC |
827 ms |
62648 KB |
01_test_23.txt |
AC |
716 ms |
32352 KB |
01_test_24.txt |
AC |
650 ms |
32536 KB |
01_test_25.txt |
AC |
413 ms |
68820 KB |
01_test_26.txt |
AC |
400 ms |
68824 KB |
01_test_27.txt |
AC |
537 ms |
74940 KB |
01_test_28.txt |
AC |
536 ms |
74996 KB |
01_test_29.txt |
AC |
531 ms |
74888 KB |
01_test_30.txt |
AC |
528 ms |
74980 KB |
01_test_31.txt |
AC |
657 ms |
74880 KB |
01_test_32.txt |
AC |
667 ms |
74948 KB |
01_test_33.txt |
AC |
644 ms |
75028 KB |
01_test_34.txt |
AC |
642 ms |
74892 KB |
01_test_35.txt |
AC |
656 ms |
74964 KB |
01_test_36.txt |
AC |
654 ms |
75016 KB |
01_test_37.txt |
AC |
651 ms |
74888 KB |
01_test_38.txt |
AC |
653 ms |
74944 KB |
01_test_39.txt |
AC |
634 ms |
74980 KB |
01_test_40.txt |
AC |
637 ms |
74900 KB |
01_test_41.txt |
AC |
633 ms |
74940 KB |
01_test_42.txt |
AC |
519 ms |
74936 KB |
01_test_43.txt |
AC |
426 ms |
74996 KB |
01_test_44.txt |
AC |
394 ms |
74880 KB |
01_test_45.txt |
AC |
395 ms |
74912 KB |
01_test_46.txt |
AC |
840 ms |
76272 KB |
01_test_47.txt |
AC |
70 ms |
9340 KB |
01_test_48.txt |
AC |
1 ms |
3584 KB |
01_test_49.txt |
AC |
549 ms |
26700 KB |
01_test_50.txt |
AC |
650 ms |
32560 KB |
01_test_51.txt |
AC |
624 ms |
32332 KB |
01_test_52.txt |
AC |
354 ms |
62312 KB |
01_test_53.txt |
AC |
410 ms |
62380 KB |
01_test_54.txt |
AC |
540 ms |
62528 KB |
01_test_55.txt |
AC |
287 ms |
42060 KB |
01_test_56.txt |
AC |
306 ms |
42096 KB |
01_test_57.txt |
AC |
330 ms |
42136 KB |