Submission #52349157
Source Code Expand
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long L = scanner.nextLong(), R = scanner.nextLong();
int max = Long.toBinaryString(R - L).length() - 1;
long ms = 1L << max;
long m = ms;
while (m < L) m += ms;
String sL = Long.toBinaryString(m - L);
String sR = Long.toBinaryString(R - m);
Stack<Long> up = new Stack<>();
for (int i = 0;i < sL.length();i++) {
if (sL.charAt(i) == '1') up.add(1L << (sL.length() - i - 1));
}
Queue<Long> down = new ArrayDeque<>();
for (int i = 0;i < sR.length();i++) {
if (sR.charAt(i) == '1') down.add(1L << (sR.length() - i - 1));
}
System.out.println(up.size() + down.size());
long now = L;
while (!up.isEmpty()) {
long u = up.pop();
System.out.println(now + " " + (now + u));
now += u;
}
while (!down.isEmpty()) {
long d = down.poll();
System.out.println(now + " " + (now + d));
now += d;
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Divide Interval |
| User | tagucha |
| Language | Java (OpenJDK 17) |
| Score | 450 |
| Code Size | 1204 Byte |
| Status | AC |
| Exec Time | 97 ms |
| Memory | 40364 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 93 ms | 39952 KiB |
| 00_sample_02.txt | AC | 92 ms | 40056 KiB |
| 00_sample_03.txt | AC | 92 ms | 39988 KiB |
| 01_test_01.txt | AC | 93 ms | 40000 KiB |
| 01_test_02.txt | AC | 92 ms | 40004 KiB |
| 01_test_03.txt | AC | 95 ms | 40016 KiB |
| 01_test_04.txt | AC | 93 ms | 40068 KiB |
| 01_test_05.txt | AC | 93 ms | 40364 KiB |
| 01_test_06.txt | AC | 94 ms | 40216 KiB |
| 01_test_07.txt | AC | 94 ms | 40012 KiB |
| 01_test_08.txt | AC | 95 ms | 40232 KiB |
| 01_test_09.txt | AC | 95 ms | 40196 KiB |
| 01_test_10.txt | AC | 95 ms | 40048 KiB |
| 01_test_11.txt | AC | 94 ms | 39948 KiB |
| 01_test_12.txt | AC | 95 ms | 40216 KiB |
| 01_test_13.txt | AC | 95 ms | 40208 KiB |
| 01_test_14.txt | AC | 95 ms | 40024 KiB |
| 01_test_15.txt | AC | 94 ms | 40008 KiB |
| 01_test_16.txt | AC | 97 ms | 40012 KiB |
| 01_test_17.txt | AC | 94 ms | 40216 KiB |
| 01_test_18.txt | AC | 94 ms | 39992 KiB |
| 01_test_19.txt | AC | 95 ms | 40148 KiB |
| 01_test_20.txt | AC | 94 ms | 40232 KiB |
| 01_test_21.txt | AC | 92 ms | 39864 KiB |
| 01_test_22.txt | AC | 93 ms | 39956 KiB |
| 01_test_23.txt | AC | 95 ms | 40352 KiB |
| 01_test_24.txt | AC | 97 ms | 40008 KiB |
| 01_test_25.txt | AC | 92 ms | 40084 KiB |
| 01_test_26.txt | AC | 92 ms | 39856 KiB |
| 01_test_27.txt | AC | 93 ms | 40096 KiB |
| 01_test_28.txt | AC | 93 ms | 40008 KiB |
| 01_test_29.txt | AC | 94 ms | 39964 KiB |