Submission #1117740

#TimeUsernameProblemLanguageResultExecution timeMemory
1117740vjudge1Match (CEOI16_match)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; # define int long long void solve() { int cnt = 1; string s; cin >> s; vector < char > bra(s.size(), '*'); vector < int > chk(s.size() , 0); for(int i = 0; i < s.size(); i++) { for(int j = s.size() - 1; j >= 0; j--) { if(s[i] == s[j] && bra[i] == '*' && bra[j] == '*') { bra[i] = '('; bra[j] = ')'; chk[i] = cnt; chk[j] = cnt; cnt++; break; } } } for(int i = 0; i < bra.size(); i++) { if(bra[i] == '*') { cout << -1 << endl; return ; } } for(int i = 0; i < s.size(); i++) { for(int j = i + 1; j < s.size(); j++) { if(s[i] == s[j] && chk[i] == chk[j]) { if(j - i == 1) { if(s[i + 1] != s[i]) { cout << -1 << endl; return; } else continue; } if(j - i == 0) { continue; } int ind1 = -1, ind2 = -1; for(int ic = i + 1; ic < j; ic++) { for(int jc = i + 2; jc < j; jc++) { if(s[ic] == s[jc]) { ind1 = ic; ind2 = jc; break; } } if(ind1 == -1 || ind2 == -1) { cout << -1 << endl; return ; } } } } } for(int i = 0; i < bra.size(); i++) cout << bra[i] << ' '; cout << endl; } signed main() { int tt = 1; // cin >> tt; while(tt--) solve(); }

Compilation message (stderr)

match.cpp: In function 'void solve()':
match.cpp:12:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for(int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
match.cpp:27:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i = 0; i < bra.size(); i++)
      |                  ~~^~~~~~~~~~~~
match.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i = 0; i < s.size(); i++)
      |                  ~~^~~~~~~~~~
match.cpp:37:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int j = i + 1; j < s.size(); j++)
      |                        ~~^~~~~~~~~~
match.cpp:76:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int i = 0; i < bra.size(); i++)
      |                  ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...