Submission #1036547

#TimeUsernameProblemLanguageResultExecution timeMemory
1036547model_codeSprinklers (CEOI24_sprinklers)C++17
20 / 100
2068 ms1288 KiB
// Authors: Robert Jaworski #include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wsign-compare" using namespace std; bool check(int K, const std::vector<int>& s, const std::vector<int>& f, const vector<int>& c, bool verbose=false) { int i = 0; vector<int> cover(f.size(), 0); for (; i < s.size(); i++) { int l, r; if (c[i] == 0) { l = s[i] - K; r = s[i]; } else { l = s[i]; r = s[i] + K; } for (int j = 0; j < f.size(); j++) { if (l <= f[j] && f[j] <= r) { cover[j]++; } } } bool covered = true; for (auto&& x : cover) { covered = x > 0; if (!covered) break; } return covered; } bool bruteforce(int N, int M, int K, const vector<int>& s, const vector<int>& f, std::vector<int>& conf) { conf.resize(N, 0); for (int i = 0; i != N;) { if (check(K, s, f, conf)) return true; for (i = 0; i < N; i++) { conf[i] ^= 1; if (conf[i]) break; } } return false; } int main() { int N, M; cin >> N >> M; vector<int> s(N, 0), f(M, 0), conf; for (auto&& x : s) { cin >> x; } for (auto&& x : f) { cin >> x; } if (N == 1) { if (s.back() <= f[0]) { cout << (f.back() - s.back()) << endl << "R" << endl; } else if (s[0] >= f.back()) { cout << (s[0] - f[0]) << endl << "L" << endl; } else { cout << -1 << endl; } return 0; } int maxK = 1; int K, l, r; if (bruteforce(N, M, 0, s, f, conf)) { K = 0; goto END; } while (!bruteforce(N, M, maxK, s, f, conf)) maxK <<= 1; l = maxK / 2; r = maxK; while (l+1 < r) { int m = (l+r) / 2; if (bruteforce(N, M, m, s, f, conf)) { r = m; } else { l = m; } } K = r; if (!bruteforce(N, M, K, s, f, conf)) { cout << "Very bad" << endl; } END: cout << K << endl; for (auto&& x : conf) { cout << (x ? 'R' : 'L'); } cout << endl; return 0; }
#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...