이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll calc2(vector<int> a, int d)
{
ll t = 0, mx = 0;
for(int i = 1;i<a.size();i++)
{
t=max(0ll,t+(d-(a[i]-a[i-1])));
mx=max(mx,t);
}
return mx;
}
ll calc(vector<int> a, ll d)
{
vector<int> l, r;
int n = a.size(), mid = n/2;
for(int i = 0;i<n;i++)
if(i<mid)
l.pb(a[i]);
else
r.pb(a[i]);
if(n%2)
l.pb(a[mid]);
reverse(l.begin(),l.end());
for(auto &x:l)
x=-x;
return max(calc2(l,d),calc2(r,d))*2+(n%2==0?max(0ll,d-(a[mid]-a[mid-1])):0);
}
ll calc1(vector<int> a, int d)
{
int n = a.size();
for(auto &x:a)
x*=2;
d*=2;
ll l = 0, r = 1e18;
while(l<r)
{
ll mid = (l+r)/2;
bool ok = 1;
ll cur = -1e18;
for(int i = 0;i<n;i++)
{
cur=max(a[i]-mid,cur+d);
if(cur>a[i]+mid)
{
ok=0;
break;
}
}
if(ok)
r=mid;
else
l=mid+1;
}
return l;
}
int main()
{
fio
// ifstream cin("in.in");
int n, m, d;
cin >> n >> m >> d;
vector<int> a(n);
for(auto &x:a)
cin >> x;
while(m--)
{
int x;
cin >> x;
a.pb(x);
sort(a.begin(),a.end());
ll res = calc1(a,d);
cout << res/2;
if(res%2)
cout << ".5";
cout << " ";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'long long int calc2(std::vector<int>, int)':
Main.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i = 1;i<a.size();i++)
| ~^~~~~~~~~
# | 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... |