제출 #681407

#제출 시각아이디문제언어결과실행 시간메모리
681407vjudge1괄호 문자열 (CEOI16_match)C++14
10 / 100
43 ms15956 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define all(a) a.begin(), a.end() typedef long long ll; typedef pair<int, int> ii; const int N = 2000 + 5; const int mod = 1e9 + 7; vector<int> pos['z' + 1]; int f[N][N]; string s; string t; int n; int dp(int l, int r) { if(l > r) return 1; if((r - l + 1) & 1) return 0; int &res = f[l][r]; if(~res) return res; if(s[l] == s[r]) { if(dp(l + 1, r - 1)) { t[l] = '(', t[r] = ')'; return res = 1; } } // int tmp = lower_bound(all(pos[s[l]]), r) - pos[s[l]].begin() - 1; // while(tmp >= 0 && pos[s[l]][tmp] > l) // { // int i = pos[s[l]][tmp]; for(int i = r - 1; i > l; i--) if(s[l] == s[i]) { if(dp(l + 1, i - 1) && dp(i + 1, r)) { t[l] = '(', t[i] = ')'; return res = 1; } // tmp--; } return res = 0; } void solve() { cin >> s; int n = s.size(); t.resize(n); for(int i = 0; i < n; i++) pos[s[i]].pb(i); memset(f, -1, sizeof f); if(dp(0, n - 1)) cout << t; else cout << -1; } signed main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while(t--) solve(); return 0; }

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

match.cpp: In function 'void solve()':
match.cpp:58:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   58 |         pos[s[i]].pb(i);
      |                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...