結果

問題 No.202 1円玉投げ
ユーザー hirokazu1020hirokazu1020
提出日時 2015-05-15 16:52:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 237 ms / 5,000 ms
コード長 3,530 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 78,000 KB
実行使用メモリ 37,964 KB
最終ジャッジ日時 2023-08-23 22:52:19
合計ジャッジ時間 4,693 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
11,232 KB
testcase_01 AC 237 ms
37,964 KB
testcase_02 AC 5 ms
8,580 KB
testcase_03 AC 5 ms
8,644 KB
testcase_04 AC 5 ms
8,712 KB
testcase_05 AC 13 ms
10,332 KB
testcase_06 AC 162 ms
28,584 KB
testcase_07 AC 178 ms
30,616 KB
testcase_08 AC 191 ms
30,764 KB
testcase_09 AC 91 ms
22,140 KB
testcase_10 AC 37 ms
14,648 KB
testcase_11 AC 77 ms
20,096 KB
testcase_12 AC 82 ms
20,196 KB
testcase_13 AC 41 ms
15,448 KB
testcase_14 AC 14 ms
10,604 KB
testcase_15 AC 90 ms
21,704 KB
testcase_16 AC 70 ms
13,384 KB
testcase_17 AC 65 ms
11,172 KB
testcase_18 AC 64 ms
11,052 KB
testcase_19 AC 79 ms
21,000 KB
testcase_20 AC 148 ms
27,132 KB
testcase_21 AC 80 ms
20,920 KB
testcase_22 AC 6 ms
8,604 KB
testcase_23 AC 6 ms
8,544 KB
testcase_24 AC 6 ms
8,580 KB
testcase_25 AC 6 ms
8,592 KB
testcase_26 AC 6 ms
8,816 KB
testcase_27 AC 6 ms
8,852 KB
testcase_28 AC 6 ms
8,600 KB
testcase_29 AC 6 ms
8,576 KB
testcase_30 AC 6 ms
9,096 KB
testcase_31 AC 5 ms
8,556 KB
testcase_32 AC 6 ms
8,812 KB
testcase_33 AC 6 ms
8,628 KB
testcase_34 AC 6 ms
8,808 KB
testcase_35 AC 67 ms
10,972 KB
testcase_36 AC 67 ms
11,056 KB
testcase_37 AC 199 ms
31,936 KB
testcase_38 AC 72 ms
11,284 KB
testcase_39 AC 6 ms
8,536 KB
testcase_40 AC 5 ms
8,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


int highest_pop(unsigned int b){
#ifdef __GNUC__
	return 31-__builtin_clz(b);
#else 
	int res=0;
	for(int i=4;i>=0;i--){
		int shift=1<<i;
		if(b>>shift){
			b>>=shift;
			res|=shift;
		}
	}
	return res;
#endif
}

template<int U=30> 
class Set{
	unsigned int summary;
	Set<U-5> *ch[1<<5];
	static int low_bits(unsigned int a){
		return a&((1<<U-5)-1);
	}
	static int high_bits(unsigned int a){
		return a>>(U-5);
	}
	static int index(unsigned int high,unsigned int low){
		return high<<U-5|low;
	}
public:
	Set():summary(0){
		for(int i=0;i<(1<<5);i++)ch[i]=NULL;
	}
	~Set(){clear();}
	void clear(){
		summary=0;
		for(int i=0;i<(1<<5);i++){
			if(ch[i])delete ch[i];
			ch[i]=NULL;
		}
	}
	void insert(int v){
		int high=high_bits(v);
		summary|=1<<high;
		if(!ch[high])ch[high]=new Set<U-5>();
		ch[high]->insert(low_bits(v));
	}
	bool erase(int v){
		int high=high_bits(v);
		if(!ch[high])return true;
		if(!ch[high]->erase(low_bits(v))){
			delete ch[high];
			ch[high]=NULL;			
			return summary&=~(1<<high);
		}
		return true;
	}
	int nextvalue(int v)const{
		int high=high_bits(v);
		int low=low_bits(v);
		int a;
		if(ch[high] && (a=ch[high]->nextvalue(low))!=-1){
			return index(high,a);
		}else{
			high=summary&~((1<<high)-1)&~(1<<high);
			if(!high)return -1;
			high=highest_pop(high&-high);
			return index(high,ch[high]->min());
		}
	}
	int prevvalue(int v)const{
		int high=high_bits(v);
		int low=low_bits(v);
		int a;
		if(ch[high] && (a=ch[high]->prevvalue(low))!=-1){
			return index(high,a);
		}else{
			high=summary&((1<<high)-1);
			if(!high)return -1;
			high=highest_pop(high);
			return index(high,ch[high]->max());
		}
	}
	int min()const{
		if(!summary)return -1;
		int high=highest_pop(summary&-summary);
		return index(high,ch[high]->min());
	}
	int max()const{
		if(!summary)return -1;
		int high=highest_pop(summary);
		return index(high,ch[high]->max());
	}
	bool member(int v)const{
		int high=high_bits(v);
		return ch[high] && ch[high]->member(low_bits(v));
	}
};


template<> 
class Set<5>{
	unsigned int summary;
public:
	Set():summary(0){}
	void clear(){summary=0;}
	void insert(int v){
		summary|=1<<v;
	}
	bool erase(int v){
		return summary&=~(1<<v);
	}
	int nextvalue(int v)const{
		int a=summary&~((1<<v)-1)&~(1<<v);
		if(!a)return -1;
		return highest_pop(a&-a);
	}
	int prevvalue(int v)const{
		int a=summary&((1<<v)-1);
		if(!a)return -1;
		return highest_pop(a);
	}
	int min()const{
		if(!summary)return -1;
		return highest_pop(summary&-summary);
	}
	int max()const{
		if(!summary)return -1;
		return highest_pop(summary);
	}
	bool member(int v)const{
		return summary>>v&1;
	}
};




Set<15> xset[20021];


int main(){
	int n,ans=0;
	cin>>n;
	rep(i,n){
		bool hit=false;
		int x,y;
		cin>>x>>y;
		for(int a=max(0,y-20);!hit&&a<y+20;a++){
			int b;
			b=xset[a].prevvalue(x+21);
			if(b!=-1&&x-20<=b){
				if((a-y)*(a-y)+(b-x)*(b-x)<20*20)hit=true;
				b=xset[a].prevvalue(b);
				if(b!=-1&&(a-y)*(a-y)+(b-x)*(b-x)<20*20)hit=true;
			}
		}
		if(!hit){
			xset[y].insert(x);
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}
0