結果

問題 No.457 (^^*)
ユーザー femtofemto
提出日時 2016-12-09 16:13:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 167,160 KB
実行使用メモリ 11,556 KB
最終ジャッジ日時 2023-08-19 03:13:31
合計ジャッジ時間 2,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 6 ms
11,200 KB
testcase_03 AC 5 ms
11,148 KB
testcase_04 WA -
testcase_05 AC 5 ms
11,224 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 6 ms
11,264 KB
testcase_13 AC 6 ms
11,200 KB
testcase_14 AC 5 ms
11,280 KB
testcase_15 AC 6 ms
11,244 KB
testcase_16 AC 6 ms
11,180 KB
testcase_17 AC 6 ms
11,212 KB
testcase_18 AC 5 ms
11,152 KB
testcase_19 AC 5 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll dp[100010][10];

struct Sum {
	vector<ll> v;
	Sum(int n, ll* a) {
		v.assign(n + 1, 0);
		for(int i = 0; i < n; i++) {
			v[i + 1] = v[i] + a[i];
		}
	}

	// [l, r]
	ll query(int l, int r) {
		return v[r + 1] - v[l];
	}
};

ll f(string s, string t) {
	memset(dp, 0, sizeof dp);
	dp[0][0] = 1;

	ll ret = 0;
	for(int i = 0; i < s.size(); i++) {
		for(int j = 0; j < t.size(); j++) {
			if(s[i] == t[j]) {
				if(j == t.size() - 1) ret += dp[i][j];
				else dp[i + 1][j + 1] += dp[i][j];
			}
			if(s[i] == '(' || s[i] == ')') {
				dp[i + 1][j] += dp[i][j];
			}
		}
	}

	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	cout << f(s, "(^^*)") << " " << f(s, "(*^^)") << endl;
}
0