結果
| 問題 | No.708 (+ー)の式 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 16:47:56 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 2,000 ms |
| + 759µs | |
| コード長 | 3,333 bytes |
| 記録 | |
| コンパイル時間 | 2,850 ms |
| コンパイル使用メモリ | 336,168 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-23 16:48:01 |
| 合計ジャッジ時間 | 3,734 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
/*
#include<kyopro/master>
void self::main(){
STR(s);
ll N=s.size();
vec<ll>pos(N,-1);
vec<ll>st;
fo(i,N){
if(s[i]=='('){
st.eb(i);
}else if(s[i]==')'){
ll j=st.pop_back();
pos[i]=j;
pos[j]=i;
}
}
auto dfs=[&](this auto self,ll l,ll r)->ll{
if(l>r)return 0;
if(l==r)return s[l]-'0';
if(s[l]=='('&&s[r]==')')return self(l+1,r-1);
ll res=0;
if(in('0',s[l],'9'+1)){
ll x=s[l]-'0';
res=x+self(l+1,r);
}
else if(s[l]=='('){
ll x=self(l,pos[l]);
res=x+self(pos[l]+1,r);
}
else{
if(in('0',s[l+1],'9'+1)){
ll x=s[l+1]-'0';
if(s[l]=='-')x=-x;
res=x+self((l+1)+1,r);
}
else if(s[l+1]=='('){
ll x=self(l+1,pos[l+1]);
if(s[l]=='-')x=-x;
res=x+self(pos[l+1]+1,r);
}
}
return res;
};
pp(dfs(0,N-1));
}
*/
#include<bits/stdc++.h>
using namespace std;
namespace self{void main();void sub();template<ostream&o>void pp(const auto&...a);void epp(const auto&...a);}
int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);self::main();}
#define eb emplace_back
#define RD(T,...) T __VA_ARGS__;lin(__VA_ARGS__)
#define STR(...) RD(str,__VA_ARGS__)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
namespace self{
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
bool in(auto l,auto m,auto r){return l<=m&&m<r;}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace self{
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
using vector<V>::vector;
auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
auto pop_back(){auto r=this->back();vector<V>::pop_back();return r;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace self{
struct str:string{
str()=default;
ll size()const{return string::size();}
};
}
template<ostream&o=cout>void self::pp(const auto&...a){const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}
void self::main(){
STR(s);
ll N=s.size();
vec<ll>pos(N,-1);
vec<ll>st;
fo(i,N){
if(s[i]=='('){
st.eb(i);
}else if(s[i]==')'){
ll j=st.pop_back();
pos[i]=j;
pos[j]=i;
}
}
auto dfs=[&](this auto self,ll l,ll r)->ll{
if(l>r)return 0;
if(l==r)return s[l]-'0';
if(s[l]=='('&&s[r]==')')return self(l+1,r-1);
ll res=0;
if(in('0',s[l],'9'+1)){
ll x=s[l]-'0';
res=x+self(l+1,r);
}
else if(s[l]=='('){
ll x=self(l,pos[l]);
res=x+self(pos[l]+1,r);
}
else{
if(in('0',s[l+1],'9'+1)){
ll x=s[l+1]-'0';
if(s[l]=='-')x=-x;
res=x+self((l+1)+1,r);
}
else if(s[l+1]=='('){
ll x=self(l+1,pos[l+1]);
if(s[l]=='-')x=-x;
res=x+self(pos[l+1]+1,r);
}
}
return res;
};
pp(dfs(0,N-1));
}