#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define Y8o "Semiexpress"
#define maxn 3005
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof()
{
if(fopen(Y8o".inp", "r"))
{
freopen(Y8o".inp", "r", stdin);
// freopen(Y8o".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
}
void ctime()
{
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
int n, m, k;
ll A, B, C, T;
ll a[maxn];
int sum[maxn][maxn]; /// sum[i][j] : số lượng nhiều nhất khi xét nhóm i, đặt j vt
int dp[maxn][maxn]; /// dp[i][j] : số lượng nhiều nhất khi xét đến nhóm i, đặt j vt
int limit[maxn]; /// limit[i] : so luong dat nhieu nhat tai nhom i
void prepare()
{
for(int i = 1, cnt = 0; i <= m; i ++, cnt = 0)
{
ll val = (a[i] - 1) * B;
if(val > T) break;
ll val2 = val, pos = a[i + 1] - 1;
int l = a[i] + 1, r = a[i + 1] - 1, lim = a[i];
while(1)
{
while(l <= r)
{
int mid = (l + r) >> 1;
if(val2 + A * (mid - lim) > T) r = mid - 1;
else l = mid + 1;
}
if(l > pos) break;
val2 = val + (l - a[i]) * C;
if(val2 > T)
{
pos = l - 1;
break;
}
sum[i][cnt ++] = (l - 1) - a[i] + 1 - (i == 1);
lim = l ++, r = a[i + 1] - 1;
if(l > r) break;
}
sum[i][cnt] = pos - a[i] + 1 - (i == 1);
if(i == m) sum[i][cnt] = 1;
limit[i] = cnt;
/*
for(int t = a[i] + 1; t <= a[i + 1] - 1; t ++)
{
val2 += A;
if(val2 > T)
{
val2 = val + (t - a[i]) * C;
if(val2 > T)
{
pos = t - 1;
break;
}
sum[i][cnt ++] = (t - 1) - a[i] + 1 - (i == 1);
}
}
sum[i][cnt] = pos - a[i] + 1 - (i == 1);
if(i == m) sum[i][cnt] = 1;
*/
}
}
void sub2()
{
prepare();
for(int i = 1; i <= m; i ++)
{
for(int j = 0; j <= k; j ++)
{
for(int t = 0; t <= j; t ++)
{
dp[i][j] = max(dp[i][j], dp[i - 1][t] + sum[i][j - t]);
}
}
}
int ans = 0;
for(int t = 0; t <= k; t ++) ans = max(ans, dp[m][t]);
cout << ans;
}
struct dl
{
int val, i, cnt;
bool operator < (const dl & other)
const { return val < other.val; };
}; priority_queue<dl> q;
void sub()
{
prepare();
for(int i = 1; i <= m; i ++) q.push({ sum[i][0], i, 0 });
int ans = 0;
while(q.size())
{
int val = q.top().val, i = q.top().i, cnt = q.top().cnt;
q.pop();
if(cnt && !k) continue;
k -= (cnt >= 1);
ans += val;
if(cnt < limit[i]) q.push({ sum[i][cnt + 1] - sum[i][cnt], i, cnt + 1 });
}
cout << ans;
}
void solve()
{
cin >> n >> m >> k, k -= m;
cin >> A >> B >> C >> T;
for(int i = 1; i <= m; i ++) cin >> a[i];
sub();
// if(n <= 300) sub2();
// else sub();
}
int main()
{
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --)
{
solve();
}
ctime();
return 0;
}
Compilation message
semiexpress.cpp: In function 'void iof()':
semiexpress.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(Y8o".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4572 KB |
Output is correct |
21 |
Execution timed out |
1062 ms |
10708 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |