結果

問題 No.457 (^^*)
ユーザー zaichuzaichu
提出日時 2017-10-29 19:28:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 164,920 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 09:47:18
合計ジャッジ時間 2,673 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long x, long long y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    string S;
    cin >> S;
    int N = S.size();
    int ans1 = 0, ans2 = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == '(')
        {
            int cnt1 = 0, cnt2 = 0;
            bool flag1 = false, flag2 = false;
            for (int j = i + 1; j < N; j++)
            {
                if (cnt1 < 2 && S[j] == '^')
                    cnt1++;
                else if (cnt1 == 2 && S[j] == '*')
                    flag1 = true;

                if (cnt2 == 0 && S[j] == '*')
                    flag2 = true;
                else if (flag2 && cnt2 < 2 && S[j] == '^')
                    cnt2++;

                if (flag1 && S[j] == ')')
                    ans1++;
                if (cnt2 == 2 && S[j] == ')')
                    ans2++;
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
}
0