# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239749 | VEGAnn | Go (COCI18_go) | C++14 | 188 ms | 95480 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
#define i3 array<int,3>
using namespace std;
typedef long double ld;
typedef long long ll;
const int N = 200100;
const int M = 110;
const int K = 110;
const int T = 2010;
const int oo = 2e9;
i3 a[M];
short f[T][M][M][2], ans = 0, n, k, m;
void upd(short &x, short y){
x = max(x, y);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> k >> m;
for (int i = 0; i < m; i++)
cin >> a[i][0] >> a[i][1] >> a[i][2];
a[m++] = {k, 0, 1};
sort(a, a + m);
for (int tim = 1; tim < T; tim++)
for (int l = 0; l < m; l++)
for (int r = l; r < m; r++)
for (int tp = 0; tp < 2; tp++)
f[tim][l][r][tp] = -1;
for (int i = 0; i < m; i++)
if (a[i][0] == k && a[i][1] == 0)
f[1][i][i][0] = 0;
for (int tim = 1; tim < T; tim++){
for (int l = 0; l < m; l++)
for (int r = l; r < m; r++)
for (int tp = 0; tp < 2; tp++){
if (f[tim][l][r][tp] < 0) continue;
if (ans < f[tim][l][r][tp]){
ans = f[tim][l][r][tp];
// cerr << ans << " " << tim << " " << l << " " << r << '\n';
}
if (l > 0){
int nw = tim;
if (tp == 0)
nw += a[l][0] - a[l - 1][0];
else nw += a[r][0] - a[l - 1][0];
if (nw < T)
upd(f[nw][l - 1][r][0], f[tim][l][r][tp] + (nw <= a[l - 1][2] ? a[l - 1][1] : 0));
}
if (r < m - 1){
int nw = tim;
if (tp == 1)
nw += a[r + 1][0] - a[r][0];
else nw += a[r + 1][0] - a[l][0];
if (nw < T)
upd(f[nw][l][r + 1][1], f[tim][l][r][tp] + (nw <= a[r + 1][2] ? a[r + 1][1] : 0));
}
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |