Submission #1264287

#TimeUsernameProblemLanguageResultExecution timeMemory
1264287duyanhloveavMatch (CEOI16_match)C++20
100 / 100
12 ms12352 KiB
#include <bits/stdc++.h> using namespace std; #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1LL) using ll = long long; const int mxn = 9 + 1e5; const int inf = 0x3f3f3f3f; const ll lnf = 0x3f3f3f3f3f3f3f3f; int n, nxt[mxn][26]; char res[mxn]; string s; void solve(int l, int r) { if (l > r) return; int p = nxt[r][s[l] - 'a']; if (!p) { cout << "-1\n"; exit(0); } res[l] = '('; res[p] = ')'; solve(l + 1, p - 1); solve(p + 1, r); } void _27augain(void) { cin >> s; n = s.size(); s = '*' + s; for (int i = 1; i <= n; ++i) { for (int j = 0; j < 26; ++j) { if (s[i] - 'a' == j) { nxt[i][j] = i; } else { nxt[i][j] = nxt[max(0, nxt[i - 1][s[i] - 'a'] - 1)][j]; } } } solve(1, n); for (int i = 1; i <= n; ++i) { cout << res[i]; } } int32_t main(void) { #define task "27augain" cin.tie(0)->sync_with_stdio(0); for (string iext : {"in", "inp"}) { if (fopen((task "." + iext).c_str(), "r")) { freopen((task "." + iext).c_str(), "r", stdin); freopen(task ".out", "w", stdout); } } int testcase = 1; // cin >> testcase; while (testcase--) { _27augain(); } return 0; }

Compilation message (stderr)

match.cpp: In function 'int32_t main()':
match.cpp:54:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |       freopen((task "." + iext).c_str(), "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
match.cpp:55:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |       freopen(task ".out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...