結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
![]() |
提出日時 | 2019-07-28 21:05:50 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 1,152 bytes |
コンパイル時間 | 1,079 ms |
コンパイル使用メモリ | 29,952 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 15:07:06 |
合計ジャッジ時間 | 3,312 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
コンパイルメッセージ
main.c: In function 'in': main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 7 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:14:24: note: in expansion of macro 'gc' 14 | int n = 0, c = gc(); | ^~
ソースコード
// yukicoder: No.321 (P,Q)-サンタと街の子供たち// 2019.7.28 bal4u#include <stdio.h>#if 1#define gc() getchar_unlocked()#else#define gc() getchar()#endifint in() // 整数の入力(負数対応){int n = 0, c = gc();if (c == '-') { c = gc();do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');return -n;}do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');return n;}int gcd(int a, int b) {int r;while (b != 0) r = a % b, a = b, b = r;return a;}int main(){int P, Q, N, x, y, g, ans;ans = 0;P = in(), Q = in(), N = in();if (P == 0 && Q == 0) while (N--) x = in(), y = in(), ans += (x == 0) && (y == 0);else if (P == 0) while (N--) x = in(), y = in(), ans += (x % Q == 0) && (y % Q == 0);else if (Q == 0) while (N--) x = in(), y = in(), ans += (x % P == 0) && (y % P == 0);else {g = gcd(P, Q), P /= g, Q /= g;if ((P & 1) && (Q & 1)) while (N--) {x = in(), y = in(), ans += (x % g == 0 && y % g == 0 && ((x/g+y/g) & 1) == 0);} else if (g == 1) ans = N;else while (N--) {x = in(), y = in(), ans += (x % g == 0 && y % g == 0);}}printf("%d\n", ans);return 0;}