結果
問題 | No.220 世界のなんとか2 |
ユーザー |
|
提出日時 | 2016-11-04 12:16:23 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 140 ms / 1,000 ms |
コード長 | 1,737 bytes |
コンパイル時間 | 3,471 ms |
コンパイル使用メモリ | 79,888 KB |
実行使用メモリ | 54,256 KB |
最終ジャッジ日時 | 2024-11-25 02:34:57 |
合計ジャッジ時間 | 6,983 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.util.Scanner; import java.math.BigInteger; public class Yuki220 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int p=sc.nextInt(); long ary1[],ary2[],ary3[],ary4[]; ary1=new long[19]; ary2=new long[19]; ary3=new long[19]; ary4=new long[19]; String S="1"; int h=1; for(int i=0;i<19;++i){ S+="0"; long b=0,d=0,e=0; BigInteger bi_div=new BigInteger("3"); BigInteger bi_a=new BigInteger(S); bi_a=bi_a.divide(bi_div); long b1_2=1; for(int j=0;j<i;++j){ b1_2*=10; } long b1=h*b1_2; long b2=0; int cnt=0; for(int j=i-1;j>=0;--j){ long b3=ary1[j]; long b3_2=1; for(int k=0;k<cnt;++k){ b3_2*=10; } long b4=b3*b3_2; b2+=b4; cnt+=1; } long b5=b1-b2; ary1[i]=b5; b=b5; String S_b=Long.toString(b); BigInteger bi_b=new BigInteger(S_b); BigInteger bi_c=new BigInteger("0"); bi_c=bi_c.add(bi_a); bi_c=bi_c.add(bi_b); long d1=0,d2=0,d3=0,d4=0,d5=0,d6=0,d7=0; if(i-1>=0) d1=ary2[i-1]; if(i-2>=0) d2=ary2[i-2]; if(i-2>=0) d3=d1-d2; d4=d1*3; d5=d3*6; if(i-1>=0) d5+=ary3[i-1]; ary3[i]=d5; d6=1; for(int j=0;j<i*2-1;++j){ d6*=3; } d6+=d1; d7=d4+d5+d6; if(d7==0) d7=1; ary2[i]=d7; d=d7; String S_d=Long.toString(d); BigInteger bi_d=new BigInteger(S_d); BigInteger bi_e=new BigInteger("0"); bi_e=bi_e.add(bi_c); bi_e=bi_e.subtract(bi_d); e=bi_e.longValue(); ary4[i]=e; h+=1; } System.out.println(ary4[p-1]); } }