QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137325#2356. Partition of Queries4k2kok#WA 2ms3584kbC++201.0kb2023-08-10 10:26:572023-08-10 10:27:01

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:27:01]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3584kb
  • [2023-08-10 10:26:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define db long double

const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;

int n, y, bck[1001000];

string str;

void solve() {
    cin >> n >> y;
    cin >> str; str = " " + str;
    for (int i = n; i >= 1; i--) {
        bck[i] = bck[i + 1] + (str[i] == '?');
    }
    int cnt = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        if (str[i] == '?') {
            if (cnt * bck[i] >= y) {
                cnt = 0;
                ans += y;
            }
            ans += cnt;
        }
        if (str[i] == '+') {
            cnt++;
        }
        // cerr << i << ' ' << cnt << ' ' << ans << '\n';
    }
    cout << ans << '\n';
}

signed main(){
    io;
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3460kb

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

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

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

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

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

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

input:

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

output:

0

result:

ok single line: '0'

Test #5:

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

input:

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

output:

19

result:

ok single line: '19'

Test #6:

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

input:

1 1
?

output:

0

result:

ok single line: '0'

Test #7:

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

input:

9 7
++++++++?

output:

7

result:

ok single line: '7'

Test #8:

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

input:

9 8
++++++++?

output:

8

result:

ok single line: '8'

Test #9:

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

input:

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

output:

15

result:

ok single line: '15'

Test #10:

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

input:

5 3
+?+?+

output:

3

result:

ok single line: '3'

Test #11:

score: -100
Wrong Answer
time: 2ms
memory: 3460kb

input:

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

output:

16

result:

wrong answer 1st lines differ - expected: '10', found: '16'