結果

問題 No.2709 1975 Powers
ユーザー tnakao0123
提出日時 2024-04-30 10:16:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 44,668 KB
最終ジャッジ日時 2025-02-21 09:51:40
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |   scanf("%d%d%d", &n, &p, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:43:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |   for (int i = 0; i < n; i++) scanf("%d", as + i);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

/* -*- 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