結果

問題 No.457 (^^*)
ユーザー imulanimulan
提出日時 2016-12-08 00:27:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,671 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 165,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 20:47:16
合計ジャッジ時間 2,495 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 53 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 52 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 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;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int N=10000;
int l[N]={}, r[N]={};
int L=0,R=0;

// i文字目から左側で最も近い*の位置、i文字目から右側で最も近い*の位置
int astl[N], astr[N];

// ^の個数の累積和
int hat[N]={};

int main()
{
    string s;
    cin >>s;

    int S=s.size();
    rep(i,S)
    {
        if(s[i]=='(') l[L++]=i;
        else if(s[i]==')') r[R++]=i;
        else if(s[i]=='^') ++hat[i];
    }

    for(int i=1; i<N; ++i) hat[i]+=hat[i-1];

    memset(astl,-1,sizeof(astl));
    memset(astr,-1,sizeof(astr));

    if(s[0]=='*') astl[0]=0;
    for(int i=1; i<S; ++i)
    {
        if(s[i]=='*') astl[i]=i;
        else astl[i]=max(astl[i],astl[i-1]);
    }

    if(s[S-1]=='*') astr[S-1]=S-1;
    for(int i=S-2; i>=0; --i)
    {
        if(s[i]=='*') astr[i]=i;
        else
        {
            if(astr[i+1]!=-1) astr[i]=astr[i+1];
        }
    }

    ll x=0,y=0;
    rep(i,L)rep(j,R)if(l[i]<r[j])
    {
        // *の位置,間にある^の個数
        int a_pos,hats;

        // 左向き
        a_pos = astl[r[j]];
        if(a_pos!=-1)
        {
            hats = hat[a_pos] - hat[l[i]];
            if(hats>=2) ++x;
        }

        // 右向き
        a_pos = astr[l[i]];
        if(a_pos!=-1)
        {
            hats = hat[r[j]] - hat[a_pos];
            if(hats>=2) ++y;
        }
    }

    printf("%lld %lld\n", x,y);
    return 0;
}
0