QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201566 | #2356. Partition of Queries | 8BQube# | WA | 1ms | 7948kb | C++20 | 1.7kb | 2023-10-05 15:10:46 | 2023-10-05 15:10:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
struct Line {
ll a, b;
ll operator()(ll x) const {
return a * x + b;
}
};
const int N = 1e6 + 5;
ll P[N], S[N], dp[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, y;
cin >> n >> y;
ll tt = 0;
{
string s;
cin >> s;
for (int i = 0, c = 0; i < n; i++)
if (s[i] == '+')
c++;
else
tt += c;
P[0] = 0;
for (int i = 1; i <= n; i++)
P[i] = P[i - 1] + (s[i - 1] == '+');
S[n + 1] = 0;
for (int i = n; i >= 0; i--)
S[i] = S[i + 1] + (s[i] == '?');
}
dp[0] = 0;
deque<Line> dq;
for (int i = 1; i <= n; i++) {
Line l = {-P[i - 1], dp[i - 1]};
while (true) {
if (SZ(dq) >= 1 && dq.back().a == l.a) {
if (l.b >= dq.back().b)
dq.pop_back();
else
break;
}
else if (SZ(dq) >= 2 && (l.b - dq[SZ(dq) - 2].b) / (dq[SZ(dq) - 2].a - l.a) >= (dq.back().b - dq[SZ(dq) - 2].b) / (dq[SZ(dq) - 2].a - dq.back().a))
dq.pop_back();
else {
dq.push_back(l);
break;
}
}
assert(SZ(dq));
while (SZ(dq) >= 2 && dq[0](S[i]) <= dq[1](S[i]))
dq.pop_front();
dp[i] = dq[0](S[i]) + (ll)S[i] * P[i] - y;
}
ll mx = 0;
for (int i = 0; i <= n; i++)
mx = max(mx, dp[i]);
cout << tt - mx << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7752kb
input:
6 5 ++??+?
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7940kb
input:
6 8 ++??+?
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7712kb
input:
5 1 +++++
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7912kb
input:
10 0 ++?+??++??
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 7948kb
input:
12 100 +?+++??+??++
output:
19
result:
ok single line: '19'
Test #6:
score: 0
Accepted
time: 1ms
memory: 7720kb
input:
1 1 ?
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 7600kb
input:
9 7 ++++++++?
output:
7
result:
ok single line: '7'
Test #8:
score: 0
Accepted
time: 1ms
memory: 7656kb
input:
9 8 ++++++++?
output:
8
result:
ok single line: '8'
Test #9:
score: 0
Accepted
time: 0ms
memory: 7648kb
input:
10 15 ++++++++??
output:
15
result:
ok single line: '15'
Test #10:
score: 0
Accepted
time: 0ms
memory: 7648kb
input:
5 3 +?+?+
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 1ms
memory: 7712kb
input:
10 5 +?+?+??+??
output:
10
result:
ok single line: '10'
Test #12:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
10 7 +?+?+??+??
output:
12
result:
ok single line: '12'
Test #13:
score: 0
Accepted
time: 0ms
memory: 7720kb
input:
15 4 +?+?+??+??+??+?
output:
14
result:
ok single line: '14'
Test #14:
score: 0
Accepted
time: 1ms
memory: 7688kb
input:
15 6 +?+?+??+??+??+?
output:
18
result:
ok single line: '18'
Test #15:
score: 0
Accepted
time: 1ms
memory: 7908kb
input:
19 8 +?+?+??+??+??+?++??
output:
28
result:
ok single line: '28'
Test #16:
score: 0
Accepted
time: 1ms
memory: 7944kb
input:
20 9 +?+?+??+??+??+?++???
output:
30
result:
ok single line: '30'
Test #17:
score: 0
Accepted
time: 1ms
memory: 7656kb
input:
500 100 +?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++++...
output:
2710
result:
ok single line: '2710'
Test #18:
score: -100
Wrong Answer
time: 1ms
memory: 7748kb
input:
10000 100 +?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++...
output:
56657
result:
wrong answer 1st lines differ - expected: '56616', found: '56657'