| 记录编号 |
611360 |
评测结果 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
| 题目名称 |
[THUPC 2025 Final] 一个 01 串,n 次三目运算符,最后值为 1 |
最终得分 |
100 |
| 用户昵称 |
LikableP |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
1.034 s |
| 提交时间 |
2026-01-28 22:37:59 |
内存使用 |
4.51 MiB |
显示代码纯文本
#include<bits/stdc++.h>
char s[333333];
char val(char x,char y,char z){
return x=='1'?y:z;
}
std::pair<std::string, char> fold(int l,int r){
std::string str;
char v=s[r];
for(int i=l;i<r;i+=2){
str+=s[i];
str+='?';
str+=s[i+1];
str+=':';
}
str+=s[r];
for(int i=r-2;i>=l;i-=2){
v=val(s[i],s[i+1],v);
}
return std::make_pair(str,v);
}
int main(){
freopen("thupc_2025_conditionop.in", "r", stdin);
freopen("thupc_2025_conditionop.out", "w", stdout);
int n;
scanf("%d",&n);
n=2*n+1;
scanf("%s",s+1);
int last=0;
for(int i=1;i<=n;++i){
if(s[i]=='1'&&last>0){
if(i%2==0&&last&1){
puts("Yes");
std::string s4=fold(last+1,i).first;
auto tmp=fold(i+1,n);
std::string s5=tmp.first;
char v5=tmp.second;
if(last==1){
printf("1?(%s):(%s)\n",s4.c_str(),s5.c_str());
return 0;
}
tmp=fold(1,last-2);
std::string s1=tmp.first;
char v1=tmp.second;
if(v1=='1'){
printf("(%s)?(%c?1:(%s)):(%s)\n",s1.c_str(),s[last-1],s4.c_str(),s5.c_str());
}
else{
printf("((%s)?%c:1)?(%s):(%s)\n",s1.c_str(),s[last-1],s4.c_str(),s5.c_str());
}
return 0;
}
}
if(s[i]=='1'){
last=i;
}
}
if(s[n]=='1'&&std::string(s+1)!="101"){
puts("Yes");
auto left=s[1]=='0'?fold(1,1):fold(1,3);
auto mid=s[1]=='0'?fold(2,n-1):fold(4,n-1);
printf("(%s)?(%s):1\n",left.first.c_str(),mid.first.c_str());
return 0;
}
puts("No");
return 0;
}