結果

問題 No.1084 積の積
ユーザー SSRSSSRS
提出日時 2020-06-19 22:10:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 1,460 ms
コンパイル使用メモリ 168,156 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 14:30:40
合計ジャッジ時間 3,688 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 44 ms
4,380 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 44 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 36 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 25 ms
4,376 KB
testcase_13 AC 51 ms
4,380 KB
testcase_14 AC 19 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 58 ms
4,376 KB
testcase_17 AC 23 ms
4,380 KB
testcase_18 AC 38 ms
4,380 KB
testcase_19 AC 51 ms
4,380 KB
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 20 ms
4,380 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 31 ms
4,376 KB
testcase_24 AC 28 ms
4,376 KB
testcase_25 AC 51 ms
4,380 KB
testcase_26 AC 41 ms
4,380 KB
testcase_27 AC 41 ms
4,376 KB
testcase_28 AC 41 ms
4,376 KB
testcase_29 AC 41 ms
4,376 KB
testcase_30 AC 41 ms
4,376 KB
testcase_31 AC 41 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1000000000;
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  bool zero = false;
  for (int i = 0; i < N; i++){
    if (A[i] == 0){
      zero = true;
    }
  }
  if (zero){
    cout << 0 << endl;
  } else {
    int R = 0;
    long long ans = 1;
    long long curr = 1;
    long long tmp = 1;
    for (int L = 0; L < N; L++){
      while (1){
        if (R == N){
          break;
        }
        if (curr * A[R] >= INF){
          break;
        }
        curr *= A[R];
        R++;
        tmp *= curr;
        tmp %= MOD;
      }
      ans *= tmp;
      ans %= MOD;
      curr /= A[L];
      tmp *= modpow(modinv(A[L]), R - L);
      tmp %= MOD;
    }
    cout << ans << endl;
  }
}
0