結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー tobbie
提出日時 2025-05-28 14:12:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 999 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 194,532 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-05-28 14:12:37
合計ジャッジ時間 4,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  char st[n];
  int sti = 0;
  bool itvl = false;
  rep(i, n) {
    if (s[i] == '(') {
      st[sti] = s[i];
      sti++;
    }
    if (s[i] == ')') {
      if (st[sti - 1] == '(')
	sti--;
      else {
	cout << "No" << endl;
	return 0;
      }
      if (i < n-1 && sti == 0)
	itvl = true;
    }
  }
  if (sti > 0 || !itvl) {
    cout << "No" << endl;
    return 0;
  }
  string t = "";
  int c = 0;
  rep(i, n) {
    if (s[i] == '(') {
      if (i > 0 && (t[(int)t.size() - 1] == ')')) {
	t += "+";
      }
      t += s[i];
    }
    if (s[i] == ')') {
      if (t[(int)t.size() - 1] == '(') {
	t += "1+1";
	c += 2;
      } else {
	t += "+1";
	c += 1;
      }
      t += s[i];
    }
  }
  while (c < k) {
    t += "+1";
    c++;
  }
  if (k == c)
    cout << "Yes" << endl << t << endl;
  else
    cout << "No" << endl;
  return 0;
}
0