結果

問題 No.2709 1975 Powers
ユーザー BBhorseBBhorse
提出日時 2024-03-31 14:50:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 179,696 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-31 14:50:42
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 5 ms
6,548 KB
testcase_03 AC 102 ms
6,548 KB
testcase_04 AC 161 ms
6,548 KB
testcase_05 AC 94 ms
6,548 KB
testcase_06 AC 48 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 44 ms
6,548 KB
testcase_09 AC 115 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 8 ms
6,548 KB
testcase_12 AC 15 ms
6,548 KB
testcase_13 AC 120 ms
6,548 KB
testcase_14 AC 26 ms
6,548 KB
testcase_15 AC 28 ms
6,548 KB
testcase_16 AC 97 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 20 ms
6,548 KB
testcase_19 AC 159 ms
6,548 KB
testcase_20 AC 4 ms
6,548 KB
testcase_21 AC 42 ms
6,548 KB
testcase_22 AC 183 ms
6,548 KB
testcase_23 AC 180 ms
6,548 KB
testcase_24 AC 187 ms
6,548 KB
testcase_25 AC 183 ms
6,548 KB
testcase_26 AC 184 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll=long long;
#define rep(i,s,n) for (ll i = (s); i < (n); i++)
using namespace std;
using Graph = vector<vector<ll>>;
ll MOD=998244353;
const ll INF=1e18;

ll mod;

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1) res=(res*a)%mod;
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

int main(){
  ll N,P,Q;
  cin>>N>>P>>Q;
  mod=P;
  vector<ll> A(N);
  rep(i,0,N){
    cin>>A[i];
  }
  vector<vector<ll>> L(3,vector<ll> (N));
  vector<pair<ll,ll>> X(N);
  rep(i,0,N){
    L[0][i]=modpow(10,A[i]);
  }
  rep(i,0,N){
    L[1][i]=modpow(9,A[i]);
  }
  rep(i,0,N){
    L[2][i]=modpow(7,A[i]);
  }
  rep(i,0,N){
    X[i]={modpow(5,A[i]),i};
  }
  sort(X.begin(), X.end());

  ll ans=0;

  rep(i,0,N){
    rep(j,0,N){
      rep(k,0,N){
        if(!(A[i]<A[j]&&A[j]<A[k])) continue;
        ll s=L[0][i]+L[1][j]+L[2][k];
        s%=mod;
        ll a=(Q+mod-s)%mod;
        ll l=distance(X.begin(), lower_bound(X.begin(), X.end(), make_pair(a,(ll)0)));
        ll r=distance(X.begin(), lower_bound(X.begin(), X.end(), make_pair(a+1,(ll)0)));
        //cout<<a<<endl;
        if(X[l].first==a){
          rep(x,l,r){
            if(A[k]<A[X[x].second]){
              ans++;
              //cout<<i<<j<<k<<X[x].first<<X[x].second<<endl;
            }
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
}
0