結果

問題 No.2924 <===Super Spaceship String===>
ユーザー れいん
提出日時 2024-11-13 00:24:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,050 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 197,208 KB
最終ジャッジ日時 2025-02-25 04:00:53
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 3 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    vector<int> lt;
    vector<int> gt;
    vector<int> eq;
    int N = S.size();
    for (int i = 0; i < N; i++)
    {
        if (S[i] == '<')
        {
            lt.push_back(i);
        }
        if (S[i] == '>')
        {
            gt.push_back(i);
        }
        if (S[i] == '=')
        {
            eq.push_back(i);
        }
    }
    vector<int> lt_tmp = lt;
    reverse(lt.begin(), lt.end());
    int current_place = lt[0] + 1;
    int lt_N = lt.size();
    int ans = N;
    for (int i = 0; i < lt_N; i++)
    {
        auto it_gt = lower_bound(gt.begin(), gt.end(), current_place);
        auto it_eq = lower_bound(eq.begin(), eq.end(), current_place);
        auto it_lt = lower_bound(lt_tmp.begin(), lt_tmp.end(), current_place);

        if (it_gt == gt.end() || it_eq == eq.end())
        {
            if (i != lt_N - 1)
            {
                current_place = lt[i + 1] + 1;
            }
            continue; // 後で変更
        }
        int lt_place;
        if (it_lt == lt.end())
        {
            lt_place = 1e9;
        }
        else
        {
            lt_place = *it_lt;
        }
        int gt_place = *it_gt;
        int eq_place = *it_eq;

        if (!(eq_place < gt_place && gt_place < lt_place)) //=><の順番では無ければ
        {
            if (i != lt_N - 1)
            {
                current_place = lt[i + 1] + 1;
            }
            continue; // 後で変更
        }
        ans -= gt_place - eq_place + 2;
        auto next_lt = lower_bound(lt_tmp.begin(), lt_tmp.end(), lt[i]);
        auto next_gt = upper_bound(gt.begin(), gt.end(), gt_place);
        if (next_lt == lt.begin() || next_gt == gt.end())
        {
            if (i != lt_N - 1)
            {
                current_place = lt[i + 1] + 1;
            }
        }
        else // 現在の<>が内側の<>だった場合
        {
            current_place = gt_place + 1;
        }
    }
    cout << ans;
}
0