結果
問題 | No.420 mod2漸化式 |
ユーザー |
![]() |
提出日時 | 2016-09-09 22:50:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 104 ms / 1,000 ms |
コード長 | 2,317 bytes |
コンパイル時間 | 2,300 ms |
コンパイル使用メモリ | 79,836 KB |
実行使用メモリ | 51,608 KB |
最終ジャッジ日時 | 2024-12-24 11:07:53 |
合計ジャッジ時間 | 6,155 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 35 |
ソースコード
import java.io.BufferedReader;import java.io.Closeable;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.Arrays;import java.util.HashSet;import java.util.LinkedList;import java.util.Scanner;import java.util.Set;import java.util.StringTokenizer;public class Main {public static void main(String[] args) throws IOException {Scanner sc = new Scanner(System.in);final int x = sc.nextInt();if(x >= 32){System.out.println(0 + " " + 0);}else{long[] count_DP = new long[32 + 1];long[] count_nextDP = new long[32 + 1];long[] value_DP = new long[32 + 1];long[] value_nextDP = new long[32 + 1];count_DP[0] = 1;for(int i = 0; i <= 31; i++){Arrays.fill(count_nextDP, 0);Arrays.fill(value_nextDP, 0);//System.out.println(Arrays.toString(value_DP));for(int j = 0; j <= i; j++){count_nextDP[j] += count_DP[j];if(j < 32){count_nextDP[j + 1] += count_DP[j];}value_nextDP[j] += value_DP[j] * 2;if(j < 32){value_nextDP[j + 1] += value_DP[j] * 2 + count_DP[j];}}{long[] tmp = count_DP;count_DP = count_nextDP;count_nextDP = tmp;}{long[] tmp = value_DP;value_DP = value_nextDP;value_nextDP = tmp;}}System.out.println(count_nextDP[x] + " " + value_nextDP[x]);}}public static class Scanner implements Closeable {private BufferedReader br;private StringTokenizer tok;public Scanner(InputStream is) throws IOException {br = new BufferedReader(new InputStreamReader(is));}private void getLine() throws IOException {while (!hasNext()) {tok = new StringTokenizer(br.readLine());}}private boolean hasNext() {return tok != null && tok.hasMoreTokens();}public String next() throws IOException {getLine();return tok.nextToken();}public int nextInt() throws IOException {return Integer.parseInt(next());}public long nextLong() throws IOException {return Long.parseLong(next());}public double nextDouble() throws IOException {return Double.parseDouble(next());}public void close() throws IOException {br.close();}}}