Submission #1140514

#TimeUsernameProblemLanguageResultExecution timeMemory
1140514ghammazhassanSprinklers (CEOI24_sprinklers)C++20
9 / 100
47 ms2900 KiB
// #include <bits/stdc++.h> #include <iostream> #include <cmath> #include <algorithm> #include <map> #include <vector> #include <iomanip> #include <string> #include <queue> #include <set> #include <deque> using namespace std; #define int long long #define endl "\n"; const int N=2e5+5; const int M=1e9+7; void solve() { int n,m; cin >> n >> m; vector<int>a(n),b(m); for (int i=0;i<n;i++){ cin >> a[i]; } for (int i=0;i<m;i++){ cin >> b[i]; } if (n==1 and a[0]>b[0] and a[0]<b[m-1]){ cout << -1 << endl; return; } else if (n==1){ if (a[0]>b[0]){ cout << a[0]-b[0] << endl; cout << 'L' << endl; } else{ cout << b[m-1]-a[0] << endl; cout << 'R' << endl; } return; } int l=0; int h=b[m-1]+1; int mi=(l+h)/2; while (l<h){ queue<int>o; for (int p:b){ o.push(p); } for (int i:a){ if (!o.empty()){ int he=o.front(); if (he<i){ while (!o.empty()){ he=o.front(); if (he>=i-mi and he<=i){ o.pop(); } else{ break; } } } else{ while (!o.empty()){ he=o.front(); if (he<=i+mi and he>=i){ o.pop(); } else{ break; } } } } } if (o.empty()){ h=mi; } else{ l=mi+1; } mi=(l+h)/2; } string s; queue<int>o; for (int p:b){ o.push(p); } for (int i:a){ if (!o.empty()){ int he=o.front(); if (he<i){ s+='L'; while (!o.empty()){ he=o.front(); if (he>=i-mi and he<=i){ o.pop(); } else{ break; } } } else{ s+='R'; while (!o.empty()){ he=o.front(); if (he<=i+mi and he>=i){ o.pop(); } else{ break; } } } } else{ s+='R'; } } cout << mi << endl; cout << s << endl; } signed main() { ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE cout << fixed<<setprecision(9); int t=1; // cin >> t; for (int _=1;_<=t;_++){ solve(); } }
#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...