题意与分析
稍微复杂一些的思维题。反正这场全是思维题,就一道暴力水题(B)。题解直接去看官方的,很详尽。
代码
#include <bits/stdc++.h>
#define MP make_pair
#define PB emplace_back
#define fi first
#define se second
#define ZERO(x) memset((x), 0, sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define rep(i, a, b) for (repType i = (a); i <= (b); ++i)
#define per(i, a, b) for (repType i = (a); i >= (b); --i)
#define QUICKIO
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
using namespace std;
using ll=long long;
using repType=int;
int main()
{
int n; cin>>n;
vector<int> vec;
rep(i,1,n)
{
int tmp; cin>>tmp; vec.PB(tmp);
}
if(n==1)
{
if(vec[0]==0) {cout<<"YES"<<endl; cout<<0<<endl;}
else cout<<"NO"<<endl;
}
else
{
if(vec[n-1]==1) cout<<"NO"<<endl;
else if(vec[n-1]==0 && vec[n-2]==1)
{
cout<<"YES"<<endl;
rep(i,0,n-1)
{
if(i!=0) cout<<"->";
cout<<vec[i];
}
cout<<endl;
}
else // 0 0
{
rep(i,0,n-3)
{
if(vec[i]==0)
{
cout<<"YES"<<endl;
rep(j,0,i-1)
{
if(j!=0) cout<<"->";
cout<<vec[j];
}
if(i-1>=0) cout<<"->";
cout<<"(0->(";
rep(j,i+1,n-3)
{
cout<<vec[j]<<"->";
}
cout<<"0))->0"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
}
}
return 0;
}