제출 #699023

#제출 시각아이디문제언어결과실행 시간메모리
699023cpLover22Match (CEOI16_match)C++17
10 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define siz(x) (int)x.size() const int N = 1e5 + 5; int n, c[N][26]; vector<int> pos[26]; string st; char res[N]; bool flag = 1; void mat(int l, int r) { if (l > r) return; int p, t = st[l] - 'a'; for (p = siz(pos[t]) - 1; p >= 0; --p) { bool flag = 1; int cp = pos[t][p]; if (cp > r || cp <= l) continue; for (int i = 0; i < 26; ++i) if ((c[cp][i] - c[l - 1][i]) % 2) { // cerr << i << ' ' << l << ' ' << cp << '\n'; flag = 0; break; } if (flag) break; } // cerr << l << ' ' << r << ":\n"; if (p == -1) return flag = 0, void(); p = pos[t][p]; // cerr << l << ' ' << r << ' ' << p << '\n'; res[l] = '(', res[p] = ')'; // cerr << l << ' ' << p << '\n'; mat(l + 1, p - 1); mat(p + 1, r); } int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); if (fopen("match.in", "r")) { freopen("match.in", "r", stdin); freopen("match.out", "w", stdout); freopen("log.txt", "w", stderr); } cin >> st; n = st.size(); st = ' ' + st; for (int i = 1; i <= n; ++i) pos[st[i] - 'a'].eb(i); for (int i = 1; i <= n; ++i) for (int j = 0; j < 26; ++j) c[i][j] = c[i - 1][j] + (st[i] - 'a' == j); // cerr << "? " << c[] mat(1, n); if (!flag) cout << -1; else { for (int i = 1; i <= n; ++i) cout << res[i]; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

match.cpp: In function 'int main()':
match.cpp:40:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     freopen("match.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
match.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen("match.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
match.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen("log.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...