Submission #1201338
Source Code Expand
import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int V = sc.nextInt(); long[] x = new long[N]; for (int i = 0; i < N; ++i) { x[i] = sc.nextLong(); } int cnt = 0; int tmp = V; while (tmp > 0) { ++cnt; tmp /= 2; } ++cnt; int[] Vs = new int[cnt]; Vs[0] = V; for (int i = 1; i < cnt; ++i) { Vs[i] = Vs[i - 1] / 2; } int[][] toRight = new int[cnt][N]; int[][] toLeft = new int[cnt][N]; for (int i = 0; i < cnt; ++i) { for (int j = 0; j < N; ++j) { toRight[i][j] = j; toLeft[i][j] = j; } } for (int i = 0; i < cnt; ++i) { for (int j = N - 2; j >= 0; --j) { if (x[j + 1] - x[j] <= Vs[i]) { toRight[i][j] = toRight[i][j + 1]; } } } for (int i = 0; i < cnt; ++i) { for (int j = 1; j < N; ++j) { if (x[j] - x[j - 1] <= Vs[i]) { toLeft[i][j] = toLeft[i][j - 1]; } } } int[] dpRight = new int[1 << cnt]; int[] dpLeft = new int[1 << cnt]; Arrays.fill(dpLeft, N); Arrays.fill(dpRight, -1); for (int i = 0; i < (1 << cnt); ++i) { for (int nxt = 0; nxt < cnt; ++nxt) { if ((i & (1 << nxt)) > 0) { continue; } int ni = i | (1 << nxt); dpRight[ni] = Math.max(dpRight[ni], dpRight[i]); if (dpRight[i] + 1 < N) dpRight[ni] = Math.max(dpRight[ni], toRight[nxt][dpRight[i] + 1]); } } for (int i = 0; i < (1 << cnt); ++i) { for (int nxt = 0; nxt < cnt; ++nxt) { if ((i & (1 << nxt)) > 0) { continue; } int ni = i | (1 << nxt); dpLeft[ni] = Math.min(dpLeft[ni], dpLeft[i]); if (dpLeft[i] - 1 >= 0) dpLeft[ni] = Math.min(dpLeft[ni], toLeft[nxt][dpLeft[i] - 1]); } } int[] ans = new int[N]; for (int i = 0; i < (1 << cnt); i += 2) { int co = ((1 << cnt) - 1) ^ i; co -= 1; if (dpLeft[co] - dpRight[i] <= 1) { Arrays.fill(ans, 1); break; } if (dpLeft[co] - toRight[0][dpRight[i] + 1] <= 1) { ++ans[toLeft[0][dpLeft[co] - 1]]; if (toRight[0][dpRight[i] + 1] + 1 < N) { --ans[toRight[0][dpRight[i] + 1] + 1]; } } } for (int i = 1; i < N; ++i) { ans[i] += ans[i - 1]; } for (int i = 0; i < N; ++i) { if (ans[i] > 0) { System.out.println("Possible"); } else { System.out.println("Impossible"); } } } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }
Submission Info
Submission Time | |
---|---|
Task | E - Camel and Oases |
User | fortoobye |
Language | Java8 (OpenJDK 1.8.0) |
Score | 1000 |
Code Size | 2605 Byte |
Status | AC |
Exec Time | 1829 ms |
Memory | 133488 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt, 67.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 91 ms | 20820 KB |
00_example_02.txt | AC | 92 ms | 18772 KB |
00_example_03.txt | AC | 92 ms | 19924 KB |
01.txt | AC | 313 ms | 24660 KB |
02.txt | AC | 207 ms | 21588 KB |
03.txt | AC | 308 ms | 25044 KB |
04.txt | AC | 211 ms | 24788 KB |
05.txt | AC | 282 ms | 24916 KB |
06.txt | AC | 792 ms | 49140 KB |
07.txt | AC | 531 ms | 42920 KB |
08.txt | AC | 658 ms | 45932 KB |
09.txt | AC | 635 ms | 53028 KB |
10.txt | AC | 529 ms | 41940 KB |
11.txt | AC | 575 ms | 42776 KB |
12.txt | AC | 566 ms | 45988 KB |
13.txt | AC | 1721 ms | 133488 KB |
14.txt | AC | 291 ms | 26452 KB |
15.txt | AC | 186 ms | 24532 KB |
16.txt | AC | 296 ms | 26580 KB |
17.txt | AC | 184 ms | 21844 KB |
18.txt | AC | 251 ms | 24148 KB |
19.txt | AC | 224 ms | 25660 KB |
20.txt | AC | 724 ms | 55276 KB |
21.txt | AC | 579 ms | 45896 KB |
22.txt | AC | 649 ms | 44280 KB |
23.txt | AC | 621 ms | 51248 KB |
24.txt | AC | 560 ms | 44812 KB |
25.txt | AC | 632 ms | 47460 KB |
26.txt | AC | 685 ms | 45064 KB |
27.txt | AC | 1829 ms | 101436 KB |
28.txt | AC | 690 ms | 46956 KB |
29.txt | AC | 533 ms | 37924 KB |
30.txt | AC | 676 ms | 43748 KB |
31.txt | AC | 523 ms | 44676 KB |
32.txt | AC | 553 ms | 45168 KB |
33.txt | AC | 545 ms | 40532 KB |
34.txt | AC | 645 ms | 44668 KB |
35.txt | AC | 1715 ms | 96228 KB |
36.txt | AC | 272 ms | 24016 KB |
37.txt | AC | 169 ms | 24532 KB |
38.txt | AC | 292 ms | 25812 KB |
39.txt | AC | 169 ms | 20436 KB |
40.txt | AC | 264 ms | 24276 KB |
41.txt | AC | 220 ms | 24484 KB |
42.txt | AC | 282 ms | 27860 KB |
43.txt | AC | 219 ms | 26536 KB |
44.txt | AC | 272 ms | 23764 KB |
45.txt | AC | 219 ms | 22612 KB |
46.txt | AC | 507 ms | 42524 KB |
47.txt | AC | 600 ms | 44728 KB |
48.txt | AC | 519 ms | 45312 KB |
49.txt | AC | 598 ms | 45224 KB |
50.txt | AC | 534 ms | 41816 KB |
51.txt | AC | 571 ms | 48156 KB |
52.txt | AC | 521 ms | 46472 KB |
53.txt | AC | 596 ms | 45620 KB |
54.txt | AC | 525 ms | 42160 KB |
55.txt | AC | 623 ms | 40264 KB |
56.txt | AC | 468 ms | 40376 KB |
57.txt | AC | 587 ms | 42460 KB |
58.txt | AC | 531 ms | 44404 KB |
59.txt | AC | 555 ms | 45660 KB |
60.txt | AC | 544 ms | 41756 KB |
61.txt | AC | 569 ms | 43080 KB |
62.txt | AC | 506 ms | 46084 KB |
63.txt | AC | 606 ms | 42788 KB |
64.txt | AC | 544 ms | 42548 KB |
65.txt | AC | 620 ms | 42728 KB |
66.txt | AC | 93 ms | 21332 KB |
67.txt | AC | 92 ms | 19028 KB |