# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
824520 |
2023-08-14T07:20:26 Z |
이동현(#10361) |
Robogolf (ROI19_golf) |
C++17 |
|
5000 ms |
524288 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
const int mod = 998244353;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<array<int, 3>> a(k);
for(int i = 0; i < k; ++i){
cin >> a[i][0] >> a[i][1] >> a[i][2];
--a[i][0], --a[i][1];
}
sort(a.begin(), a.end(), [&](array<int, 3>&x, array<int, 3>&y){
return x[0] + x[1] < y[0] + y[1] || (x[0] + x[1] == y[0] + y[1] && x[1] < y[1]);
});
int ans = 0;
auto sol = [&](int bt){
vector<int> dp(n + m - 1 + bt);
int ap = k - 1;
for(int i = n + m - 2 + bt; i >= 0; i -= 2){
auto pos = [&](int x, int y){
assert((n + bt - x - 1 - (m - y - 1)) % 2 == 0);
return m - 1 + (n + bt - x - 1 - (m - y - 1)) / 2;
};
while(ap >= 0 && a[ap][0] + a[ap][1] == i){
dp[pos(a[ap][0], a[ap][1])] = a[ap][2];
--ap;
}
// cout << i << endl;
// for(auto&j:dp) cout << j << ' ';
// cout << endl;
for(int x = 0; x <= i; ++x){
int y = i - x;
if(x < n && y < m){
(ans += dp[pos(x, y)] + mod * 2) %= mod;
// cout << dp[pos(x, y)] << endl;
}
}
// cout << endl;
for(int i = 1; i + 1 < (int)dp.size(); ++i){
if(dp[i] < dp[i - 1] && dp[i] < dp[i + 1]){
dp[i] = min(dp[i - 1], dp[i + 1]);
}
}
while(ap >= 0 && a[ap][0] + a[ap][1] == i - 1){
int j = ap;
while(j - 1 >= 0 && a[j - 1][0] + a[j - 1][1] == i - 1 && a[j][1] - 1 == a[j - 1][1]){
--j;
}
int p = pos(a[j][0] + 1, a[j][1]);
assert(p > 0);
dp[p] = min(a[j][2], dp[p - 1]);
for(int k = j; k < ap; ++k){
dp[p + k - j + 1] = min(a[k][2], a[k + 1][2]);
}
assert(p + ap - j + 1 + 1 < (int)dp.size());
dp[p + ap - j + 1] = min(a[ap][2], dp[p + ap - j + 2]);
ap = j - 1;
}
}
};
sol(0);
sol(1);
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
276 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
32 ms |
6752 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
276 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5029 ms |
4424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5029 ms |
4424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
276 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
304 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
276 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |