結果

問題 No.457 (^^*)
ユーザー ei1333333ei1333333
提出日時 2016-12-08 21:16:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 146,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 02:31:11
合計ジャッジ時間 3,276 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define reps(i, j, n) for(int i = int(j); i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

int calc(string &S)
{
  int sum1[10001], sum2[10000] = {};
  memset(sum1, -1, sizeof(sum1));
  rep(i, S.size()) {
    sum1[i + 1] = sum1[i];
    if(S[i] == '*') sum1[i + 1] = i;
  }
  rep(i, S.size()) {
    sum2[i + 1] += sum2[i];
    if(S[i] == '^') sum2[i + 1]++;
  }

  int ret = 0;
  rep(i, S.size()) {
    if(S[i] == '(') {
      reps(j, i + 1, S.size()) {
        if(S[j] == ')') {
          if(sum1[j + 1] == -1) continue;
          ret += sum2[sum1[j + 1]] - sum2[i] >= 2;
        }
      }
    }
  }
  return (ret);
}

int main()
{
  string S;
  cin >> S;
  string T = S;
  reverse(begin(T), end(T));
  for(char &c : T) {
    if(c == '(') c = ')';
    else if(c == ')') c = '(';
  }
  cout << calc(S) << " " << calc(T) << endl;
}
0