結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-05-17 12:53:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,009 bytes |
| コンパイル時間 | 615 ms |
| コンパイル使用メモリ | 40,832 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-17 12:53:21 |
| 合計ジャッジ時間 | 3,244 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d%d%s", &n, &k, s);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3143.cc: No.3143 Colorless Green Parentheses Sleep Furiously - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_M = MAX_N * 5;
/* typedef */
/* global variables */
char s[MAX_N + 4], t[MAX_M + 4];
int vs[MAX_N + 1];
/* subroutines */
/* main */
int main() {
int n, k;
scanf("%d%d%s", &n, &k, s);
int f = 0, m = 0, d = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
vs[d++]++, vs[d] = 0;
if (m > 0 && t[m - 1] == ')') t[m++] = '+';
t[m++] = '(';
}
else {
if (vs[d] == 0) t[m++] = '1', f++, vs[d] = 1;
if (vs[d] < 2) t[m++] = '+', t[m++] = '1', f++, vs[d]++;
t[m++] = ')';
if (--d < 0) { puts("No"); return 0; }
}
}
if (d > 0 || f > k) { puts("No"); return 0; }
while (f < k) t[m++] = '+', t[m++] = '1', f++, vs[0]++;
t[m] = '\0';
if (vs[0] >= 2) puts("Yes"), puts(t);
else puts("No");
return 0;
}
tnakao0123