제출 #874873

#제출 시각아이디문제언어결과실행 시간메모리
874873Muhammad_Aneeq괄호 문자열 (CEOI16_match)C++17
0 / 100
0 ms348 KiB
/* بسم الله الرحمن الرحيم Author: (:Muhammad Aneeq:) */ #pragma GCC optimize("O2") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <iostream> #include <map> #include <vector> #include <algorithm> using namespace std; inline void solve() { string x; cin>>x; int n=x.size(); map<char,vector<int>>d; for (int i=0;i<n;i++) d[x[i]].push_back(i); for (auto i:d) { if (i.second.size()%2) { cout<<-1<<endl;return; } } string ans=string(n,' '); for (auto i:d) { vector<int>x,y; for (auto j:i.second) if (j%2) x.push_back(j); else y.push_back(j); if (x.size()!=y.size()) { cout<<-1<<endl;return; } if (x[0]>y[0]) swap(x,y); reverse(y.begin(), y.end()); for (int i=0;i<x.size();i++) { int z=min(x[i],y[i]); ans[z]='('; ans[y[i]+x[i]-z]=')'; } } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); solve(); }

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

match.cpp: In function 'void solve()':
match.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i=0;i<x.size();i++)
      |                ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...