結果

問題 No.457 (^^*)
ユーザー cielciel
提出日時 2016-12-08 21:50:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 75,628 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 02:35:38
合計ジャッジ時間 2,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 459 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 458 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int solve(const string &s){
	int len=s.size();
	vector<int>al;
	vector<int>ar;
	vector<int>ah(len);
	vector<int>ast;
	for(int i=0;i<len;i++){
		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(int i=1;i<len;i++)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;}
			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;
}
0