Submission #1453641
Source Code Expand
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 int N, V; int K; int L[20]; int X[200000]; int U[200000]; int F[20][200000]; bool B[200000]; int dp[2][1<<20]; int find(int x) { if (U[x] == x) return x; return U[x] = find(U[x]); } void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (x < y) swap(x, y); U[y] = x; } bool same(int x, int y) { return find(x) == find(y); } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> V; rep(i, N) cin >> X[i]; int t = V; //L[K++] = t; while (t > 0) { t /= 2; L[K++] = t; } rep(e, 2) { rep(k, K) { rep(i, N) U[i] = i; rep(i, N-1) { int d = abs(X[i+1]-X[i]); if (d <= L[k]) unite(i, i+1); } rep(i, N) F[k][i] = find(i); } dp[e][0] = 0; rep(b, 1<<K) { int x = dp[e][b]; rep(i, K) { if ((1<<i) & b) continue; int nx = x; if (x != N) nx = F[i][x]+1; int nb = b | (1<<i); dp[e][nb] = max(dp[e][nb], nx); } } reverse(X, X+N); } rep(i, N) U[i] = i; rep(i, N-1) { int d = X[i+1]-X[i]; if (d <= V) unite(i, i+1); } rep(lb, 1<<K) { int rb = ((1<<K)-1) ^ lb; int a = dp[0][lb], b = N-1-(dp[1][rb]); if (a > b) { // all possible rep(i, N) { cout << "Possible\n"; } return 0; } if (same(a, b)) { B[find(a)] = true; } } rep(x, N) { if (B[find(x)]) cout << "Possible\n"; else cout << "Impossible\n"; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Camel and Oases |
User | funcsr |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 2087 Byte |
Status | AC |
Exec Time | 152 ms |
Memory | 25600 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 | 2 ms | 6400 KB |
00_example_02.txt | AC | 2 ms | 6400 KB |
00_example_03.txt | AC | 2 ms | 8448 KB |
01.txt | AC | 39 ms | 19712 KB |
02.txt | AC | 12 ms | 16896 KB |
03.txt | AC | 40 ms | 19712 KB |
04.txt | AC | 12 ms | 16896 KB |
05.txt | AC | 39 ms | 19712 KB |
06.txt | AC | 53 ms | 20224 KB |
07.txt | AC | 20 ms | 17280 KB |
08.txt | AC | 48 ms | 20096 KB |
09.txt | AC | 22 ms | 17280 KB |
10.txt | AC | 42 ms | 19968 KB |
11.txt | AC | 31 ms | 19584 KB |
12.txt | AC | 44 ms | 19968 KB |
13.txt | AC | 152 ms | 25600 KB |
14.txt | AC | 39 ms | 19712 KB |
15.txt | AC | 12 ms | 16896 KB |
16.txt | AC | 39 ms | 19712 KB |
17.txt | AC | 12 ms | 16896 KB |
18.txt | AC | 37 ms | 19712 KB |
19.txt | AC | 21 ms | 19200 KB |
20.txt | AC | 50 ms | 20096 KB |
21.txt | AC | 19 ms | 17280 KB |
22.txt | AC | 50 ms | 20096 KB |
23.txt | AC | 23 ms | 17280 KB |
24.txt | AC | 41 ms | 19968 KB |
25.txt | AC | 30 ms | 19584 KB |
26.txt | AC | 49 ms | 20096 KB |
27.txt | AC | 149 ms | 25600 KB |
28.txt | AC | 51 ms | 20096 KB |
29.txt | AC | 18 ms | 17152 KB |
30.txt | AC | 48 ms | 20096 KB |
31.txt | AC | 27 ms | 19456 KB |
32.txt | AC | 43 ms | 19968 KB |
33.txt | AC | 28 ms | 19584 KB |
34.txt | AC | 45 ms | 20096 KB |
35.txt | AC | 149 ms | 25600 KB |
36.txt | AC | 39 ms | 19712 KB |
37.txt | AC | 12 ms | 16896 KB |
38.txt | AC | 39 ms | 19712 KB |
39.txt | AC | 12 ms | 16896 KB |
40.txt | AC | 37 ms | 19712 KB |
41.txt | AC | 21 ms | 19200 KB |
42.txt | AC | 37 ms | 19712 KB |
43.txt | AC | 21 ms | 19200 KB |
44.txt | AC | 39 ms | 19712 KB |
45.txt | AC | 21 ms | 19200 KB |
46.txt | AC | 18 ms | 17152 KB |
47.txt | AC | 46 ms | 19968 KB |
48.txt | AC | 28 ms | 19456 KB |
49.txt | AC | 46 ms | 19968 KB |
50.txt | AC | 27 ms | 19456 KB |
51.txt | AC | 45 ms | 19968 KB |
52.txt | AC | 27 ms | 19456 KB |
53.txt | AC | 45 ms | 19968 KB |
54.txt | AC | 27 ms | 19456 KB |
55.txt | AC | 46 ms | 20096 KB |
56.txt | AC | 17 ms | 17152 KB |
57.txt | AC | 44 ms | 19968 KB |
58.txt | AC | 28 ms | 19456 KB |
59.txt | AC | 44 ms | 19968 KB |
60.txt | AC | 28 ms | 19456 KB |
61.txt | AC | 46 ms | 19968 KB |
62.txt | AC | 27 ms | 19456 KB |
63.txt | AC | 46 ms | 19968 KB |
64.txt | AC | 28 ms | 19456 KB |
65.txt | AC | 47 ms | 20096 KB |
66.txt | AC | 2 ms | 6400 KB |
67.txt | AC | 2 ms | 6400 KB |