結果

問題 No.22 括弧の対応
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2019-01-10 03:24:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 584 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 70,200 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 13:33:03
合計ジャッジ時間 1,303 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:44:31: 警告: ‘mark’ may be used uninitialized [-Wmaybe-uninitialized]
   44 |                 if (T[i] == m && S[i] != mark)
main.cpp:33:14: 備考: ‘mark’ はここで定義されています
   33 |         char mark;
      |              ^~~~
main.cpp:44:31: 警告: ‘m’ may be used uninitialized [-Wmaybe-uninitialized]
   44 |                 if (T[i] == m && S[i] != mark)
main.cpp:32:13: 備考: ‘m’ はここで定義されています
   32 |         int m;
      |             ^

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

int main()
{
	int n, k;
	string S;
	cin >> n >> k >> S;

	vector<int> T(n);

	int i = 0, j = 0;
	bool flg = false;
	while (!flg)
	{
		while (S[i] != ')' || T[i] != 0)
		{
			i++;
		}
		T[i] = ++j;
		flg = i == n - 1 ? true : false;
		while (T[i] > 0)
		{
			i--;
		}
		T[i] = j;
	}
	int m;
	char mark;
	rep(i, n)
	{
		if (i + 1 == k)
		{
			m = T[i];
			mark = S[i];
		}
	}
	rep(i, n)
	{
		if (T[i] == m && S[i] != mark)
		{
			cout << i + 1 << endl;
		}
	}
}
0