제출 #476718

#제출 시각아이디문제언어결과실행 시간메모리
476718wiktoria_bazan괄호 문자열 (CEOI16_match)C++14
0 / 100
0 ms204 KiB
#include <iostream> #include <stack> #include <algorithm> #include <string> #include <vector> using namespace std; int const N = 1e5 + 9; int n; string s; stack <char> S; int ile[N][30]; int nt[30]; vector<int> V[30]; int check(int in) { int a = s[in] - 'a'; for (int i = V[a].size() - 1; i >= 0; i--) { int nIn = V[a][i]; if (nIn <= in) return -1; bool t = true; for (int j = 0; j < 30; j++) { nt[j] = ile[nIn][j]; if(in > 0) nt[j] -= ile[in - 1][j]; if (nt[j] % 2 == 1) t = false; } if (t == true) return nIn; } } void task() { string w = ""; for (int i = 0; i < n; i++) { V[s[i] - 'a'].push_back(i); if (i > 0) { for (int j = 0; j < 30; j++) ile[i][j] = ile[i - 1][j]; } ile[i][s[i] - 'a']++; w.insert(w.size(), "0"); } for (int i = 0; i < n; i++) { if (w[i] == ')') continue; w[i] = '('; int ch = check(i); if (ch == -1) { cout << -1; return; } w[ch] = ')'; } cout << w; return; } int main() { cin >> s; n = s.size(); task(); }

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

match.cpp: In function 'int check(int)':
match.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type]
   31 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...