Submission #1140512

#TimeUsernameProblemLanguageResultExecution timeMemory
1140512ghammazhassanSprinklers (CEOI24_sprinklers)C++20
0 / 100
2 ms320 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; } } 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() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif 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(); } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |         freopen("input.txt","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen("output.txt","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...