結果

問題 No.33 アメーバがたくさん
ユーザー cielciel
提出日時 2015-10-29 03:42:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,105 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 69,968 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:55:06
合計ジャッジ時間 1,044 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |         scanf("%lld%lld%lld",&n,&d,&t);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:43:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |                 scanf("%lld",&x);
      |                 ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <unordered_map>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<long long,long long> pll;

long long checkio(const vector<pll> &v){
	long long result=0;
	long long l,r;
	set<pll> se;
	for(auto &e:v){
		l=e.first,r=e.second;
		auto right=se.lower_bound(make_pair(l,0LL)); //p.first <= right.first
		if(right!=se.begin()){
			--right;
			auto left=right;
			++right;
			if(l<=left->second+1){ // overlap with left
				l=left->first;
				r=max(r,left->second);
				result-=left->second-left->first+1;
				se.erase(left);
			}
		}
		while(right!=se.end() && right->first<=r){ // overlap with right
			r=max(r,right->second);
			result-=right->second-right->first+1;
			se.erase(right++);
		}
		result+=r-l+1;
		se.insert(make_pair(l,r));
	}
	return result;
}

int main(){
	unordered_map<long long,vector<pll>> dic;
	long long n,d,t,x,m;
	scanf("%lld%lld%lld",&n,&d,&t);
	for(int i=0;i<n;i++){
		scanf("%lld",&x);
		m=(x%d+d)%d;
		dic[m].emplace_back((x-m)/d-t,(x-m)/d+t);
	}
	x=0;
	for(auto &e:dic)x+=checkio(e.second);
	printf("%lld\n",x);
}
0