제출 #1140731

#제출 시각아이디문제언어결과실행 시간메모리
1140731ghammazhassanSprinklers (CEOI24_sprinklers)C++20
3 / 100
2104 ms236792 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=1; int mi=l; vector<pair<int,string>>q; // while (l){ // int i=0; // queue<int>o; // for (int j:b){ // o.push(j); // } // string s; // for (int j:a){ // s+='W'; // } // while (!o.empty()){ // if (i>=n){ // break; // } // int he=o.front(); // while (!o.empty() and a[i]<=o.front()){ // he =o.front(); // if (he<=a[i]+mi and he>=a[i]){ // o.pop(); // s[i]='R'; // } // else if (i!=n-1){ // s[i]='R'; // i++; // } // else{ // break; // } // } // if (o.empty()){ // continue; // } // he=o.front(); // int f=he+mi; // while (i<n-1 and a[i+1]<=f){ // s[i]='R'; // i++; // } // if (s[i]=='R'){ // break; // } // s[i]='L'; // while (!o.empty()){ // he =o.front(); // if (he>=a[i]-mi and he<=a[i]){ // o.pop(); // } // else{ // break; // } // } // i++; // } // // cout << mi << " " << s << endl; // for (int i=0;i<n;i++){ // if (s[i]!='L'){ // s[i]='R'; // } // } // q.push_back({mi,s}); // i=0; // while (!o.empty()){ // int he=o.front(); // if ((he>=a[i]-mi and he<=a[i] and s[i]=='L') or (he<=a[i]+mi and he>=a[i] and s[i]=='R')){ // o.pop(); // } // else if (i!=n-1){ // i++; // } // else{ // break; // } // } // if (o.empty()){ // break; // } // else{ // l*=2; // } // // cout << mi << endl; // mi=l; // } // int h=l; // l/=2; mi=0; while (mi<1000000){ int i=0; queue<int>o; for (int j:b){ o.push(j); } string s; for (int j:a){ s+='W'; } while (!o.empty()){ if (i>=n){ break; } int he=o.front(); while (!o.empty() and a[i]<=o.front()){ he =o.front(); if (he<=a[i]+mi and he>=a[i]){ o.pop(); s[i]='R'; } else if (i!=n-1){ s[i]='R'; i++; } else{ break; } } if (o.empty()){ continue; } he=o.front(); int f=he+mi; while (i<n-1 and a[i+1]<=f){ s[i]='R'; i++; } if (s[i]=='R'){ break; } s[i]='L'; while (!o.empty()){ he =o.front(); if (he>=a[i]-mi and he<=a[i]){ o.pop(); } else{ break; } } i++; } // cout << mi << " " << s << endl; for (int i=0;i<n;i++){ if (s[i]!='L'){ s[i]='R'; } } q.push_back({mi,s}); i=0; while (!o.empty()){ int he=o.front(); if ((he>=a[i]-mi and he<=a[i] and s[i]=='L') or (he<=a[i]+mi and he>=a[i] and s[i]=='R')){ o.pop(); } else if (i!=n-1){ i++; } else{ break; } } if (o.empty()){ break; } mi++; } for (auto i:q){ if (i.first==mi){ cout << mi <<endl; cout << i.second << endl; break; } } } 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...