이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> pll;
#define fi first
#define se second
const int MAXN = 100010;
const int INF = 1 << 30;
lint X[MAXN];
void solve(vector<lint> &v, vector<pll> &r, vector<pll> &x) {
for(auto &a : v) {
pll t = pll(a, max(-a, 0ll));
while(!r.empty() && t.fi < 0) {
t.se = max(t.se, r.back().se - t.fi);
t.fi += r.back().fi;
r.pop_back();
}
(t.fi >= 0 ? r : x).push_back(t);
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, K;
lint T;
cin >> N >> K >> T;
for(int i = 1; i <= N; i++) cin >> X[i];
lint s = 0, e = INF;
while(s < e) {
lint m = (s + e) / 2;
vector<lint> v1, v2;
for(int i = 1; i < K; i++) v1.push_back(2 * T * m - X[i + 1] + X[i]);
for(int i = N; i > K; i--) v2.push_back(2 * T * m - X[i] + X[i - 1]);
vector<pll> r1, r2, x1, x2;
solve(v1, r1, x1);
solve(v2, r2, x2);
/*
printf("m = %lld\nv1 : ", m);
for(auto a : v1) printf("%lld ", a);
printf("\nv2 : ");
for(auto a : v2) printf("%lld ", a);
printf("\nr1 : ");
for(auto a : r1) printf("(%lld, %lld) ", a.fi, a.se);
printf("\nr2 : ");
for(auto a : r2) printf("(%lld, %lld) ", a.fi, a.se);
printf("\n");
*/
lint t = 0;
int p1 = int(r1.size()) - 1, p2 = int(r2.size()) - 1;
while(p1 >= 0 || p2 >= 0) {
if(p1 >= 0 && t >= r1[p1].se) t += r1[p1--].fi;
else if(p2 >= 0 && t >= r2[p2].se) t += r2[p2--].fi;
else break;
}
if(p1 >= 0 || p2 >= 0) {
s = m + 1;
continue;
}
p1 = p2 = 0;
t = 0;
for(auto a : v1) t += a;
for(auto a : v2) t += a;
while(p1 < x1.size() || p2 < x2.size()) {
if(p1 < x1.size() && t - x1[p1].fi >= x1[p1].se) t -= x1[p1++].fi;
else if(p2 < x2.size() && t - x2[p2].fi >= x2[p2].se) t -= x2[p2++].fi;
else break;
}
if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
else e = m;
}
cout << s << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sparklers.cpp: In function 'int main()':
sparklers.cpp:70:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p1 < x1.size() || p2 < x2.size()) {
~~~^~~~~~~~~~~
sparklers.cpp:70:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p1 < x1.size() || p2 < x2.size()) {
~~~^~~~~~~~~~~
sparklers.cpp:71:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p1 < x1.size() && t - x1[p1].fi >= x1[p1].se) t -= x1[p1++].fi;
~~~^~~~~~~~~~~
sparklers.cpp:72:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if(p2 < x2.size() && t - x2[p2].fi >= x2[p2].se) t -= x2[p2++].fi;
~~~^~~~~~~~~~~
sparklers.cpp:75:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
~~~^~~~~~~~~~~
sparklers.cpp:75:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |