結果
| 問題 |
No.457 (^^*)
|
| コンテスト | |
| ユーザー |
TangentDay
|
| 提出日時 | 2016-12-08 01:58:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,616 bytes |
| コンパイル時間 | 671 ms |
| コンパイル使用メモリ | 85,556 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-28 04:13:40 |
| 合計ジャッジ時間 | 1,349 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
int calc(string s){
int n = s.length();
VVI dp(n+1, VI(5));
REP(i,n){
if (s[i] == '('){
dp[i+1][0] = dp[i][0] + 1;
dp[i+1][1] = dp[i][1];
dp[i+1][2] = dp[i][2];
dp[i+1][3] = dp[i][3];
}else if (s[i] == '*'){
dp[i+1][1] = dp[i][1] + dp[i][0];
dp[i+1][2] = dp[i][2];
dp[i+1][3] = dp[i][3];
}else if (s[i] == '^'){
dp[i+1][0] = dp[i][0];
dp[i+1][2] = dp[i][1];
dp[i+1][3] = dp[i][3] + dp[i][2];
}else{
dp[i+1][0] = dp[i][0];
dp[i+1][1] = dp[i][1];
dp[i+1][2] = dp[i][2];
dp[i+1][3] = dp[i][3];
dp[i+1][4] = dp[i][3];
}
}
int res = 0;
REP(i,n+1) res += dp[i][4];
return res;
}
int main() {
string s;
cin >> s;
int a = calc(s);
reverse(s.begin(), s.end());
REP(i,s.length()){
if (s[i] == '(') s[i] = ')';
else if (s[i] == ')') s[i] = '(';
}
int b = calc(s);
printf("%d %d\n", b, a);
return 0;
}
TangentDay