結果
問題 | No.786 京都大学の過去問 |
ユーザー | kqleid |
提出日時 | 2019-07-20 01:13:13 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 3,069 bytes |
コンパイル時間 | 3,083 ms |
コンパイル使用メモリ | 78,452 KB |
実行使用メモリ | 37,312 KB |
最終ジャッジ日時 | 2024-06-07 22:56:27 |
合計ジャッジ時間 | 3,876 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
37,228 KB |
testcase_01 | AC | 46 ms
36,796 KB |
testcase_02 | AC | 46 ms
37,192 KB |
testcase_03 | AC | 45 ms
37,192 KB |
testcase_04 | AC | 46 ms
37,312 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static final int MOD = (int)1e9+7; public static void main(String[] args){ FastScanner sc = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); solve(sc,out); out.flush(); } public static void solve(FastScanner sc, PrintWriter out) { int n = sc.nextInt(); long[] dp = new long[n + 2]; dp[0] = 0; dp[1] = 1; for(int i = 2; i <= n+1; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } out.println(dp[n+1]); } public static long gcd(long a, long b) { if(a < b) return gcd(b, a); if(b == 0) return a; return gcd(b, a % b); } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long factorial(int n) { long a; if(n > 0) { a = n * factorial(n - 1); }else{ a = 1; } return a; } } class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> { public Pair(K key, V value) { super(key, value); } public Pair<V, K> swap() { return new Pair<V, K>(getValue(), getKey()); } } class UnionFind { int[] par; public UnionFind(int n) { par = new int[n]; Arrays.fill(par, -1); } int root(int x) { if(par[x] < 0) return x; return par[x] = root(par[x]); } boolean unite(int x,int y) { x = root(x); y = root(y); if(x == y) return false; if(size(x) < size(y)) { int tmp = x; x = y; y = tmp; } par[x] += par[y]; par[y] = x; return true; } boolean same(int x,int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int a) { return -par[root(a)]; } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } }