結果
問題 |
No.781 円周上の格子点の数え上げ
|
ユーザー |
|
提出日時 | 2021-12-06 23:41:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 315 ms / 2,000 ms |
コード長 | 901 bytes |
コンパイル時間 | 1,650 ms |
コンパイル使用メモリ | 74,196 KB |
実行使用メモリ | 95,596 KB |
最終ジャッジ日時 | 2024-07-07 09:50:30 |
合計ジャッジ時間 | 5,752 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
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); } }