結果

問題 No.22 括弧の対応
ユーザー y_mazun
提出日時 2015-04-24 21:23:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 510 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 63,712 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 06:59:47
合計ジャッジ時間 1,327 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:5:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 | inline int getInt(){ int s; scanf("%d", &s); return s; }
      |                             ~~~~~^~~~~~~~~~

ソースコード

diff #

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <stack>
#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int k = getInt() - 1;
  string s; cin >> s;
  stack<int> st;

  REP(i,n){
    if(s[i] == '('){
      st.push(i);
    }else{
      const int p = st.top(); st.pop();
      if(p == k || i == k){
	printf("%d\n", p == k ? i + 1 : p + 1);
      }
    }
  }

  return 0;
}
0