結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2015-05-03 18:11:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,455 bytes |
| コンパイル時間 | 546 ms |
| コンパイル使用メモリ | 85,928 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 17:39:26 |
| 合計ジャッジ時間 | 1,137 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 3 |
ソースコード
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
#define LL long long
int N, M;
LL Total;
LL exist[100001];
LL a[100];
LL res1, res2;
void prev(int n,LL val,int bit){
//cout << "prev:" << n << endl;
if (n == M){
// cout << val << endl;
exist[val] = bit;
return;
}
if (val%a[n] == 0)prev(n - 1, val / a[n], bit + (1 << (n - M - 1)));
if (val - a[n]>0)prev(n - 1, val - a[n], bit);
return;
}
bool next(int n, LL val, int bit){
//cout << "next:" << n << endl;
if (n == M){
// cout << val << endl;
if (exist[val] != -1){
res1 = bit; res2 = exist[val];
return true;
}
return false;
}
if (val + a[n+1] <= Total)if (next(n + 1, val+a[n+1], bit))return true;
if (val*a[n+1] <= Total)if (next(n + 1, val*a[n+1], bit + (1 << n)))return true;
return false;
}
int main(void){
cin >> N >> Total;
for (int i = 0; i <= 100000; i++)exist[i] = -1;
for (int i = 0; i < N; i++)cin >> a[i];
M = N / 2;
prev(N - 1, Total, 0);
next(0, a[0], 0);
for (int i = 0; i < N/2; i++)
{
if (res1&(1 << i))cout << '*'; else cout << '+';
}
for (int i = 0; i < (N-1)/2; i++)
if (res2&(1 << i))cout << '*'; else cout << '+';
cout << endl;
return 0;
}
btk