結果

問題 No.202 1円玉投げ
ユーザー TatamoTatamo
提出日時 2016-10-04 19:04:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,556 ms / 5,000 ms
コード長 1,736 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 66,872 KB
実行使用メモリ 8,852 KB
最終ジャッジ日時 2023-08-23 23:29:30
合計ジャッジ時間 12,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 447 ms
8,692 KB
testcase_01 AC 183 ms
8,700 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 318 ms
7,044 KB
testcase_07 AC 384 ms
7,484 KB
testcase_08 AC 393 ms
7,444 KB
testcase_09 AC 138 ms
5,716 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 98 ms
5,220 KB
testcase_12 AC 104 ms
5,332 KB
testcase_13 AC 41 ms
4,428 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 129 ms
5,732 KB
testcase_16 AC 128 ms
8,624 KB
testcase_17 AC 1,100 ms
8,576 KB
testcase_18 AC 1,091 ms
8,692 KB
testcase_19 AC 113 ms
5,468 KB
testcase_20 AC 254 ms
6,672 KB
testcase_21 AC 114 ms
5,680 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 8 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 8 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 5 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1,542 ms
8,728 KB
testcase_36 AC 188 ms
8,852 KB
testcase_37 AC 430 ms
7,856 KB
testcase_38 AC 1,556 ms
8,528 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<utility>
#include<vector>
#include<set>

using namespace std;
#define cerr cerr << "[DBG] "  
#define DBG(x) cerr << #x << ": " << x << endl
// http://genkisugimoto.com/jp/blog/procon/2015/04/15/print-debug-technique-in-cpp.html
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; }

typedef long long ll;

struct Coin{
	int x;
	int y;
};

// for set
bool operator<(const Coin &a, const Coin &b){
	if(a.x==b.x){
		return a.y < b.y;
	}
	return a.x < b.x;
}

typedef set<Coin>::iterator CSItr;

// yukicoder problems/476 No.202
int main(){
	int n;
	cin >> n;
	vector<Coin> coins(n);
	for(int i=0; i<n; i++){
		Coin c;
		cin >> c.x >> c.y;
		coins[i] = c;
	}
	set<Coin> field;
	for(int i=0; i<n; i++){
		//DBG(i);
		int cx = coins[i].x;
		int cy = coins[i].y;
		if(field.empty()){
			field.insert(coins[i]);
		}
		else{
			Coin low, up;
			low.x = cx-20;
			low.y = cy;
			up.x = cx+20;
			up.y = cy;
			//cerr << "low: " << low.x << "," << low.y << endl;
			CSItr begin = field.lower_bound(low);
			CSItr end = field.upper_bound(up);
			bool flg_collided = false; // true : not collided
			for(CSItr itr = begin; itr!=end; itr++){
				ll dx = cx - itr->x;
				ll dy = cy - itr->y;
				//DBG(dx);
				//DBG(dy);
				if(dx*dx + dy*dy < 20*20){
					DBG(dx*dx+dy*dy);
					flg_collided = true;
					break;
				}
			}
			//DBG(flg_collided);
			if(!flg_collided) {
				field.insert(coins[i]);
			}
		}
	}
	cout << field.size() << endl;

	return 0;
}
0