이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
rikka simp
/⌒ヽ
|/ ⌒ ____
| ..: : : : : : : : : : : : >
イ: : : / : : : : : : : : : : : `ヽ / ̄〉
、___./: : : : :/:| : : : : : : : : : !: : V: :ハ / /
/: : : : : :/ |: : : | :/\: : |: : : |: : : {__  ̄}
/: : : |/|:/、ミi|: : : |/ 斗 ヽ:!: : : !: : : }ヽ:.} ̄
/⌒{: :: :.7笊ぅレ、: :| ん笊ぅ.}: : : |: : : |: :V
弋__八: : | 弋+ツ 弋+ .ツ}: : : : : : :|: ハ
| }.⊂⊃ __ ⊂⊃: : :/、: : | : ハ
|..八 〈/ } ;′:/ / : 人: : ::}
ヽ > . \__.ノ /: : :レ': / )ノ
ヽ ≧ーァ―‐ァ.厶イ ( ̄)
\ / / V三}
*/
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const ll maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int n, m;
vector<int> a, b;
int Find(int x, int first)
{
int l = first, r = m, pos = 1e9;
while (l <= r)
{
int mid = (l + r) / 2;
if (b[mid] >= x)
{
pos = mid;
r = mid - 1;
}
else l = mid + 1;
}
return pos;
}
int check(int m)
{
int pos = 0;
for (int i = 0; i < n; i++)
{
int idx = Find(a[i] - m, pos);
if (idx == 1e9) return 0;
if (abs(b[idx] - a[i]) > m) return 0;
pos = idx + 1;
}
return 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("test.INP","r",stdin);
//freopen("test.OUT","w",stdout);
cin >> n >> m;
for (int i = 0; i < n; i++)
{
int x; cin >> x;
a.push_back(x);
}
for (int i = 0; i < m; i++)
{
int x; cin >> x;
b.push_back(x);
}
if (n > m)
{
swap(n, m);
swap(a, b);
}
sort(a.begin(), a.end()); sort(b.begin(),b.end());
int l = 1, r = 1e9, ans;
while (l <= r)
{
int mid = (l + r) / 2;
if (check(mid))
{
ans = mid;
r = mid - 1;
}
else l = m + 1;
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
cipele.cpp: In function 'int main()':
cipele.cpp:94:20: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
94 | cout << ans << "\n";
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |