結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー Yang33
提出日時 2018-10-02 21:45:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 2,500 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 176,088 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 10:06:02
合計ジャッジ時間 3,629 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2018/10/02 Problem: yukicoder 321 / Link: http://yukicoder.me/problems/no/321 ----- */
/* ------------
---------- */
/* ----------
-------- */
LL ans = 0LL;
void solve() {
int H, W; H = W = 100;
cout << "what is vec(P,Q)?" << endl;
int P, Q; cin >> P >> Q;
VVI m(2*H, VI(2*W, 0));
m[H][W] = 2;
queue<PII>q;
q.push(PII(H, W));
while (!q.empty()) {
PII a = q.front(); q.pop();
for (int i = -1; i < 2; i += 2) {
for (int j = -1; j < 2; j += 2) {
int ny = a.first + P * i;
int nx = a.second + Q * j;
#define IN(x,y,z) (x<=y&&y<z)
if (IN(0, ny, 2 * H) && IN(0, nx, 2 * W) && !m[ny][nx]) {
m[ny][nx] = 1;
q.push(PII(ny, nx));
}
}
}
for (int i = -1; i < 2; i += 2) {
for (int j = -1; j < 2; j += 2) {
int ny = a.first + Q * i;
int nx = a.second + P * j;
if (IN(0, ny, 2 * H) && IN(0, nx, 2 * W) && !m[ny][nx]) {
m[ny][nx] = 1;
q.push(PII(ny, nx));
}
}
}
}
FOR(i, -20, 21) {
FOR(j, -20, 21) {
cout << m[i+H][j+W] << " ";
}cout << endl;
}
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
//solve(); return 0;
LL P, Q; cin >> P >> Q;
LL G = __gcd(P, Q);
if (G) {
P = P / G;
Q = Q / G;
}
LL N; cin >> N;
FOR(i, 0, N) {
LL x, y; cin >> x >> y;
if (P == 0 && P == Q) {
if (x == 0 && x == y)ans++;
}
else {
if (x%G == 0 && y%G == 0) {
x /= G, y /= G;
if (P & 1 && Q & 1) {
if ((x + y) % 2 == 0) {
ans++;
}
}
else {
ans++;
}
}
}
}
cout << ans << "\n";
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0