QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137328#2356. Partition of Queriesckz#WA 1ms3592kbC++201.5kb2023-08-10 10:30:462023-08-10 10:30:47

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 10:30:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2023-08-10 10:30:46]
  • 提交

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: 1ms
memory: 3584kb

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3532kb

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3464kb

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

10 0
++?+??++??

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3592kb

input:

12 100
+?+++??+??++

output:

19

result:

ok single line: '19'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3484kb

input:

1 1
?

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3500kb

input:

9 7
++++++++?

output:

7

result:

ok single line: '7'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

9 8
++++++++?

output:

8

result:

ok single line: '8'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3592kb

input:

10 15
++++++++??

output:

15

result:

ok single line: '15'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

5 3
+?+?+

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

10 5
+?+?+??+??

output:

10

result:

ok single line: '10'

Test #12:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

10 7
+?+?+??+??

output:

12

result:

ok single line: '12'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

15 4
+?+?+??+??+??+?

output:

14

result:

ok single line: '14'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3532kb

input:

15 6
+?+?+??+??+??+?

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

19 8
+?+?+??+??+??+?++??

output:

28

result:

ok single line: '28'

Test #16:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

20 9
+?+?+??+??+??+?++???

output:

30

result:

ok single line: '30'

Test #17:

score: -100
Wrong Answer
time: 1ms
memory: 3548kb

input:

500 100
+?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++++...

output:

14304

result:

wrong answer 1st lines differ - expected: '2710', found: '14304'