結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-27 19:30:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,128 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 76,184 KB
実行使用メモリ 90,908 KB
最終ジャッジ日時 2024-05-01 05:45:59
合計ジャッジ時間 7,242 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,756 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1,083 ms
39,936 KB
testcase_07 AC 505 ms
20,096 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

const int INF = 1e9;
int p, q, n;
int x[100001], y[100001];

int main(void){
	cin >> p >> q >> n;
	int lx = INF, rx = -INF, uy = -INF, sy = INF;
	rep(i, n){
		cin >> x[i] >> y[i];
		lx = min(lx, x[i]);//左端
		rx = max(rx, x[i]);//右端
		uy = max(uy, y[i]);//上
		sy = min(sy, y[i]);//下
	}
	int dx[] = {p, p, -p, -p, q, q, -q, -q};
	int dy[] = {q, -q, q, -q, p, -p, p, -p};

	set<pair<int, int> > s;
	queue<pair<int, int> > q;
	q.push(make_pair(0, 0));
	while(!q.empty()){
		auto now = q.front(); q.pop();
		// printf("k %d %d\n", now.first, now.second);
		rep(i, 8){
			int ny = now.first + dy[i], nx = now.second + dx[i];
			if(!(lx <= nx && nx <= rx && sy <= ny && ny <= uy)) continue;
			if(s.count(make_pair(ny, nx)) != 0) continue;
			// printf("%d %d\n", nx, ny);
			s.insert(make_pair(ny, nx));
			q.push(make_pair(ny, nx));
		}
	}

	int ret = 0;
	rep(i, n){
		if(s.count(make_pair(y[i], x[i])) != 0){
			ret++;
		}
	}
	printf("%d\n", ret);
}
0