結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー SSRSSSRS
提出日時 2021-01-22 22:54:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 3,914 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 178,268 KB
実行使用メモリ 18,140 KB
最終ジャッジ日時 2024-06-08 17:01:43
合計ジャッジ時間 11,613 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 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 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 12 ms
5,376 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 13 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 AC 14 ms
5,376 KB
testcase_24 AC 14 ms
5,376 KB
testcase_25 AC 13 ms
5,376 KB
testcase_26 AC 14 ms
5,376 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 106 ms
9,144 KB
testcase_29 AC 89 ms
7,344 KB
testcase_30 AC 74 ms
6,916 KB
testcase_31 AC 87 ms
9,192 KB
testcase_32 AC 114 ms
11,112 KB
testcase_33 AC 70 ms
6,940 KB
testcase_34 AC 107 ms
9,956 KB
testcase_35 AC 134 ms
9,956 KB
testcase_36 AC 192 ms
12,948 KB
testcase_37 AC 48 ms
6,240 KB
testcase_38 AC 101 ms
7,780 KB
testcase_39 AC 65 ms
6,388 KB
testcase_40 AC 78 ms
7,352 KB
testcase_41 AC 126 ms
8,504 KB
testcase_42 AC 172 ms
12,004 KB
testcase_43 AC 116 ms
9,320 KB
testcase_44 AC 142 ms
10,272 KB
testcase_45 AC 98 ms
8,452 KB
testcase_46 AC 93 ms
10,744 KB
testcase_47 AC 67 ms
6,724 KB
testcase_48 AC 192 ms
18,004 KB
testcase_49 AC 141 ms
17,876 KB
testcase_50 AC 203 ms
17,808 KB
testcase_51 AC 175 ms
17,880 KB
testcase_52 AC 145 ms
17,880 KB
testcase_53 AC 284 ms
17,120 KB
testcase_54 AC 277 ms
17,120 KB
testcase_55 AC 270 ms
16,996 KB
testcase_56 AC 241 ms
17,116 KB
testcase_57 AC 147 ms
16,992 KB
testcase_58 AC 58 ms
16,996 KB
testcase_59 AC 57 ms
16,992 KB
testcase_60 AC 60 ms
16,988 KB
testcase_61 AC 60 ms
17,116 KB
testcase_62 AC 60 ms
17,116 KB
testcase_63 AC 60 ms
17,880 KB
testcase_64 AC 60 ms
17,884 KB
testcase_65 AC 58 ms
17,752 KB
testcase_66 AC 60 ms
18,140 KB
testcase_67 AC 60 ms
17,880 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 1 ms
5,376 KB
testcase_72 AC 2 ms
5,376 KB
testcase_73 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000;
int main(){
  int K, L, M, N;
  long long S;
  cin >> K >> L >> M >> N >> S;
  vector<int> A(K);
  for (int i = 0; i < K; i++){
    cin >> A[i];
  }
  vector<int> B(L);
  for (int i = 0; i < L; i++){
    cin >> B[i];
  }
  vector<int> C(M);
  for (int i = 0; i < M; i++){
    cin >> C[i];
  }
  vector<int> D(N);
  for (int i = 0; i < N; i++){
    cin >> D[i];
  }
  vector<long long> X(K * L);
  for (int i = 0; i < K; i++){
    for (int j = 0; j < L; j++){
      X[i * L + j] = A[i] * B[j];
    }
  }
  vector<long long> Y(M * N);
  for (int i = 0; i < M; i++){
    for (int j = 0; j < N; j++){
      Y[i * N + j] = C[i] * D[j];
    }
  }
  vector<long long> Xp, Xn;
  for (int i = 0; i < K * L; i++){
    if (X[i] >= 0){
      Xp.push_back(X[i]);
    } else {
      Xn.push_back(-X[i]);
    }
  }
  vector<long long> Yp, Yn;
  for (int i = 0; i < N * M; i++){
    if (Y[i] >= 0){
      Yp.push_back(Y[i]);
    } else {
      Yn.push_back(-Y[i]);
    }
  }
  sort(Xp.begin(), Xp.end());
  sort(Xn.begin(), Xn.end());
  sort(Yp.begin(), Yp.end());
  sort(Yn.begin(), Yn.end());
  int Xps = Xp.size();
  int Xns = Xn.size();
  int Yps = Yp.size();
  int Yns = Yn.size();
  long long tv = -INF;
  long long fv = INF;
  while (fv - tv > 1){
    long long mid = (tv + fv) / 2;
    long long cnt = 0;
    if (mid >= 0){
      cnt += (long long) Xps * Yns;
      cnt += (long long) Xns * Yps;
      int p1 = 0;
      for (int i = Xps - 1; i >= 0; i--){
        while (p1 < Yps){
          if (Xp[i] * Yp[p1] < mid){
            p1++;
          } else {
            break;
          }
        }
        cnt += p1;
      }
      int p2 = 0;
      for (int i = Xns - 1; i >= 0; i--){
        while (p2 < Yns){
          if (Xn[i] * Yn[p2] < mid){
            p2++;
          } else {
            break;
          }
        }
        cnt += p2;
      }
    } else {
      int p1 = 0;
      for (int i = Xps - 1; i >= 0; i--){
        while (p1 < Yns){
          if (Xp[i] * Yn[p1] <= -mid){
            p1++;
          } else {
            break;
          }
        }
        cnt += Yns - p1;
      }
      int p2 = 0;
      for (int i = Xns - 1; i >= 0; i--){
        while (p2 < Yps){
          if (Xn[i] * Yp[p2] <= -mid){
            p2++;
          } else {
            break;
          }
        }
        cnt += Yps - p2;
      }
    }
    if (cnt < S){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
  sort(Y.begin(), Y.end());
  for (int i = 0; i < K * L; i++){
    int id = -1;
    if (X[i] >= 0){
      int tv2 = -1;
      int fv2 = N * M;
      while (fv2 - tv2 > 1){
        int mid2 = (tv2 + fv2) / 2;
        if (X[i] * Y[mid2] <= tv){
          tv2 = mid2;
        } else {
          fv2 = mid2;
        }
      }
      if (tv2 != -1){
        if (X[i] * Y[tv2] == tv){
          id = tv2;
        }
      }
    } else {
      int tv2 = N * M;
      int fv2 = -1;
      while (tv2 - fv2 > 1){
        int mid2 = (tv2 + fv2) / 2;
        if (X[i] * Y[mid2] <= tv){
          tv2 = mid2;
        } else {
          fv2 = mid2;
        }
      }
      if (tv2 != N * M){
        if (X[i] * Y[tv2] == tv){
          id = tv2;
        }
      }
    }
    if (id != -1){
      bool ok1 = false;
      for (int j = 0; j < K; j++){
        for (int k = 0; k < L; k++){
          if (A[j] * B[k] == X[i]){
            cout << A[j] << ' ' << B[k] << ' ';
            ok1 = true;
            break;
          }
        }
        if (ok1){
          break;
        }
      }
      bool ok2 = false;
      for (int j = 0; j < M; j++){
        for (int k = 0; k < N; k++){
          if (C[j] * D[k] == Y[id]){
            cout << C[j] << ' ' << D[k] << endl;
            ok2 = true;
            break;
          }
        }
        if (ok2){
          break;
        }
      }
      break;
    }
  }
}
0