結果

問題 No.2260 Adic Sum
ユーザー kotatsugamekotatsugame
提出日時 2023-04-07 21:30:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 14,336 KB
最終ジャッジ日時 2024-04-15 23:42:41
合計ジャッジ時間 3,543 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 37 ms
8,064 KB
testcase_15 AC 53 ms
9,596 KB
testcase_16 AC 32 ms
7,296 KB
testcase_17 AC 61 ms
10,080 KB
testcase_18 AC 71 ms
5,376 KB
testcase_19 AC 76 ms
5,376 KB
testcase_20 AC 66 ms
5,376 KB
testcase_21 AC 67 ms
5,376 KB
testcase_22 AC 61 ms
5,376 KB
testcase_23 AC 59 ms
5,376 KB
testcase_24 AC 76 ms
5,376 KB
testcase_25 AC 102 ms
13,696 KB
testcase_26 AC 98 ms
13,696 KB
testcase_27 AC 108 ms
14,336 KB
testcase_28 AC 105 ms
13,824 KB
testcase_29 AC 103 ms
13,824 KB
testcase_30 AC 59 ms
5,760 KB
testcase_31 AC 80 ms
9,656 KB
testcase_32 AC 82 ms
9,624 KB
testcase_33 AC 53 ms
5,376 KB
testcase_34 AC 48 ms
5,376 KB
testcase_35 AC 102 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
using namespace std;
int P;
long ans;
void solve(const vector<int>&A)
{
	if(A.size()<=1)return;
	if(A.size()<=30)
	{
		for(int i=0;i<A.size();i++)for(int j=i+1;j<A.size();j++)
		{
			int d=abs(A[i]-A[j]);
			while(d%P==0)d/=P,ans++;
		}
		return;
	}
	map<int,vector<int> >mp;
	for(int i=0;i<A.size();i++)mp[A[i]%P].push_back(A[i]/P);
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		int n=it->second.size();
		ans+=(long)n*(n-1)/2;
		solve(it->second);
	}
}
int main()
{
	int N;cin>>N>>P;
	vector<int>A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	solve(A);
	cout<<ans<<endl;
}
0