結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
![]() |
提出日時 | 2015-12-14 01:52:50 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 682 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 22,784 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 21:50:49 |
合計ジャッジ時間 | 1,988 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%d%d%d", &p, &q, &n); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d%d", &x[i], &y[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int p, q, n, x[100000], y[100000]; int gcd(int a, int b) { if(b == 0) { return a; } return gcd(b, a % b); } int main(void) { scanf("%d%d%d", &p, &q, &n); int i; for(i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); } if(p < q) { int temp = p; p = q; q = temp; } int d = gcd(p, q), counter = 0; for(i = 0; i < n; i++) { if(q != 0) { if( x[i] % d == 0 && y[i] % d == 0 && ( ((p + q) / d) % 2 == 1 || ((x[i] + y[i]) / d) % 2 == 0 ) ) { counter++; } } else if(p != 0) { if( x[i] % p == 0 && y[i] % p == 0 ) { counter++; } } else { if( x[i] == 0 && y[i] == 0 ) { counter++; } } } printf("%d\n", counter); return 0; }