結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2015-05-03 18:28:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 5,000 ms |
| コード長 | 1,751 bytes |
| コンパイル時間 | 778 ms |
| コンパイル使用メモリ | 86,224 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-14 15:29:37 |
| 合計ジャッジ時間 | 1,423 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#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;
inline int check(int a, int b){
while (a != 0 || b != 0){
if ((a & 1) != (b & 1))break;
a >>= 1;
b >>= 1;
}
return (a & 1) < (b & 1);
}
void prev(int n,LL val,int bit){
//cout << "prev:" << n << endl;
if (n == M){
// cout << val << endl;
if (exist[val] == -1 || check(bit, exist[val]))
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];
//cout << val << endl;
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++)
{
// cout << a[i];
if (res1&(1 << i))cout << '*'; else cout << '+';
}
//cout << a[M] << endl;
for (int i = 0; i < (N - 1) / 2; i++){
if (res2&(1 << i))cout << '*'; else cout << '+';
// cout << a[i + M + 1];
}
cout << endl;
return 0;
}
btk