結果

問題 No.33 アメーバがたくさん
ユーザー ttkkggwwttkkggww
提出日時 2022-03-22 17:34:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 987 bytes
コンパイル時間 4,792 ms
コンパイル使用メモリ 269,008 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 16:23:21
合計ジャッジ時間 5,105 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
ll n,d,t;
vector<ll> x;
using P = pair<ll,ll>;

void solve(){
	map<ll,vector<P>> mp;
	sort(x.begin(),x.end());
	for(ll i = 0;i<n;i++){
		mp[(x[i]%d+d)%d].push_back(P(x[i],x[i]+1));
	}
	vector<vector<P>> vvp;
	for(auto &i:mp){
		vvp.push_back(i.second);
	}
	for(auto &i:vvp){
		for(auto &[l,r]:i){
			l -= d*t;
			r += d*t;
		}
	}
	for(auto &i:vvp){
		vector<P> add;
		for(auto &j:i){
			if(add.empty()){
				add.push_back(j);
			}else{
				//cout<<add.back().second<<' '<<j.first<<endl;
				if(add.back().second >= j.first){
					add.back().second = j.second;
				}else{
					add.push_back(j);
				}
			}
		}
		i = add;
	}
	ll ans = 0;
	for(auto &i:vvp){
		for(auto &[l,r]:i){
			ans += (r-l+d-1)/d;
		}
	}
	cout<<ans<<endl;

	
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> d >> t;
	x = vector<ll>(n);
	for(auto &i:x)cin >> i;
	solve();
}
0