AtCoder Regular Contest 037

Submission #1058990

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int n, k;
vll a, b;

pii bs(ll mid) {
  pii ret = {0, 0};
  rep (i, n) {
    bool flag = (mid % a[i] == 0) ? true : false;
    ll r = mid / a[i];
    int ub = upper_bound(all(b), r) - begin(b);
    if (flag) {
      ret.first += lower_bound(all(b), r) - begin(b);
    } else {
      ret.first += ub;
    }
    ret.second += ub;
  }
  return ret;
}

int main() {
  scanf("%d %d", &n, &k);
  a.resize(n);
  b.resize(n);
  rep (i, n) {
    scanf("%lld", &a[i]);
  }
  rep (i, n) {
    scanf("%lld", &b[i]);
  }
  sort(all(a)); sort(all(b));
  ll l = a[0] * b[0] - 1;
  ll h = a[n-1] * b[n-1] + 1;
  ll mid;
  while (true) {
    mid = (l + h)/2;
    pii p = bs(mid);
    if (k <= p.first) {
      h = mid;
      continue;
    } else if (p.second < k) {
      l = mid;
      continue;
    }
    // p.first < k && k <= p.second
    break;
  }
  printf("%lld\n", mid);

  return 0;
}

Submission

Task問題 C - 億マス計算
User nameユーザ名 gosenoku
Created time投稿日時
Language言語 C++14 (Clang++ 3.4)
Status状態 AC
Score得点 100
Source lengthソースコード長 1824 Byte
File nameファイル名
Exec time実行時間 104 ms
Memory usageメモリ使用量 1312 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample_01.txt,subtask0_sample_02.txt,subtask0_sample_03.txt
Subtask1 5 / 5 subtask0_sample_01.txt,subtask0_sample_02.txt,subtask0_sample_03.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt
Subtask2 95 / 95 subtask0_sample_01.txt,subtask0_sample_02.txt,subtask0_sample_03.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt,subtask2_21.txt,subtask2_22.txt,subtask2_23.txt,subtask2_24.txt,subtask2_25.txt,subtask2_26.txt,subtask2_27.txt,subtask2_28.txt,subtask2_29.txt,subtask2_30.txt,subtask2_31.txt,subtask2_32.txt,subtask2_33.txt,subtask2_34.txt,subtask2_35.txt,subtask2_36.txt,subtask2_37.txt,subtask2_38.txt,subtask2_39.txt,subtask2_40.txt,subtask2_41.txt,subtask2_42.txt,subtask2_43.txt,subtask2_44.txt,subtask2_45.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample_01.txt AC 18 ms 792 KB
subtask0_sample_02.txt AC 18 ms 928 KB
subtask0_sample_03.txt AC 17 ms 792 KB
subtask1_01.txt AC 17 ms 924 KB
subtask1_02.txt AC 17 ms 796 KB
subtask1_03.txt AC 17 ms 928 KB
subtask1_04.txt AC 16 ms 800 KB
subtask1_05.txt AC 16 ms 800 KB
subtask1_06.txt AC 17 ms 800 KB
subtask1_07.txt AC 25 ms 856 KB
subtask1_08.txt AC 17 ms 800 KB
subtask1_09.txt AC 17 ms 796 KB
subtask1_10.txt AC 17 ms 924 KB
subtask1_11.txt AC 17 ms 796 KB
subtask1_12.txt AC 17 ms 920 KB
subtask1_13.txt AC 17 ms 796 KB
subtask1_14.txt AC 17 ms 924 KB
subtask1_15.txt AC 17 ms 796 KB
subtask2_16.txt AC 46 ms 920 KB
subtask2_17.txt AC 36 ms 1184 KB
subtask2_18.txt AC 30 ms 1052 KB
subtask2_19.txt AC 29 ms 1052 KB
subtask2_20.txt AC 92 ms 1268 KB
subtask2_21.txt AC 72 ms 1312 KB
subtask2_22.txt AC 67 ms 1312 KB
subtask2_23.txt AC 45 ms 1312 KB
subtask2_24.txt AC 90 ms 1312 KB
subtask2_25.txt AC 100 ms 1300 KB
subtask2_26.txt AC 103 ms 1308 KB
subtask2_27.txt AC 104 ms 1304 KB
subtask2_28.txt AC 75 ms 1184 KB
subtask2_29.txt AC 104 ms 1308 KB
subtask2_30.txt AC 81 ms 1308 KB
subtask2_31.txt AC 29 ms 1308 KB
subtask2_32.txt AC 20 ms 912 KB
subtask2_33.txt AC 30 ms 928 KB
subtask2_34.txt AC 50 ms 1184 KB
subtask2_35.txt AC 55 ms 1312 KB
subtask2_36.txt AC 38 ms 928 KB
subtask2_37.txt AC 33 ms 920 KB
subtask2_38.txt AC 25 ms 800 KB
subtask2_39.txt AC 77 ms 1184 KB
subtask2_40.txt AC 72 ms 1304 KB
subtask2_41.txt AC 71 ms 1304 KB
subtask2_42.txt AC 39 ms 1052 KB
subtask2_43.txt AC 75 ms 1300 KB
subtask2_44.txt AC 77 ms 1312 KB
subtask2_45.txt AC 73 ms 1312 KB