結果
| 問題 |
No.781 円周上の格子点の数え上げ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-21 23:41:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,325 bytes |
| コンパイル時間 | 4,009 ms |
| コンパイル使用メモリ | 88,448 KB |
| 実行使用メモリ | 44,172 KB |
| 最終ジャッジ日時 | 2024-09-15 13:25:57 |
| 合計ジャッジ時間 | 10,657 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 TLE * 2 -- * 13 |
ソースコード
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 = 1; x <= r; x++) {
for(int y = 1; y <= r; y++) {
if(r == x*x + y*y) {
result++;
}
}
}
result = result * 4;
if(Math.sqrt(r) % 1 == 0) result += 4;
return result;
}
}