ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214783 | #2835. 机器故障探测 | linzhiyi | 50 | 1ms | 1200kb | C++ | 559b | 2024-11-21 20:27:38 | 2024-11-22 09:34:19 |
answer
#include<bits/stdc++.h>
using namespace std;
int solve(int l, int r, int x) {
if (x == 0) return 0;
if (l == r) return 0;
if (r - l + 1 == x) return 0;
int mid = l + r - 1 >> 1;
if (mid - l == r - mid - 1) return 1 + solve(l, mid, x / 2) + solve(mid + 1, r, ceil(x * 1.0 / 2));
else if (mid - l > r - mid - 1) return 1 + solve(l, mid, ceil(x * 1.0 / 2)) + solve(mid + 1, r, x / 2);
return 1 + solve(l, mid, x / 2) + solve(mid + 1, r, ceil(x * 1.0 / 2));
}
int main()
{
int n, m;
cin >> n >> m;
cout << solve(1, n, m);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1200kb
input:
6 2
output:
5
result:
ok single line: '5'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1200kb
input:
7 4
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 1200kb
input:
8 2
output:
5
result:
wrong answer 1st lines differ - expected: '6', found: '5'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 1200kb
input:
50 5
output:
22
result:
wrong answer 1st lines differ - expected: '24', found: '22'
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 1200kb
input:
49 3
output:
15
result:
wrong answer 1st lines differ - expected: '16', found: '15'
Test #6:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
45 45
output:
0
result:
ok single line: '0'
Test #7:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
44 1
output:
6
result:
ok single line: '6'
Test #8:
score: 10
Accepted
time: 1ms
memory: 1196kb
input:
498 1
output:
9
result:
ok single line: '9'
Test #9:
score: 0
Wrong Answer
time: 0ms
memory: 1196kb
input:
300 10
output:
65
result:
wrong answer 1st lines differ - expected: '66', found: '65'
Test #10:
score: 0
Wrong Answer
time: 0ms
memory: 1196kb
input:
500 23
output:
123
result:
wrong answer 1st lines differ - expected: '143', found: '123'