結果

問題 No.33 アメーバがたくさん
ユーザー data9824data9824
提出日時 2015-06-15 04:03:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,130 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:47:40
合計ジャッジ時間 1,266 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main() {
	int n;
	long long d, t;
	cin >> n >> d >> t;
	vector<long long> x(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	map<long long, set<long long> > positions;
	for (int i = 0; i < n; ++i) {
		positions[(0x80000000LL + x[i]) % d].insert(0x80000000LL + x[i]);
	}
	long long result = 0LL;
	for (map<long long, set<long long> >::const_iterator it = positions.begin();
		it != positions.end();
		++it) {
		vector<pair<long long, long long> > ranges;
		for (set<long long>::const_iterator itSet = it->second.begin();
			itSet != it->second.end();
			++itSet) {
			ranges.push_back(make_pair(*itSet / d - t, *itSet / d + t));
		}
		if (!ranges.empty()) {
			long long lower = ranges.front().first;
			long long upper = ranges.front().second;
			for (size_t i = 1; i < ranges.size(); ++i) {
				if (upper < ranges[i].first) {
					result += upper - lower + 1;
					lower = ranges[i].first;
				}
				upper = ranges[i].second;
			}
			result += upper - lower + 1;
		}
	}
	cout << result << endl;
	return 0;
}
0