이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define itn int
#define fi first
#define se second
#pragma optimization ("O3")
#pragma GCC target ("avx2")
#pragma optimization ("unroll_loops")
int maxn = 1e6 + 50;
vector<vector<ll>> go(maxn, vector<ll> (21));
vector<int> d(maxn), v(maxn);
vector<ll> presum(maxn), h(maxn);
bool isdeeper (int a, int b) { // true if a is deeper
return h[a] >= h[b];
}
int binlift (int a, int k) {
for (int l = 20; l >= 0; --l) {
if (k & (1 << l)) {
a = go[a][l];
}
}
return a;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, s; ll k; cin >> n >> s >> k;
for (int i = 1; i < n; ++i)
cin >> d[i];
for (int i = 1; i <= n; ++i)
cin >> v[i];
presum[0] = 0;
h[1] = 0;
for (int i = 1; i <= n; ++i)
presum[i] = presum[i - 1] + v[i];
for (int i = 2; i <= n; ++i) {
h[i] = h[i - 1] + d[i - 1];
//cout << h[i] << ' ';
} //cout << endl;
go[n][0] = n + 1;
go[n + 1][0] = n + 1;
for (int i = 1; i < n; ++i) {
int j = (int) (upper_bound(h.begin() + 1, h.begin() + n + 1, h[i] + k) - h.begin() - 1);
//cout << i << ' ' << j << endl;
j = (int) (upper_bound(h.begin() + 1, h.begin() + n + 1, h[j] + k) - h.begin() - 1);
//cout << i << ' ' << j << endl;
go[i][0] = j + 1;
}
for (int l = 1; l <= 20; ++l) {
for (int i = 1; i <= n + 1; ++i) {
go[i][l] = go[go[i][l - 1]][l - 1];
}
}
ll ans = -1;
for (int i = 1; i <= n; ++i) {
ans = max(ans, presum[binlift(i, s) - 1] - presum[i - 1]);
}
//cout << ans << endl;
for (int i = 1; i <= n; ++i) {
if (ans == presum[binlift(i, s) - 1] - presum[i - 1]) {
vector<int> shields;
for (int j = i; j <= n && shields.size() < s; j = go[j][0]) {
shields.push_back((int) (upper_bound(h.begin() + 1, h.begin() + n + 1, h[j] + k) - h.begin() - 1));
}
cout << shields.size() << '\n';
for (int elem : shields)
cout << elem << ' ';
break;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
SolarStorm.cpp:8: warning: ignoring '#pragma optimization ' [-Wunknown-pragmas]
8 | #pragma optimization ("O3")
|
SolarStorm.cpp:10: warning: ignoring '#pragma optimization ' [-Wunknown-pragmas]
10 | #pragma optimization ("unroll_loops")
|
SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:64:54: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
64 | for (int j = i; j <= n && shields.size() < s; j = go[j][0]) {
| ~~~~~~~~~~~~~~~^~~
# | 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... |