結果
問題 | No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩 |
ユーザー | 👑 Kazun |
提出日時 | 2020-10-21 14:13:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 3,605 bytes |
コンパイル時間 | 1,204 ms |
コンパイル使用メモリ | 91,036 KB |
実行使用メモリ | 37,068 KB |
最終ジャッジ日時 | 2024-06-08 11:56:18 |
合計ジャッジ時間 | 12,727 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 14 ms
5,376 KB |
testcase_19 | AC | 7 ms
5,376 KB |
testcase_20 | AC | 16 ms
5,376 KB |
testcase_21 | AC | 8 ms
5,376 KB |
testcase_22 | AC | 12 ms
5,376 KB |
testcase_23 | AC | 16 ms
5,376 KB |
testcase_24 | AC | 18 ms
5,504 KB |
testcase_25 | AC | 16 ms
5,376 KB |
testcase_26 | AC | 18 ms
5,376 KB |
testcase_27 | AC | 11 ms
5,376 KB |
testcase_28 | AC | 137 ms
18,280 KB |
testcase_29 | AC | 115 ms
14,204 KB |
testcase_30 | AC | 89 ms
11,876 KB |
testcase_31 | AC | 102 ms
16,760 KB |
testcase_32 | AC | 152 ms
28,052 KB |
testcase_33 | AC | 81 ms
12,288 KB |
testcase_34 | AC | 150 ms
23,396 KB |
testcase_35 | AC | 162 ms
17,868 KB |
testcase_36 | AC | 261 ms
30,640 KB |
testcase_37 | AC | 68 ms
13,260 KB |
testcase_38 | AC | 118 ms
13,804 KB |
testcase_39 | AC | 70 ms
10,376 KB |
testcase_40 | AC | 96 ms
14,076 KB |
testcase_41 | AC | 158 ms
20,032 KB |
testcase_42 | AC | 206 ms
22,636 KB |
testcase_43 | AC | 150 ms
17,540 KB |
testcase_44 | AC | 152 ms
18,616 KB |
testcase_45 | AC | 129 ms
15,372 KB |
testcase_46 | AC | 127 ms
24,780 KB |
testcase_47 | AC | 88 ms
13,516 KB |
testcase_48 | AC | 256 ms
36,964 KB |
testcase_49 | AC | 196 ms
37,068 KB |
testcase_50 | AC | 273 ms
36,960 KB |
testcase_51 | AC | 242 ms
36,964 KB |
testcase_52 | AC | 201 ms
36,964 KB |
testcase_53 | AC | 330 ms
36,832 KB |
testcase_54 | AC | 315 ms
36,964 KB |
testcase_55 | AC | 361 ms
36,960 KB |
testcase_56 | AC | 310 ms
36,836 KB |
testcase_57 | AC | 209 ms
36,908 KB |
testcase_58 | AC | 88 ms
20,196 KB |
testcase_59 | AC | 89 ms
20,200 KB |
testcase_60 | AC | 75 ms
20,200 KB |
testcase_61 | AC | 75 ms
20,200 KB |
testcase_62 | AC | 77 ms
20,268 KB |
testcase_63 | AC | 14 ms
14,464 KB |
testcase_64 | AC | 15 ms
14,576 KB |
testcase_65 | AC | 16 ms
14,464 KB |
testcase_66 | AC | 14 ms
14,464 KB |
testcase_67 | AC | 17 ms
14,464 KB |
testcase_68 | AC | 2 ms
5,376 KB |
testcase_69 | AC | 2 ms
5,376 KB |
testcase_70 | AC | 2 ms
5,376 KB |
testcase_71 | AC | 2 ms
5,376 KB |
testcase_72 | AC | 2 ms
5,376 KB |
testcase_73 | AC | 2 ms
5,376 KB |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<set> using namespace std; using ll = long long; void input(vector<ll>& X) { for (int i = 0; i < X.size(); i++) { cin >> X.at(i); } } ll abs_max(vector<ll> X) { ll t = 0; for (int i = 0; i < X.size(); i++) { if (t < abs(X.at(i))) { t = abs(X.at(i)); } } return t; } pair<ll, ll> h(ll x, vector<ll> G, vector<ll> H) { if (x == 0) { if (find(G.begin(), G.end(), 0) != G.end()) { return make_pair(0, H[0]); } else { return make_pair(G[0], 0); } } set<ll> F(H.begin(), H.end()); for (auto g : G) { if (g == 0) continue; if (x % g == 0 && F.count(x / g)) { return make_pair(g, x / g); } } return make_pair(-1, -1); } int main() { ll K, L, M, N, S, T; cin >> K >> L >> M >> N >> S; vector<ll> A(K), B(L), C(M), D(N); vector<ll> U(K * L), V(M * N); vector<ll> U_pos(0), U_neg(0); vector<ll> V_pos(0), V_neg(0); ll U_positive, U_zero, U_negative; ll V_positive, V_zero, V_negative; ll E_positive, E_zero, E_negative; ll A_abs_max, B_abs_max, C_abs_max, D_abs_max; ll E_abs_max; input(A); input(B); input(C); input(D); A_abs_max = abs_max(A); B_abs_max = abs_max(B); C_abs_max = abs_max(C); D_abs_max = abs_max(D); E_abs_max = A_abs_max * B_abs_max * C_abs_max * D_abs_max; int t; t = 0; for (int w = 0; w < K; w++) { for (int x = 0; x < L; x++) { U.at(t++) = A.at(w) * B.at(x); } } t = 0; for (int y = 0; y < M; y++) { for (int z = 0; z < N; z++) { V.at(t++) = C.at(y) * D.at(z); } } sort(V.begin(), V.end()); for (auto u : U) { if (u > 0) { U_pos.push_back(u); } else if (u < 0) { U_neg.push_back(u); } } for (auto v : V) { if (v > 0) { V_pos.push_back(v); } else if (v < 0) { V_neg.push_back(v); } } sort(U_pos.begin(), U_pos.end()); sort(U_neg.begin(), U_neg.end()); sort(V_pos.begin(), V_pos.end()); sort(V_neg.begin(), V_neg.end()); U_positive = U_pos.size(); U_negative = U_neg.size(); U_zero = K * L - (U_positive + U_negative); V_positive = V_pos.size(); V_negative = V_neg.size(); V_zero = M * N - (V_positive + V_negative); E_positive = U_positive * V_positive + U_negative * V_negative; E_negative = U_positive * V_negative + U_negative * V_positive; E_zero = K * L * M * N - (E_positive + E_negative); ll Left, Right, Z, I; if (S <= E_negative) { Left = -(E_abs_max + 1); Right = 1; while (Right - Left > 1) { T = Left + (Right - Left) / 2; Z = I = 0; for (auto u : U_pos) { while (I < V_negative && u * V_neg.at(I) <= T) I++; Z += I; } I = 0; for (auto v : V_pos) { while (I < U_negative && v * U_neg.at(I) <= T) I++; Z += I; } if (Z >= S) { Right = T; } else { Left = T; } } T = Right; } else if (E_negative + 1 <= S && S <= E_negative + E_zero) { T = 0; } else { Left = 0; Right = (E_abs_max + 1) + 1; while (Right - Left > 1) { T = Left + (Right - Left) / 2; Z = 0; I = V_positive; for (auto u : U_pos) { while (I>0 && u * V_pos.at(I-1) > T) I--; Z += I; } I = 0; for (auto v : V_neg) { while (I < U_negative && v * U_neg.at(U_negative-(I+1)) <= T) I++; Z += I; } if (Z >= S - (E_negative + E_zero)) { Right = T; } else { Left = T; } } T = Right; } ll alpha, beta, a, b, c, d; pair<ll, ll> P; P = h(T, U, V); alpha = P.first; beta = P.second; P = h(alpha, A, B); a = P.first; b = P.second; P = h(beta, C, D); c = P.first; d = P.second; cout << T << endl; cout << a << " " << b << " " << c << " " << d << endl; }