結果

問題 No.1084 積の積
ユーザー tonegawatonegawa
提出日時 2020-08-12 16:26:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,859 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 121,296 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 00:43:34
合計ジャッジ時間 2,981 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 66 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 41 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 14 ms
6,940 KB
testcase_13 AC 27 ms
6,940 KB
testcase_14 AC 11 ms
6,944 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 29 ms
6,944 KB
testcase_17 AC 13 ms
6,940 KB
testcase_18 AC 21 ms
6,940 KB
testcase_19 AC 26 ms
6,940 KB
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 11 ms
6,940 KB
testcase_22 AC 8 ms
6,944 KB
testcase_23 AC 16 ms
6,944 KB
testcase_24 AC 15 ms
6,940 KB
testcase_25 AC 27 ms
6,940 KB
testcase_26 AC 38 ms
6,944 KB
testcase_27 AC 37 ms
6,944 KB
testcase_28 AC 37 ms
6,940 KB
testcase_29 AC 37 ms
6,940 KB
testcase_30 AC 36 ms
6,940 KB
testcase_31 AC 37 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll mpow(ll a, ll b, ll p = -1){
  ll ret = 1, num = a;
  if(b==0) return 1;
  if(p==-1){
    while(b>0){
      if(b%2) ret *= num;
      num = num * num;
      b /= 2;
    }
  }else{
    while(b>0){
      if(b%2) ret = (ret*num)%p;
      num = (num*num)%p;
      b /= 2;
    }
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n);re(i, n) scanf("%lld", &a[i]);

  vll two, zero;
  for(int i=0;i<n;i++){
    if(a[i]>1) two.push_back(i);
    if(a[i]==0) zero.push_back(i);
  }
  two.push_back(n);
  zero.push_back(n);
  ll P = 1000000007;
  ll ans = 1;
  for(int l=0;l<n;l++){
    ll t = 1;
    ll idx = l;
    for(int i=0;i<32;i++){
      auto X = lower_bound(all(two), idx);
      auto Y = lower_bound(all(zero), idx);
      if((*X)==n&&(*Y)==n){//残り全部1
        ll one = n - idx;
        ans = (ans * mpow(t, one, P))%P;
        break;
      }
      if(*Y<*X){//1の連続に0
        ll one = (*Y) - idx;
        ans = (ans * mpow(t, one, P))%P;
        break;
      }else{//1の連続に2以上
        ll one = (*X) - idx;
        ans = (ans * mpow(t, one, P))%P;
        if(t* a[(*X)]>=1000000000) break;
        t *= a[*X];
        ans = (ans * t)%P;
        idx = (*X) + 1;
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}
0