結果
| 問題 |
No.457 (^^*)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-08 21:47:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 578 ms / 2,000 ms |
| コード長 | 3,312 bytes |
| コンパイル時間 | 736 ms |
| コンパイル使用メモリ | 79,396 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-28 15:30:50 |
| 合計ジャッジ時間 | 2,585 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#pragma GCC optimize("O3")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// cpp_range (generic range class, very small equivalent of boost::irange)
// (C) @cielavenir under Boost Software License.
// note: end position is exclusive.
#ifdef BOOST
#include <boost/range.hpp>
#define make_range boost::irange
#else
#include <iterator>
template<typename T>
class range{
public:
struct iterator{
const T a,b;
T p;
const long long d; //because T might be unsigned.
iterator(T _a,T _b,T _p,long long _d=1):a(_a),b(_b),p(_p),d(_d){}
public:
typedef T value_type;
typedef T& reference;
typedef T* pointer;
typedef std::ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;
//copy
iterator(const iterator &other):a(other.a),b(other.b),p(other.p),d(other.d){}
iterator operator=(const iterator &other){return iterator(other.a,other.b,other.p,other.d);}
//advance
iterator& operator+=(T n){p+=n*d;return *this;}
iterator& operator-=(T n){return *this+=(-n);}
iterator& operator++(){return *this+=1;}
iterator& operator--(){return *this-=1;}
iterator operator+(T n) const{return iterator(a,b,p+n*d);}
iterator operator-(T n) const{return *this+(-n);}
//difference
T operator-(const iterator& other) const{return p-other.p;}
//equality
bool operator==(const iterator& other) const{return a==other.a && b==other.b && d==other.d && p==other.p;}
bool operator!=(const iterator& other) const{return !(*this==other);}
//compare
bool operator<(const iterator& other) const{return a==other.a && b==other.b && d==other.d && p*d<other.p*d;}
bool operator>(const iterator& other) const{return a==other.a && b==other.b && d==other.d && p*d>other.p*d;}
//reference
const T& operator*() const{return p;}
};
private:
const T a,b;
T siz;
long long d;
public:
range(T _a,T _b,long long _d=1):a(_a),b(_b){
d=_d;
if(d==0)d=1; //
siz=( (d>0?(b-a):(a-b)) - 1) / (d>0?d:-d);
}
T operator[](T n){return a+n*d;}
iterator begin(){return iterator(a,a+d*siz,a,d);}
iterator end(){return iterator(a,a+d*siz,a+d*(siz+1),d);}
iterator rbegin(){return iterator(b-d*siz,b,b,-1*d);}
iterator rend(){return iterator(b-d*siz,b,b-d*(siz+1),-1*d);}
T size(){return siz+1;}
};
template<typename T>
range<T> make_range(T a,T b,long long d=1){return range<T>(a,b,d);}
#endif
int solve(const string &s){
int len=s.size();
vector<int>al;
vector<int>ar;
vector<int>ah(len);
vector<int>ast;
for(auto &i: make_range(0,len)){
if(s[i]=='('){
al.push_back(i);
}else if(s[i]==')'){
ar.push_back(i);
}else if(s[i]=='^'){
ah[i]++;
}else if(s[i]=='*'){
ast.push_back(i);
}
}
for(auto &i: make_range(1,len))ah[i]+=ah[i-1];
int ret=0;
for(auto &l:al){
bool f=false;
for(auto &r:ar){
if(l>=r)continue;
if(f){ret++;continue;}
auto lr=make_range(l,r);
int hidx=distance(ah.begin(),lower_bound(ah.begin(),ah.end(),ah[l]+2));
if(hidx>=r)continue;
auto st=lower_bound(ast.begin(),ast.end(),hidx);
if(st!=ast.end()&&*st<r){
ret++;
f=true;
}
}
}
return ret;
}
int main(){
string s;
getline(cin,s);
cout<<solve(s)<<' ';
reverse(s.begin(),s.end());
for(auto &e:s){
if(e=='(')e=')';
else if(e==')')e='(';
}
cout<<solve(s)<<endl;
}