結果

問題 No.33 アメーバがたくさん
ユーザー furafura
提出日時 2020-01-30 02:23:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 749 bytes
コンパイル時間 1,876 ms
コンパイル使用メモリ 180,528 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-14 08:03:27
合計ジャッジ時間 2,800 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

template<class T> struct interval{
	T l,r;
	interval():l(T{}),r(T{}){}
	interval(const T& l,const T& r):l(l),r(r){}
	bool operator<(const interval& I)const{ return make_tuple(l,r)<make_tuple(I.l,I.r); }
};

int main(){
	lint n,d,t; cin>>n>>d>>t;
	vector<lint> x(n);
	rep(i,n) cin>>x[i], x[i]+=1e9;

	map<lint,vector<interval<lint>>> S;
	rep(i,n){
		S[x[i]%d].emplace_back(x[i]/d-t,x[i]/d+t);
	}

	lint ans=0;
	for(auto& p:S){
		auto& I=p.second;
		sort(I.begin(),I.end());

		lint pre=-INF;
		for(auto& J:I){
			ans+=max(J.r-max(pre,J.l)+1,0LL);
			pre=max(pre,J.r+1);
		}
	}
	cout<<ans<<'\n';

	return 0;
}
0