結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー motimoti
提出日時 2015-12-14 16:13:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,100 bytes
コンパイル時間 1,063 ms
コンパイル使用メモリ 111,224 KB
実行使用メモリ 21,400 KB
最終ジャッジ日時 2023-10-13 16:33:20
合計ジャッジ時間 8,947 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return -H<=y&&y<H&&-W<=x&&x<W; }

typedef long long ll;
int const inf = 1<<29;

ll const MaxSize = 301;

//vector<vector<bool>> vis;
set<pair<int, int>> vis;

void solve(ll q, ll p, int h, int w) {

  vis.clear();

  ll const dx[] = {p,p,-p,-p,q,q,-q,-q};
  ll const dy[] = {q,-q,q,-q,p,-p,p,-p};

  queue<pair<ll, ll>> Q;
  Q.emplace(0, 0);
  vis.insert({0, 0});

  while(!Q.empty()) {
    auto const prev = Q.front(); Q.pop();
    auto const y = prev.first, x = prev.second;
    rep(k, 8) {
      auto const ny = y + dy[k], nx = x + dx[k];
      if(!in_range(y, x, (ll)h, (ll)w)) { continue; }
      if(vis.count({ny, nx})) { continue; }
      vis.insert({ny, nx});
      Q.emplace(ny, nx);
    }
  }
}

int main() {

  ll p, q; cin >> p >> q;
//  ll g = __gcd(p, q);
  ll N; cin >> N;
  solve(q, p, MaxSize, MaxSize);
  auto& small_case = vis;
/*
  REP(i, -10, 21) {
    REP(j, -10, 21) {
      if(small_case.count({i, j})) {
        cout << "#";
      }
      else {
        cout << ".";
      }
    }
    cout << endl;
  }
*/
  int ans = 0;

  rep(i, N) {
    ll x, y; cin >> x >> y;
    if(x < MaxSize && y < MaxSize) {
      ans += small_case.count({y, x});
    }
    else {
      if((p + q) % 2) {
        ans ++;
      }
      else {
        if((x + y) % 2 == 0) {
          ans ++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0