Submission #202300

#TimeUsernameProblemLanguageResultExecution timeMemory
202300quocnguyen1012Match (CEOI16_match)C++14
100 / 100
21 ms12148 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int maxn = 1e5 + 5; int N; int last[maxn][26]; string str; char res[maxn]; void match(int l, int r) { if (l > r) return; if (l % 2 == r % 2){ cout << -1; exit(0); } int mid = last[r][str[l] - 'a']; res[l] = '('; res[mid] = ')'; match(l + 1, mid - 1); match(mid + 1, r); } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } cin >> str; N = str.size(); str = " " + str; for (int i = 0; i < 26; ++i){ last[0][i] = 1; } for (int i = 1; i <= N; ++i){ for (int j = 0; j < 26; ++j){ if (str[i] - 'a' == j){ last[i][j] = i; } else{ last[i][j] = last[last[i - 1][str[i] - 'a'] - 1][j]; } } } match(1, N); for (int i = 1; i <= N; ++i){ cout << res[i]; } }

Compilation message (stderr)

match.cpp: In function 'int main()':
match.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
match.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...