結果

問題 No.2924 <===Super Spaceship String===>
ユーザー tnakao0123tnakao0123
提出日時 2024-10-13 17:50:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 790 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 55,640 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 17:50:10
合計ジャッジ時間 976 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 4 ms
5,248 KB
testcase_08 AC 4 ms
5,248 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2924.cc:  No.2924 <===Super Spaceship String===> - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 500000;

/* typedef */

using sti = stack<int>;

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  int l = -1, r = -1, sum = 0;
  sti q;

  for (int i = 0; i < n; i++) {
    if (s[i] == '<')
      q.push(i);
    else if (s[i] == '>') {
      if (! q.empty()) {
	int u = q.top(); q.pop();
	if (u + 1 < i) {
	  if (r <= u) sum += r - l;
	  l = u, r = i + 1;
	}
	else
	  while (! q.empty()) q.pop();
      }
    }
  }
  if (l < r) sum += r - l;

  printf("%d\n", n - sum);

  return 0;
}
0