結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
alpha_virginis
|
| 提出日時 | 2016-11-09 20:36:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 873 bytes |
| コンパイル時間 | 1,469 ms |
| コンパイル使用メモリ | 166,072 KB |
| 実行使用メモリ | 10,144 KB |
| 最終ジャッジ日時 | 2024-11-25 05:56:48 |
| 合計ジャッジ時間 | 14,093 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 4 TLE * 2 |
ソースコード
#include <bits/stdc++.h>
int n;
int total;
int xs[64];
int lower[64];
char buf[64];
bool dfs(int i, int x) {
// for(int j = 0; j < i; ++j) putchar(' ');
// printf("(i, sum, x) = (%d, %d)\n", i, x);
if( i == n ) return (x == total);
do {
if( x + lower[i+1] > total ) break;
buf[i-1] = '+';
if( dfs(i + 1, x + xs[i]) ) return true;
} while(false);
do {
if( x * lower[i+1] > total ) break;
buf[i-1] = '*';
if( dfs(i + 1, x * xs[i]) ) return true;
} while(false);
return false;
}
int main() {
scanf("%d", &n);
scanf("%d", &total);
for(int i = 0; i < n; ++i) {
scanf("%d", &xs[i]);
}
// step 1
for(int i = 0; i < n; ++i) {
int x = 0;
for(int j = i; j < n; ++j) {
if( xs[j] != 1 ) x += xs[j];
}
lower[i] = x;
}
// step 2
dfs(1, xs[0]);
// step 3
printf("%s\n", buf);
return 0;
}
alpha_virginis