結果

問題 No.22 括弧の対応
ユーザー naimonon77
提出日時 2015-10-25 14:00:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 708 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 63,960 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:04:26
合計ジャッジ時間 1,194 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:12: warning: ‘rep’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |    cout << rep << endl;
      |            ^~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <stack>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define SQR(X) ((X)*(X))

typedef long long ll;
typedef unsigned long long ull;
typedef long double lb;
/* ここからが本編 */

int main(void)
{
   int i,j;
   int n,k;
   char c;
   int rep;
   stack<int> a;
   cin >> n >> k;
   for(i=1;i<=n;i++) {
      cin >> c;
      if(c == '(') a.push(i);
      else {
         if(k == i) {
            rep = a.top(); break;
         }
         else if(a.top() == k) {
            rep = i; break;
         }
         else a.pop();
      }
   }
   cout << rep << endl;
   return 0;
}
0