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