結果

問題 No.2709 1975 Powers
コンテスト
ユーザー tnakao0123
提出日時 2024-04-30 10:16:24
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,247 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 303 ms
コンパイル使用メモリ 58,416 KB
実行使用メモリ 75,136 KB
最終ジャッジ日時 2026-07-04 15:55:57
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2709.cc:  No.2709 1975 Powers - yukicoder
 */

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

/* constant */

const int MAX_N = 200;
const int K = 4;
const int MAX_P = 100000;
const int ds[K] = { 10, 9, 7, 5 };

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], es[MAX_N][K], cs[MAX_N + 1][MAX_P];

/* subroutines */

int powmod(int a, int b, int mod) {
  int p = 1;
  while (b > 0) {
    if (b & 1) p = (ll)p * a % mod;
    a = (ll)a * a % mod;
    b >>= 1;
  }
  return p;
}

/* main */

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

  for (int i = 0; i < n; i++)
    for (int j = 0; j < K; j++) es[i][j] = powmod(ds[j], as[i], p);

  for (int i = n - 1; i >= 0; i--) {
    copy(cs[i + 1], cs[i + 1] + p, cs[i]);
    cs[i][es[i][3]]++;
  }

  ll sum = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (as[i] < as[j])
	for (int k = j + 1; k < n; k++)
	  if (as[j] < as[k]) {
	    int l = upper_bound(as, as + n, as[k]) - as;
	    int x = (q + p - (es[i][0] + es[j][1] + es[k][2]) % p) % p;
	    sum += cs[l][x];
	  }

  printf("%lld\n", sum);
  
  return 0;
}
0