QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137316 | #2356. Partition of Queries | ckz# | WA | 1ms | 3544kb | C++20 | 1.5kb | 2023-08-10 10:19:12 | 2023-08-10 10:19:13 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()
using namespace std;
#define int ll
#define x(j) (j - cnt[j])
#define y(j) (f[j] - pre[j] + j * cnt[j] - cnt[j] * cnt[j])
const int N = 1e6 + 10;
int n, y, pre[N], cnt[N], f[N];
int head, que[N], p;
void solve()
{
cin >> n >> y;
string s;
cin >> s;
s = '?' + s;
for(int i = 1; i <= n; i++)
{
pre[i] = pre[i - 1];
cnt[i] = cnt[i - 1];
if(s[i] == '?')
{
cnt[i]++;
pre[i] += i - cnt[i];
}
}
int ans = pre[n];
p = 1;
que[++head] = 0;
for(int i = 1; i <= n; i++)
{
if(s[i] == '+') continue;
int k = cnt[i - 1];
while(p < head && k * (x(que[p + 1])) - x(que[p]) >= y(que[p + 1]) - y(que[p])) p++;
int j = que[p];
f[i] = y(j) - x(j) * k + y + pre[i - 1];
while(p < head && (y(que[head]) - y(que[head - 1])) * (x(i) - x(que[head])) >= (y(i) - y(que[head])) * (x(que[head] - x(que[head - 1])))) head--;
que[++head] = i;
ans = min(ans, f[i] + pre[n] - pre[i] - (i - cnt[i]) * (cnt[n] - cnt[i]));
// cerr << pre[n] - pre[i] - (i - 1) * (cnt[n] - cnt[i]) << '\n';
// cerr << f[i] << ' ' << ans << '\n';
}
cout << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t = 1;
//cin >> t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3488kb
input:
6 5 ++??+?
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
6 8 ++??+?
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
5 1 +++++
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
10 0 ++?+??++??
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
12 100 +?+++??+??++
output:
19
result:
ok single line: '19'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1 1 ?
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
9 7 ++++++++?
output:
7
result:
ok single line: '7'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
9 8 ++++++++?
output:
8
result:
ok single line: '8'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
10 15 ++++++++??
output:
15
result:
ok single line: '15'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
5 3 +?+?+
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
10 5 +?+?+??+??
output:
10
result:
ok single line: '10'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
10 7 +?+?+??+??
output:
12
result:
ok single line: '12'
Test #13:
score: -100
Wrong Answer
time: 1ms
memory: 3464kb
input:
15 4 +?+?+??+??+??+?
output:
16
result:
wrong answer 1st lines differ - expected: '14', found: '16'