結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
![]() |
提出日時 | 2016-06-08 22:06:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 1,110 bytes |
コンパイル時間 | 485 ms |
コンパイル使用メモリ | 64,216 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 22:13:46 |
合計ジャッジ時間 | 2,372 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d %d %d",&p,&q,&n); | ~~~~~^~~~~~~~~~~~~~~~~~~~~ main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | scanf("%d %d",&x,&y); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; #define REP(i,s,e) for (i = s; i <= e; i++) #define rep(i,n) REP (i,0,(int)(n)-1) #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP (i,(int)(n)-1,0) #define INF (int)1e8 #define MOD (int)(1e9+7) typedef long long ll; int gcd(int a, int b) { return b == 0 ? a : gcd(b,a%b); } int main(void) { int i, p, q, n; scanf("%d %d %d",&p,&q,&n); int ans = 0; while (n--) { int x, y; scanf("%d %d",&x,&y); if (p == 0 || q == 0) { if (p == 0 && q == 0) ans += x == 0 && y == 0; else if (p == 0) ans += x % q == 0 && y % q == 0; else ans += x % p == 0 && y % p == 0; continue; } if (x % gcd(p,q) != 0 || y % gcd(p,q) != 0) continue; x /= gcd(p,q); y /= gcd(p,q); x = (x%2+2)%2; y = (y%2+2)%2; if (x == y || p / gcd(p,q) % 2 != q / gcd(p,q) % 2) ans++; } printf("%d\n",ans); return 0; }