結果

問題 No.2709 1975 Powers
ユーザー a1048576
提出日時 2024-04-07 13:02:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 176,400 KB
実行使用メモリ 208,740 KB
最終ジャッジ日時 2024-10-01 04:27:09
合計ジャッジ時間 7,979 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n,mod,f;
  cin >> n >> mod >> f;
  vector<int> a(n);
  vector<int> p(2e6+1,1), q(2e6+1,1), r(2e6+1,1), s(2e6+1,1);
  for(int i = 0; i < 2e6; i++) {
    p[i+1] = p[i]*10%mod;
    q[i+1] = q[i]*9%mod;
    r[i+1] = r[i]*7%mod;
    s[i+1] = s[i]*5%mod;
  }
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(),a.end());
  vector<vector<int>> g(n+1,vector<int>(mod,0));
  for(int i = n-1; i >= 0; i--) {
    g[i][s[a[i]]]++;
    for(int j = 0; j < mod; j++) g[i][j]+=g[i+1][j];
  }
  int ans = 0;
  for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) for(int k = j+1; k < n; k++) {
    int x = (f-p[a[i]]-q[a[j]]-r[a[k]]+mod*mod)%mod;
    ans+=g[k+1][x];
  }
  cout << ans << endl;
}
0