제출 #100751

#제출 시각아이디문제언어결과실행 시간메모리
100751Retro3014괄호 문자열 (CEOI16_match)C++17
100 / 100
128 ms87628 KiB
#include <bits/stdc++.h> #define pb push_back #define all(v) ((v).begin(), (v).end()) #define sortv(v) sort(all(v)) #define sz(v) ((int)(v).size()) #define uniqv(v) (v).erase(unique(all(v)), (v).end()) #define umax(a, b) (a)=max((a), (b)) #define umin(a, b) (a)=min((a), (b)) #define FOR(i,a,b) for(int i = (a); i <= (b); i++) #define rep(i,n) FOR(i,1,n) #define rep0(i,n) FOR(i,0,(int)(n)-1) #define FI first #define SE second #define INF 2000000000 #define INFLL 1000000000000000000LL using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX_N = 100010; const int MAX_K = 30; string str; vector<char> v; int cnt = 1, N; vector<int> gp[MAX_N+1][MAX_K+3]; int idx[MAX_N+1][MAX_K+2]; pii arr[MAX_N+1]; vector<pii> dq; int st[MAX_N+1]; void answer(int x, int y){ dq.push_back({x, y}); pii now; int p, s, e, m; while(!dq.empty()){ x = dq.back().first; y = dq.back().second; //cout<<x<<' '<<y<<endl; //getchar(); dq.pop_back(); if(x==y && y==-1){ printf(")"); continue; } if(x>=y) continue; now = arr[x]; now.first = st[x]; //cout<<now.first<<' '<<now.second<<endl; s = 0, e = gp[now.first][now.second].size()-1, m = 0; while(s<e){ m = (s+e)/+1; if(gp[now.first][now.second][m]<=y) s = m; else e = m-1; } p = gp[now.first][now.second][s]; //cout<<p<<endl; printf("("); dq.push_back({p+1, y}); dq.push_back({-1, -1}); dq.push_back({x+1, p-1}); } } int main(){ cin>>str; N = str.size(); for(int i=0; i<str.size(); i++){ if(!v.empty() && v.back()==str[i]) v.pop_back(); else v.push_back(str[i]); } if(!v.empty()){ cout<<-1; return 0; } int now = 1; for(int i=0; i<N; i++){ st[i] = now; if(!v.empty() && v.back()==str[i]){ now = idx[now][0]; v.pop_back(); }else{ if(idx[now][str[i]-'a'+1]!=0){ now = idx[now][str[i]-'a'+1]; }else{ idx[now][str[i]-'a'+1] = ++cnt; idx[cnt][0] = now; now = cnt; } v.push_back(str[i]); } gp[now][str[i]-'a'+1].push_back(i); arr[i] = {now, str[i]-'a'+1}; //cout<<arr[i].first<<" "<<arr[i].second<<endl; } answer(0, N-1); return 0; }

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

match.cpp: In function 'int main()':
match.cpp:71:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<str.size(); i++){
               ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...