結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,936 KB
testcase_01 AC 127 ms
55,596 KB
testcase_02 AC 127 ms
55,604 KB
testcase_03 AC 127 ms
55,600 KB
testcase_04 AC 133 ms
55,716 KB
testcase_05 AC 131 ms
55,724 KB
testcase_06 AC 134 ms
55,724 KB
testcase_07 AC 132 ms
55,544 KB
testcase_08 AC 450 ms
97,776 KB
testcase_09 AC 450 ms
97,940 KB
testcase_10 AC 132 ms
55,796 KB
testcase_11 AC 134 ms
53,616 KB
testcase_12 AC 457 ms
97,984 KB
testcase_13 AC 450 ms
97,936 KB
testcase_14 AC 138 ms
57,760 KB
testcase_15 AC 131 ms
55,876 KB
testcase_16 AC 131 ms
55,808 KB
testcase_17 AC 306 ms
81,320 KB
testcase_18 AC 302 ms
81,200 KB
testcase_19 AC 304 ms
81,200 KB
testcase_20 AC 303 ms
81,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
  static Scanner sc=new Scanner(System.in);
  public static void main(String[] args){
      //原点を中心とする半径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++) {
    			if(x*x+y*y>Y)continue;
          //(x,y)は半径√(x*x+y*y)の円の円周上にある
    			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