結果

問題 No.33 アメーバがたくさん
ユーザー cielciel
提出日時 2015-10-29 02:57:25
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,265 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 65,444 KB
最終ジャッジ日時 2023-10-24 17:54:57
合計ジャッジ時間 754 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:8:25: error: ‘vector’ does not name a type
    8 | long long checkio(const vector<pll> &v){
      |                         ^~~~~~
main.cpp:8:31: error: expected ‘,’ or ‘...’ before ‘<’ token
    8 | long long checkio(const vector<pll> &v){
      |                               ^
main.cpp: In function ‘long long int checkio(int)’:
main.cpp:12:21: error: ‘v’ was not declared in this scope
   12 |         for(auto &e:v){
      |                     ^
main.cpp: In function ‘int main()’:
main.cpp:38:33: error: ‘vector’ was not declared in this scope
   38 |         unordered_map<long long,vector<pll>> dic;
      |                                 ^~~~~~
main.cpp:5:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    4 | #include <algorithm>
  +++ |+#include <vector>
    5 | using namespace std;
main.cpp:38:40: error: template argument 2 is invalid
   38 |         unordered_map<long long,vector<pll>> dic;
      |                                        ^~~
main.cpp:38:40: error: template argument 5 is invalid
main.cpp:38:43: error: expected unqualified-id before ‘>’ token
   38 |         unordered_map<long long,vector<pll>> dic;
      |                                           ^~
main.cpp:44:17: error: ‘dic’ was not declared in this scope; did you mean ‘div’?
   44 |                 dic[m].emplace_back((x-m)/d-t,(x-m)/d+t);
      |                 ^~~
      |                 div
main.cpp:47:21: error: ‘dic’ was not declared in this scope; did you mean ‘div’?
   47 |         for(auto &e:dic)x+=checkio(e.second);
      |                     ^~~
      |                     div
main.cpp:40:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |         scanf("%lld%lld%lld",&n,&d,&t);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:42:22: warning: ignoring return

ソースコード

diff #

#include <iostream>
#include <unordered_map>
#include <deque>
#include <algorithm>
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;
	deque<pll> se;
	for(auto &e:v){
		l=e.first,r=e.second;
		auto right=lower_bound(se.begin(),se.end(),make_pair(l,0LL)); //l <= se[right_idx].first
		size_t right_idx=right-se.begin();
		if(right_idx!=0){
			size_t left_idx=right_idx-1;
			if(l<=se[left_idx].second+1){ // overlap with left
				l=se[left_idx].first;
				r=max(r,se[left_idx].second);
				result-=se[left_idx].second-se[left_idx].first+1;
				se.erase(se.begin()+left_idx);
				right_idx--;
			}
		}
		while(right_idx<se.size() && se[right_idx].first<=r){ // overlap with right
			r=max(r,se[right_idx].second);
			result-=se[right_idx].second-se[right_idx].first+1;
			se.erase(se.begin()+right_idx);
		}
		result+=r-l+1;
		se.insert(se.begin()+right_idx,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