結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
Adamantite
|
| 提出日時 | 2023-06-28 00:00:04 |
| 言語 | C# (.NET 10.0.201) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 5,000 ms |
| コード長 | 1,576 bytes |
| 記録 | |
| コンパイル時間 | 8,473 ms |
| コンパイル使用メモリ | 171,960 KB |
| 実行使用メモリ | 193,188 KB |
| 最終ジャッジ日時 | 2026-03-26 00:07:08 |
| 合計ジャッジ時間 | 8,538 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (94 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net10.0/main.dll main -> /home/judge/data/code/bin/Release/net10.0/publish/
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
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();
bool leftFlag = false;
int count = 0;
Stack<(char C, int I)> stack = new Stack<(char, int)> ();
for(int i = 0; i < n; i++) {
stack.Push((s[i], i));
if (i == k - 1) {
if (s[i] == '(') {
leftFlag = true;
} else {
while (true) {
var pop = stack.Pop();
if (pop.C == '(') {
Console.WriteLine(pop.I + 1);
return;
}
}
}
}
if (s[i] == '(') {
count++;
} else {
if (0 < count) {
while (stack.Pop().C != '(') { }
count--;
}
}
if (leftFlag) {
if (stack.Count == 0 || stack.First().I < k - 1) {
Console.WriteLine(i + 1);
return;
}
}
}
}
}
}
Adamantite