結果

問題 No.457 (^^*)
ユーザー nebukuro09nebukuro09
提出日時 2016-12-08 03:12:56
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 1,213 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 96,520 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-02 23:21:35
合計ジャッジ時間 2,785 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import std.bigint;


void main() {
  auto S = readln.chomp;
  auto N = S.length.to!int;
  auto right_p = new int[](N+1);
  foreach (i; 0..N)
    if (S[i] == ')')
      right_p[i+1] = 1;
  foreach (i; 0..N)
    right_p[i+1] += right_p[i];

  int l_ans;
  foreach (i; 0..N) {
    int left;
    if (S[i] == '(') {
      foreach (j; i+1..N) {
        if (S[j] == '^')
          left = (left < 3) ? min(2, left+1) : 3;
        else if (S[j] == '*')
          left = (left == 2) ? 3 : left;
        if (left == 3) {
          l_ans += right_p[N] - right_p[j];
          break;
        }
      }
    }
  }

  int r_ans;
  foreach (i; 0..N) {
    int right;
    if (S[i] == '(') {
      foreach (j; i+1..N) {
        if (S[j] == '*')
          right = (right == 0) ? 1 : right;
        else if (S[j] == '^')
          right = (right > 0) ? min(3, right+1) : 0;
        if (right == 3) {
          r_ans += right_p[N] - right_p[j];
          break;
        }
      }
    }
  }

  writeln(l_ans, " ", r_ans);

}
0