結果

問題 No.220 世界のなんとか2
ユーザー itezpaceitezpace
提出日時 2016-11-04 12:16:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 1,737 bytes
コンパイル時間 3,834 ms
コンパイル使用メモリ 76,044 KB
実行使用メモリ 57,596 KB
最終ジャッジ日時 2023-08-16 13:28:19
合計ジャッジ時間 7,955 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,928 KB
testcase_01 AC 127 ms
55,552 KB
testcase_02 AC 126 ms
55,812 KB
testcase_03 AC 126 ms
56,232 KB
testcase_04 AC 137 ms
55,856 KB
testcase_05 AC 127 ms
57,596 KB
testcase_06 AC 128 ms
56,060 KB
testcase_07 AC 129 ms
56,172 KB
testcase_08 AC 129 ms
56,008 KB
testcase_09 AC 129 ms
55,740 KB
testcase_10 AC 128 ms
55,604 KB
testcase_11 AC 131 ms
55,996 KB
testcase_12 AC 128 ms
56,036 KB
testcase_13 AC 131 ms
56,008 KB
testcase_14 AC 131 ms
55,900 KB
testcase_15 AC 128 ms
56,068 KB
testcase_16 AC 128 ms
56,024 KB
testcase_17 AC 131 ms
55,836 KB
testcase_18 AC 128 ms
55,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]);
  }
}
0