Submission #365451

#TimeUsernameProblemLanguageResultExecution timeMemory
365451lookcookparentrises (BOI18_parentrises)C++17
50 / 100
66 ms4360 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 1000005; char res[maxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int p, t; cin >> p >> t; if (p == 1) { while (t--) { string s; cin >> s; bool ok = true; bool turn = true; int sr = 0; int sb = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '(') { res[i] = 'G'; sr++; sb++; } else { if (turn) { res[i] = 'R'; sr--; } else { res[i] = 'B'; sb--; } turn = !turn; } if (sr < 0 || sb < 0) ok = false; } if (sb>sr) { for (int i = s.length()-1; i >= 0; i--) { if (s[i] == '(') { res[i] = 'R'; break; } if (s[i] == ')' && res[i] == 'R') { res[i] = 'G'; break; } } } sr = 0; sb = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == ')') { if (res[i] == 'G') { sr--; sb--; } if (res[i] == 'R') sr--; if (res[i] == 'B') sb--; } else { if (res[i] == 'G') { sr++; sb++; } if (res[i] == 'R') sr++; if (res[i] == 'B') sb++; } if (sr < 0 || sb < 0) ok = false; } for (int i = s.length()-1; i >= 0; i--) { if (s[i] == '(' && res[i] == 'G') { if (sr>=sb && sr>0) { // maybe swap order? sr--; res[i] = 'B'; } else if (sb > 0) { sb--; res[i] = 'R'; } } if (s[i] == ')') { if (res[i] == 'R' && sb>0) { res[i] = 'G'; sb--; } else if (res[i] == 'B' && sr>0) { res[i] = 'G'; sr--; } } } sr = 0; sb = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == ')') { if (res[i] == 'G') { sr--; sb--; } if (res[i] == 'R') sr--; if (res[i] == 'B') sb--; } else { if (res[i] == 'G') { sr++; sb++; } if (res[i] == 'R') sr++; if (res[i] == 'B') sb++; } if (sr < 0 || sb < 0) ok = false; } if (ok && sr==0&&sb==0) { for (int i = 0; i < s.length(); i++) cout << res[i]; cout << '\n'; } else { cout << "impossible\n"; } } } }

Compilation message (stderr)

parentrises.cpp: In function 'int main()':
parentrises.cpp:23:31: 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]
   23 |             for (int i = 0; i < s.length(); i++) {
      |                             ~~^~~~~~~~~~~~
parentrises.cpp:54:31: 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]
   54 |             for (int i = 0; i < s.length(); i++) {
      |                             ~~^~~~~~~~~~~~
parentrises.cpp:94:31: 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]
   94 |             for (int i = 0; i < s.length(); i++) {
      |                             ~~^~~~~~~~~~~~
parentrises.cpp:113:35: 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]
  113 |                 for (int i = 0; i < s.length(); i++) cout << res[i];
      |                                 ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...