結果

問題 No.22 括弧の対応
コンテスト
ユーザー treeone
提出日時 2016-01-03 12:50:09
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 792 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 499 ms
コンパイル使用メモリ 96,448 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-07 21:17:25
合計ジャッジ時間 1,345 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge-tmp_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:45:11: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   45 |         o(ans);
      |           ^~~
main.cpp:13:20: note: in definition of macro 'o'
   13 | #define o(a) cout<<a<<endl
      |                    ^
main.cpp:30:23: note: 'ans' was declared here
   30 |         int f=0,key=0,ans;
      |                       ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	k--;
	int f=0,key=0,ans;
	vi d(n);
	rep(i,0,n){
		if(s[i]=='('){
			f++;
			d[i]=f;
		}else{
			d[i]=f;
			f--;
		}
		if(i==k) key=d[i];
	}
	rep(i,0,n){
		if(d[i]==key && i!=k) ans=i+1;
	}
	o(ans);
}
0