結果
問題 | No.22 括弧の対応 |
ユーザー | Adamantite |
提出日時 | 2023-06-28 00:16:12 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 52 ms / 5,000 ms |
コード長 | 1,125 bytes |
コンパイル時間 | 11,015 ms |
コンパイル使用メモリ | 147,436 KB |
実行使用メモリ | 163,680 KB |
最終ジャッジ日時 | 2023-09-17 22:58:18 |
合計ジャッジ時間 | 12,401 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
30,328 KB |
testcase_01 | AC | 50 ms
28,380 KB |
testcase_02 | AC | 51 ms
30,380 KB |
testcase_03 | AC | 50 ms
28,484 KB |
testcase_04 | AC | 50 ms
28,420 KB |
testcase_05 | AC | 51 ms
28,316 KB |
testcase_06 | AC | 51 ms
28,436 KB |
testcase_07 | AC | 51 ms
28,488 KB |
testcase_08 | AC | 50 ms
28,400 KB |
testcase_09 | AC | 50 ms
30,436 KB |
testcase_10 | AC | 50 ms
28,552 KB |
testcase_11 | AC | 51 ms
28,284 KB |
testcase_12 | AC | 50 ms
28,512 KB |
testcase_13 | AC | 50 ms
28,324 KB |
testcase_14 | AC | 50 ms
28,520 KB |
testcase_15 | AC | 52 ms
28,464 KB |
testcase_16 | AC | 52 ms
30,344 KB |
testcase_17 | AC | 51 ms
30,328 KB |
testcase_18 | AC | 50 ms
163,680 KB |
コンパイルメッセージ
Determining projects to restore... Restored /home/judge/data/code/main.csproj (in 128 ms). .NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f Copyright (C) Microsoft Corporation.All rights reserved. プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください main -> /home/judge/data/code/bin/Release/net6.0/main.dll main -> /home/judge/data/code/bin/Release/net6.0/publish/
ソースコード
using System; using System.Collections.Generic; namespace No22_ParenthesesCorrespondence { internal class Program { static void Main(string[] args) { string[] param = Console.ReadLine().Split(' '); int n = int.Parse(param[0]); int k = int.Parse(param[1]); string s = Console.ReadLine(); Stack<char> stack = new Stack<char>(); int count = 0; char countChar = ' '; int inc = 0; if (s[k - 1] == '(') { countChar = '('; inc = 1; } else { countChar = ')'; inc = -1; } for (int i = k - 1; i < n; i += inc) { stack.Push(s[i]); if (s[i] == countChar) { count++; } else { while (stack.Pop() != countChar) { } count--; } if (stack.Count == 0) { Console.WriteLine(i + 1); return; } } } } }