用户输出
1
2
0
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#25729 | #1032. 1-03G. JM的毒瘤题 | Accepted | 100 | 614 ms | 348 K | C++ 11 / 1.3 K | dytc | 2020-06-28 16:30:31 |
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define x first
#define y second
typedef long long ll;
using namespace std;
const int N = 1e5 + 100;
// use the recursive to cut the string
int dfs(int k, int l1, int r1, int l2, int r2) {
// judge the feasibility
if (l1 > r1 || l2 > r2 || k == 0)
return 0;
// swap promise l1 <= l2
if (l1 > l2 || (l1 == l2 && r1 < r2))
return dfs(k, l2, r2, l1, r1);
// including relationship
if (r1 >= r2)
return r2 - l2 + 1;
// simplify with the mid
int mid = 1 << (k - 1);
if (l1 > mid)
return dfs(k - 1, l1 - mid, r1 - mid, l2 - mid, r2 - mid);
if (l2 > mid)
return dfs(k, l1, r1, l2 - mid, r2 - mid);
if (r1 < mid && r2 < mid)
return dfs(k - 1, l1, r1, l2, r2);
int res[5];
// use the five possible conditions to get the max value
res[0] = max(0, r1 - l2 + 1);
res[1] = dfs(k, l1, min(mid - 1, r1), l2, min(mid - 1, r2));
res[2] = dfs(k, l1, min(mid - 1, r1), max(l2, mid + 1), r2);
res[3] = dfs(k, max(mid + 1, l1), r1, l2, min(mid - 1, r2));
res[4] = dfs(k, max(mid + 1, l1), r1, max(mid + 1, l2), r2);
return *max_element(res, res + 5);
}
int main() {
int n;
scanf("%d", &n);
while (n--) {
int k, l1, r1, l2, r2;
cin >> k >> l1 >> r1 >> l2 >> r2;
cout << dfs(k, l1, r1, l2, r2) << endl;
}
return 0;
}
用户输出
1
2
0
系统信息
Exited with return code 0
18
30 3 6 1 4
30 1 1 4 4
30 2 2 6 6
30 1 1 1 1
30 1 1 2 3
30 2 3 1 1
30 4 5 6 7
30 5 6 5 10
<126 bytes omitted>
用户输出
2
0
1
1
1
1
1
2
2
3
3
3
3
4
4
1
1
8
系统信息
Exited with return code 0
45
30 73426655 594361930 343984155 989446962
30 169720415 312105195 670978284 671296539
30 20 59
<1585 bytes omitted>
379149396
207899
5
103
2901
19516
112739
4151539
7731787
530010446
1000000000
71194568
8
<301 bytes omitted>
用户输出
379149396
207899
5
103
2901
19516
112739
4151539
7731787
530010446
1000000000
71194568
8140525
28429169
268435455
463129088
4631
<228 bytes omitted>
系统信息
Exited with return code 0
100000
11 103 1997 1063 1222
26 24644974 48409450 51667909 57999424
2 3 3 3 3
26 3660266 5056371
<2667925 bytes omitted>
160
6331516
1
669897
1502512
8644289
1107
154443
2295
1
30891
15
7171342
11
2819
1215
<609656 bytes omitted>
用户输出
160
6331516
1
669897
1502512
8644289
1107
154443
2295
1
30891
15
7171342
11
2819
12156
733
194
29096358
151
5916
1
92366
174
321
<509628 bytes omitted>
系统信息
Exited with return code 0
100000
30 642049148 976948557 570976641 972271279
30 562317312 772318035 72539938 682025304
30 30
<4380333 bytes omitted>
330222132
210000724
120072017
43243530
87344032
51372755
134353734
306730318
235458160
6499
<1031634 bytes omitted>
用户输出
330222132
210000724
120072017
43243530
87344032
51372755
134353734
306730318
235458160
6499998
134574977
4027250
218285468
83887
<931606 bytes omitted>
系统信息
Exited with return code 0