結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー piyoko_212
提出日時 2015-12-21 18:24:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 34,560 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-06 22:06:52
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:17:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         int n;scanf("%d",&n);
      |               ~~~~~^~~~~~~~~
main.cpp:18:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         for(int i=0;i<n;i++)scanf("%d%d",x+i,y+i);
      |                             ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<algorithm>
using namespace std;
int x[110000];
int y[110000];
int gcd(int a,int b){
	if(a<0)a=-a;
	if(b<0)b=-b;
	while(a){
		b%=a;int c=a;a=b;b=c;
	}
	return b;
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",x+i,y+i);
	int g=gcd(a,b);
	int t=(a+b)/g;
	int ret=0;
	if(g==0){
		for(int i=0;i<n;i++)if(x[i]==0&&y[i]==0)ret++;
		printf("%d\n",ret);
		return 0;
	}
	for(int i=0;i<n;i++){
		if(x[i]%g||y[i]%g)continue;
		int s=x[i]/g+y[i]/g;
		if(s<0)s=-s;
		if(t%2==0&&s%2!=0)continue;
		ret++;
	}
	printf("%d\n",ret);
}
0