結果
| 問題 |
No.634 硬貨の枚数1
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-19 21:46:05 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 2,405 bytes |
| コンパイル時間 | 3,402 ms |
| コンパイル使用メモリ | 78,068 KB |
| 実行使用メモリ | 78,628 KB |
| 最終ジャッジ日時 | 2024-12-25 18:44:19 |
| 合計ジャッジ時間 | 14,899 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 75 |
ソースコード
import java.io.*;
import java.util.*;
class Main {
static final int I=1<<27;
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n=sc.nextInt();
final int W=10000000;
int[]dp=new int[W];
Arrays.fill(dp,I);
dp[0]=0;
final int B=5000;
int[]t=new int[B];
Set<Integer> ts=new HashSet<Integer>();
for(int i=1;i<5000;++i){
int w=i*(i+1)/2;
t[i]=w;
ts.add(w);
if(t[i]==n){
out.println(1);
out.close();
return;
}
}
for(int i=0;i<B;++i){
int rest=n-t[i];
if(rest<=0){
continue;
}
if(ts.contains(rest)){
out.println(2);
out.close();
return;
}
}
out.println(3);
out.close();
}
// http://codeforces.com/blog/entry/7018
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n){
int[]r=new int[n];
for(int i=0;i<n;++i)r[i]=nextInt();
return r;
}
}
}
夕叢霧香(ゆうむらきりか)