結果

問題 No.781 円周上の格子点の数え上げ
ユーザー kpskps
提出日時 2021-12-06 23:39:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 2,388 ms
コンパイル使用メモリ 71,028 KB
実行使用メモリ 97,924 KB
最終ジャッジ日時 2023-09-21 16:03:35
合計ジャッジ時間 8,026 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,832 KB
testcase_01 AC 126 ms
55,964 KB
testcase_02 AC 127 ms
55,708 KB
testcase_03 AC 128 ms
55,912 KB
testcase_04 AC 127 ms
55,692 KB
testcase_05 AC 127 ms
55,796 KB
testcase_06 AC 132 ms
55,392 KB
testcase_07 AC 134 ms
55,736 KB
testcase_08 AC 465 ms
97,792 KB
testcase_09 AC 460 ms
97,892 KB
testcase_10 AC 132 ms
55,576 KB
testcase_11 AC 136 ms
55,664 KB
testcase_12 AC 458 ms
97,588 KB
testcase_13 AC 460 ms
97,924 KB
testcase_14 AC 140 ms
57,632 KB
testcase_15 AC 132 ms
55,416 KB
testcase_16 AC 133 ms
55,796 KB
testcase_17 AC 301 ms
81,428 KB
testcase_18 AC 297 ms
81,320 KB
testcase_19 AC 308 ms
81,120 KB
testcase_20 AC 311 ms
81,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    //原点を中心とする半径maxR以下の円それぞれの円周上にある格子点を数え上げるプログラム
    	//計算量:O(maxR*maxR)
    	int X=sc.nextInt(),Y=sc.nextInt();
    	int maxR=(int)Math.sqrt(Y);
    	int counter[]=new int[Y+1];
    	//counter[i]:半径√iの円の円周上にある格子点の数,ex:counter[4]は半径2の円の答え
    	
    	for(int x=-maxR;x<=maxR;x++) {
    		for(int y=-maxR;y<=maxR;y++) {
    			//(x,y)が半径Rの円の円周上にある⇔x^2+y^2=R^2
    			if(x*x+y*y>Y)continue;
    			counter[x*x+y*y]++;
    			
    		}
    	}
    	int ans=0;
    	for(int i=X;i<=Y;i++) {
    		ans=Math.max(ans, counter[i]);
    		//System.out.println("半径√iの円の答え:"+counter[i]);
    	}
    	System.out.println(ans);
  }
}
0