結果

問題 No.2008 Super Worker
ユーザー tnakao0123tnakao0123
提出日時 2022-07-18 22:51:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,785 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 45,732 KB
実行使用メモリ 7,700 KB
最終ジャッジ日時 2023-09-13 13:47:32
合計ジャッジ時間 4,411 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,028 KB
testcase_01 AC 2 ms
5,052 KB
testcase_02 AC 2 ms
4,976 KB
testcase_03 AC 2 ms
5,052 KB
testcase_04 AC 2 ms
5,008 KB
testcase_05 AC 2 ms
5,016 KB
testcase_06 AC 2 ms
4,972 KB
testcase_07 AC 2 ms
4,996 KB
testcase_08 AC 1 ms
5,048 KB
testcase_09 AC 2 ms
5,024 KB
testcase_10 AC 2 ms
5,024 KB
testcase_11 AC 2 ms
5,020 KB
testcase_12 AC 2 ms
5,028 KB
testcase_13 AC 2 ms
5,020 KB
testcase_14 AC 2 ms
4,996 KB
testcase_15 AC 2 ms
5,020 KB
testcase_16 AC 2 ms
5,088 KB
testcase_17 AC 2 ms
5,116 KB
testcase_18 AC 2 ms
5,036 KB
testcase_19 AC 2 ms
5,040 KB
testcase_20 AC 2 ms
5,048 KB
testcase_21 AC 2 ms
5,020 KB
testcase_22 AC 2 ms
5,016 KB
testcase_23 AC 60 ms
7,644 KB
testcase_24 AC 59 ms
7,660 KB
testcase_25 AC 60 ms
7,656 KB
testcase_26 AC 60 ms
7,684 KB
testcase_27 AC 61 ms
7,660 KB
testcase_28 AC 67 ms
7,628 KB
testcase_29 AC 67 ms
7,632 KB
testcase_30 AC 67 ms
7,632 KB
testcase_31 AC 67 ms
7,696 KB
testcase_32 AC 68 ms
7,632 KB
testcase_33 AC 56 ms
7,700 KB
testcase_34 AC 68 ms
7,644 KB
testcase_35 AC 56 ms
7,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2008.cc:  No.2008 Super Worker - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 1000000007;

/* typedef */

/* typedef */

struct Elm {
  double d;
  int a, b;
  Elm() {}
  Elm(int _a, int _b): d((double)(_b - 1) / _a), a(_a), b(_b) {}

  bool operator<(const Elm &e) const {
    return d > e.d || (d == e.d && a < e.a);
  }
};

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

typedef MI<MOD> mi;

/* global variables */

int as[MAX_N], bs[MAX_N];
Elm es[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++) scanf("%d", bs + i);

  for (int i = 0; i < n; i++) es[i] = Elm(as[i], bs[i]);
  sort(es, es + n);

  mi x = 1, sum = 0;
  for (int i = 0; i < n; i++) {
    int ai = es[i].a, bi = es[i].b;
    sum += x * ai;
    x *= bi;
  }

  printf("%d\n", sum.v);  
  return 0;
}
0