結果
問題 | No.10 +か×か |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2018-01-05 01:27:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 111 ms / 5,000 ms |
コード長 | 2,341 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 74,704 KB |
実行使用メモリ | 57,748 KB |
最終ジャッジ日時 | 2023-08-21 06:24:18 |
合計ジャッジ時間 | 3,589 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,436 KB |
testcase_01 | AC | 43 ms
49,584 KB |
testcase_02 | AC | 43 ms
49,448 KB |
testcase_03 | AC | 92 ms
57,376 KB |
testcase_04 | AC | 89 ms
55,136 KB |
testcase_05 | AC | 44 ms
49,348 KB |
testcase_06 | AC | 111 ms
57,748 KB |
testcase_07 | AC | 85 ms
55,300 KB |
testcase_08 | AC | 81 ms
52,324 KB |
testcase_09 | AC | 78 ms
55,240 KB |
testcase_10 | AC | 43 ms
49,652 KB |
testcase_11 | AC | 44 ms
49,404 KB |
ソースコード
import java.io.*; import java.util.*; class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); int total=sc.nextInt(); int[]a=new int[n]; for(int i=0;i<n;++i)a[i]=sc.nextInt(); boolean[][]dp=new boolean[n][total+1]; dp[n-1][total]=true; for(int i=n-1;i>=1;--i){ for(int j=0;j<=total;++j){ if(j+a[i]<=total&&dp[i][j+a[i]]) dp[i-1][j]=true; if(j*a[i]<=total&&dp[i][j*a[i]]) dp[i-1][j]=true; } } // keiro fukugen int[]ops=new int[n-1]; int c=a[0]; for(int i=1;i<n;++i){ if(c+a[i]<=total&&dp[i][c+a[i]]){ ops[i-1]=1; c+=a[i]; continue; } ops[i-1]=2; c*=a[i]; } for(int i=0;i<n-1;++i) out.print(ops[i]==1?"+":"*"); out.println(); 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; } } }