結果

問題 No.2394 部分和乗総和
ユーザー 河城白露河城白露
提出日時 2023-07-28 22:10:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 1,038 ms
コンパイル使用メモリ 83,048 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 06:07:42
合計ジャッジ時間 2,455 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 130 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define ll long long
#define db double
using namespace std;
const ll N = 1e5 + 100;
ll tt,n,m,b,dp[N];
ll ksm(ll p,ll q) {
	ll res = 1;
	while(q) {
		if (q & 1) {
			res *= p;
			res %= b;
		}
		p *= p;
		p %= b;
		q /= 2;
	}
	return res;
}
void solve() {
	scanf("%lld%lld%lld",&n,&m,&b);
	m %= b;
	dp[0] = 0;
	for (ll i = 1;i <= n;i++) {
		dp[i] = (dp[i - 1] + 1) % b;
		ll x;
		scanf("%lld",&x);
		dp[i] *= ksm(m,x);
		dp[i] %= b;
	}
	ll ans = 1;
	for (ll i = 1;i <= n;i++) {
		ans += dp[i];
		ans %= b;
	}
	printf("%lld\n",ans);
}
int main() {
	tt = 1;
	while(tt) {
		solve();
		tt--;
	}
	return 0;
}
0