結果
問題 | No.457 (^^*) |
ユーザー |
|
提出日時 | 2017-02-16 22:15:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 801 ms |
コンパイル使用メモリ | 72,068 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-30 01:10:42 |
合計ジャッジ時間 | 1,975 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <iostream> #include <vector> #include <string> using namespace std; int main() { string s; cin >> s; int pos = s.find('('); s = pos == string::npos ? "" : s.substr(pos); s = s.substr(0, s.rfind(')') + 1); int n = s.size(); vector<int> closes(n + 1 , 0); for (int i = n - 1; i >= 0; i--) { closes[i] = closes[i + 1]; if (s[i] == ')') { closes[i]++; } } const string sl = "(^^*)"; const string sr = "(*^^)"; int l_count = 0; int r_count = 0; for (int i = 0; i < n; i++) { if (s[i] != '(') { continue; } int l_idx = 1; int r_idx = 1; for (int j = i + 1; j < n; j++) { if (l_idx <= 3 && s[j] == sl[l_idx]) { l_idx++; if (l_idx == 4) { l_count += closes[j]; if (r_idx == 4) { break; } } } if (r_idx <= 3 && s[j] == sr[r_idx]) { r_idx++; if (r_idx == 4) { r_count += closes[j]; if (l_idx == 4) { break; } } } } } cout << l_count << " " << r_count << endl; return 0; }