Submission #306852

#TimeUsernameProblemLanguageResultExecution timeMemory
306852joylintpHandcrafted Gift (IOI20_gift)C++14
100 / 100
265 ms17632 KiB
#include"gift.h" #include<bits/stdc++.h> using namespace std; int construct (int n, int r, vector<int> a, vector<int> b, vector<int> x) { vector<pair<int, int>> v; for (int i = 0; i < r; i++) if (x[i] == 1) v.push_back({a[i], b[i]}); sort(v.begin(), v.end()); vector<pair<int, int>> same; for (int i = 0; i < v.size(); i++) if (same.empty()) same.push_back(v[i]); else if (same.back().second + 1 >= v[i].first) same.back().second = max(same.back().second, v[i].second); else same.push_back(v[i]); string s; for (int i = 0; i < same.size(); i++) { for (int j = (i == 0 ? 0 : same[i - 1].second + 1); j <= same[i].first; j++) if (s.empty()) s += 'R'; else if (s.back() == 'R') s += 'B'; else s += 'R'; for (int j = same[i].first + 1; j <= same[i].second; j++) if (s.empty()) s += 'R'; else s += s.back(); } for (int i = (s.empty() ? 0 : same.back().second + 1); i < n; i++) if (s.empty()) s += 'R'; else if (s.back() == 'R') s += 'B'; else s += 'R'; vector<int> v2; for (auto p : same) v2.push_back(p.first), v2.push_back(p.second); for (int i = 0; i < r; i++) { if (x[i] == 1) continue; if (a[i] == b[i]) return 0; int pos = upper_bound(v2.begin(), v2.end(), a[i]) - v2.begin() - 1; if (pos != -1 && pos % 2 == 0 && b[i] <= v2[pos + 1]) return 0; } craft(s); return 1; }

Compilation message (stderr)

gift.cpp: In function 'int construct(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
gift.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
gift.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 0; i < same.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...