結果
問題 | No.10 +か×か |
ユーザー |
|
提出日時 | 2023-09-23 08:55:38 |
言語 | D (dmd 2.109.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 656 bytes |
コンパイル時間 | 5,859 ms |
コンパイル使用メモリ | 207,452 KB |
実行使用メモリ | 13,888 KB |
最終ジャッジ日時 | 2024-07-16 08:36:52 |
合計ジャッジ時間 | 11,869 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 TLE * 1 -- * 8 |
ソースコード
module main; import std; // 整数を(N - 1)桁の2進数に変換し、更に0を+、1を*に変換する string toOps(int N, long x) { return format("%0*b", N - 1, x).translate(['0' : '+', '1' : '*']); } void main() { // 入力 int N = readln.chomp.to!int; int total = readln.chomp.to!int; auto A = readln.split.to!(int[]); // 答えの計算(総当たり) long i = 0; for (; i < 2L ^^ (N - 1); i++) { auto ops = toOps(N, i); long val = A[0]; foreach (j; 0 .. N - 1) { if (ops[j] == '+') val += A[j + 1]; else // ops[j] == '*' val *= A[j + 1]; } if (val == total) break; } // 答えの出力 writeln(toOps(N, i)); }