結果

問題 No.781 円周上の格子点の数え上げ
ユーザー hirohiro
提出日時 2019-01-22 00:16:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 4,523 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 52,404 KB
最終ジャッジ日時 2023-10-13 17:35:26
合計ジャッジ時間 12,429 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
50,356 KB
testcase_01 AC 48 ms
50,276 KB
testcase_02 AC 49 ms
50,256 KB
testcase_03 AC 49 ms
50,344 KB
testcase_04 AC 47 ms
50,392 KB
testcase_05 AC 50 ms
50,352 KB
testcase_06 AC 53 ms
50,348 KB
testcase_07 AC 54 ms
50,416 KB
testcase_08 AC 79 ms
51,808 KB
testcase_09 AC 76 ms
51,460 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package ycoder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/*
 * このコードでyukicoderの問題である	No.781 円周上の格子点の数え上げに提出をしたが、
 * TLE(Time Limit Exceed)時間切れになってしまった
 * もっと効率のいいアルゴリズムを考え直さなければいけない
 */
public class CircleLatticePoint {
	public static void main(String... string) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		
		int rMin = Integer.parseInt(tmp[0]);
		int rMax = Integer.parseInt(tmp[1]);
		ArrayList<Integer> latticePointList = new ArrayList<>();

		CircleLatticePoint clp = new CircleLatticePoint();
		for(int r = rMin; r <= rMax; r++) {
			latticePointList.add(clp.getLatticePoint(r));
		}
		latticePointList.stream()
						.sorted((a,b) -> b - a);
		int maxLatticePoint = latticePointList.get(0);
		System.out.println(maxLatticePoint);
	}
	
	public int getLatticePoint(int r) {
		int result = 0;
		for(int x = 0; x <= Math.sqrt(r); x++) {
			for(int y = 0; y < Math.sqrt(r); y++) {
				if(r == x*x + y*y) {
					result++;
				}
			}
		}
		result = result * 4;
		return result;
	}
}
0