結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2025-01-11 12:14:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 611 bytes |
コンパイル時間 | 1,560 ms |
コンパイル使用メモリ | 67,200 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-11 12:14:29 |
合計ジャッジ時間 | 3,178 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d%d",&n,&k); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<iostream>#include<stack>#define rep(i,n) for(i=0;i<(int)(n);i++)using namespace std;typedef long long ll;typedef unsigned long long ull;int n,k;int main(){int i,j;scanf("%d%d",&n,&k);stack<int> sta;k--;getchar();rep(i,n){if(getchar()=='(')sta.push(i);else{j=sta.top();if(j==k){printf("%d\n",i+1);return 0;}if(i==k){printf("%d\n",j+1);return 0;}sta.pop();}}return 0;}