結果

問題 No.781 円周上の格子点の数え上げ
ユーザー kpskps
提出日時 2021-12-06 23:37:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 3,691 ms
コンパイル使用メモリ 71,160 KB
実行使用メモリ 98,452 KB
最終ジャッジ日時 2023-09-21 16:03:16
合計ジャッジ時間 7,203 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
56,076 KB
testcase_01 AC 117 ms
55,916 KB
testcase_02 AC 115 ms
56,108 KB
testcase_03 AC 116 ms
55,716 KB
testcase_04 AC 117 ms
55,832 KB
testcase_05 AC 116 ms
56,468 KB
testcase_06 AC 120 ms
56,204 KB
testcase_07 AC 122 ms
55,716 KB
testcase_08 AC 366 ms
98,452 KB
testcase_09 AC 355 ms
98,088 KB
testcase_10 AC 121 ms
56,376 KB
testcase_11 AC 125 ms
55,816 KB
testcase_12 AC 366 ms
98,340 KB
testcase_13 AC 368 ms
98,096 KB
testcase_14 AC 131 ms
57,768 KB
testcase_15 AC 122 ms
55,788 KB
testcase_16 AC 121 ms
55,500 KB
testcase_17 AC 242 ms
81,976 KB
testcase_18 AC 234 ms
82,044 KB
testcase_19 AC 240 ms
81,960 KB
testcase_20 AC 241 ms
81,216 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