Submission #867547

#TimeUsernameProblemLanguageResultExecution timeMemory
86754742kangarooparentrises (BOI18_parentrises)C++17
0 / 100
0 ms348 KiB
// // Created by 42kangaroo on 28/10/2023. // #include "bits/stdc++.h" using namespace std; #define int long long array<char,3> col{'G', 'R', 'B'}; signed main() { int p, t; cin >> p >> t; while (t--) { if (p == 1) { string s; cin >> s; bool pos = true; vector<int> co(s.size(),0); deque<int> closeInd; deque<int> openInd; int act = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == '(') { ++act; } else { closeInd.push_back(i); --act; if (act < 0) { if (closeInd.size() < 2) { cout << "impossible\n"; pos = false; break; } else { co[closeInd.front()] = 1; closeInd.pop_front(); co[closeInd.front()] = 2; closeInd.pop_front(); ++act; } } } } act = 0; for(int i = s.size() - 1; i >= 0; --i) { if (s[i] == '(') { openInd.push_back(i); --act; if (act < 0) { if (openInd.empty()) { cout << "impossible\n"; pos = false; break; } else { co[openInd.front()] = 2; openInd.pop_front(); ++act; } } } else if (co[i] < 2){ ++act; } } openInd.clear(); for(int i = s.size() - 1; i >= 0; --i) { if (s[i] == '(' && (co[i] == 0 || co[i] == 2)) { if (co[i] == 0) { openInd.push_back(i); } --act; if (act < 0) { if (openInd.empty()) { cout << "impossible\n"; pos = false; break; } else { co[openInd.front()] = 1; openInd.pop_front(); ++act; } } } else if (s[i] == ')' && (co[i] == 0 || co[i] == 2)){ ++act; } } if (pos) { for (auto e: co) { cout << col[e]; } cout << "\n"; } } } }

Compilation message (stderr)

parentrises.cpp: In function 'int main()':
parentrises.cpp:22:22: 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]
   22 |    for (int i = 0; i < s.size(); ++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...