Submission #43025650
Source Code Expand
// LUOGU_RID: 113472244
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
}
const int N = 2e5 + 10;
int n, v, a[N], pp[25][N], qq[25][N], f[1 << 18], g[1 << 18], lim[N];
signed main() {
// freopen("13.txt", "r", stdin);
// cout << log2(2e5) + 1 << endl;
read(n), read(v);
F(i, 1, n) read(a[i]);
int k = log2(v) + 1;
// cout << "! " << log2(3) << endl;
// cout << k << " " << n << endl;
F(i, 0, k) {
// cout << "! " << i << endl;
int pos = 1;
F(j, 1, n)
if (j == n || a[j + 1] - a[j] > (v >> i)) {
F(k, pos, j) pp[i][k] = j;
pos = j + 1;
}
// puts("%");
pp[0][n + 1] = n;
pos = n;
DF(j, n, 1)
if (j == 1 || a[j] - a[j - 1] > (v >> i)) {
// if (i == k) cout << j << endl;
F(k, j, pos) qq[i][k] = j;
pos = j - 1;
}
// puts("$");
qq[0][0] = 1;
}
// puts("OK");
int full = (1 << k) - 1;
F(i, 1, full)
F(j, 1, k)
if ((i >> (j - 1)) & 1)
chkmax(f[i], pp[j][f[i ^ (1 << (j - 1))] + 1]);
// cout << f[full] << endl;
g[0] = n + 1;
F(i, 1, full) {
g[i] = n;
F(j, 1, k)
if ((i >> (j - 1)) & 1)
chkmin(g[i], qq[j][g[i ^ (1 << (j - 1))] - 1]);
// cout << "! " << i << " " << g[i] << endl;
}
F(i, 1, n) lim[i] = n + 1;
F(i, 0, full) {
if (f[i] + 1 >= g[full ^ i]) {
F(j, 1, n) puts("Possible");
return 0;
} chkmin(lim[f[i] + 1], g[full ^ i] - 1);
}
DF(i, n - 1, 1) chkmin(lim[i], lim[i + 1]);//, cout << lim[i] << endl;
F(i, 1, n) {
// cout << qq[0][i] << " " << pp[0][i] << " " << lim[qq[0][i]] << endl;
puts(lim[qq[0][i]] <= pp[0][i] ? "Possible" : "Impossible");
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Camel and Oases |
| User | ast123 |
| Language | C++ (GCC 9.2.1) |
| Score | 1000 |
| Code Size | 2166 Byte |
| Status | AC |
| Exec Time | 88 ms |
| Memory | 36908 KiB |
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 | 8 ms | 3644 KiB |
| 00_example_02.txt | AC | 2 ms | 3696 KiB |
| 00_example_03.txt | AC | 2 ms | 3696 KiB |
| 01.txt | AC | 48 ms | 5912 KiB |
| 02.txt | AC | 13 ms | 4328 KiB |
| 03.txt | AC | 46 ms | 5928 KiB |
| 04.txt | AC | 14 ms | 4296 KiB |
| 05.txt | AC | 42 ms | 5864 KiB |
| 06.txt | AC | 49 ms | 10448 KiB |
| 07.txt | AC | 20 ms | 6816 KiB |
| 08.txt | AC | 47 ms | 8872 KiB |
| 09.txt | AC | 24 ms | 7332 KiB |
| 10.txt | AC | 46 ms | 7520 KiB |
| 11.txt | AC | 29 ms | 8416 KiB |
| 12.txt | AC | 45 ms | 7780 KiB |
| 13.txt | AC | 88 ms | 36852 KiB |
| 14.txt | AC | 41 ms | 5960 KiB |
| 15.txt | AC | 15 ms | 4228 KiB |
| 16.txt | AC | 41 ms | 5756 KiB |
| 17.txt | AC | 18 ms | 4284 KiB |
| 18.txt | AC | 42 ms | 5748 KiB |
| 19.txt | AC | 20 ms | 4808 KiB |
| 20.txt | AC | 50 ms | 9876 KiB |
| 21.txt | AC | 18 ms | 6988 KiB |
| 22.txt | AC | 46 ms | 9452 KiB |
| 23.txt | AC | 21 ms | 7788 KiB |
| 24.txt | AC | 46 ms | 7772 KiB |
| 25.txt | AC | 28 ms | 7944 KiB |
| 26.txt | AC | 48 ms | 9420 KiB |
| 27.txt | AC | 84 ms | 36892 KiB |
| 28.txt | AC | 49 ms | 9864 KiB |
| 29.txt | AC | 19 ms | 6716 KiB |
| 30.txt | AC | 52 ms | 9644 KiB |
| 31.txt | AC | 29 ms | 7056 KiB |
| 32.txt | AC | 46 ms | 7716 KiB |
| 33.txt | AC | 31 ms | 7784 KiB |
| 34.txt | AC | 47 ms | 8664 KiB |
| 35.txt | AC | 87 ms | 36908 KiB |
| 36.txt | AC | 42 ms | 5892 KiB |
| 37.txt | AC | 15 ms | 4232 KiB |
| 38.txt | AC | 38 ms | 5960 KiB |
| 39.txt | AC | 14 ms | 4300 KiB |
| 40.txt | AC | 37 ms | 5764 KiB |
| 41.txt | AC | 26 ms | 4980 KiB |
| 42.txt | AC | 40 ms | 5832 KiB |
| 43.txt | AC | 26 ms | 4748 KiB |
| 44.txt | AC | 43 ms | 5848 KiB |
| 45.txt | AC | 21 ms | 4808 KiB |
| 46.txt | AC | 17 ms | 6624 KiB |
| 47.txt | AC | 48 ms | 8544 KiB |
| 48.txt | AC | 31 ms | 7264 KiB |
| 49.txt | AC | 49 ms | 8544 KiB |
| 50.txt | AC | 28 ms | 7096 KiB |
| 51.txt | AC | 48 ms | 8052 KiB |
| 52.txt | AC | 30 ms | 6940 KiB |
| 53.txt | AC | 46 ms | 8192 KiB |
| 54.txt | AC | 29 ms | 7032 KiB |
| 55.txt | AC | 48 ms | 8816 KiB |
| 56.txt | AC | 17 ms | 6076 KiB |
| 57.txt | AC | 50 ms | 8592 KiB |
| 58.txt | AC | 30 ms | 7476 KiB |
| 59.txt | AC | 44 ms | 7600 KiB |
| 60.txt | AC | 31 ms | 7472 KiB |
| 61.txt | AC | 47 ms | 8492 KiB |
| 62.txt | AC | 32 ms | 7272 KiB |
| 63.txt | AC | 46 ms | 8604 KiB |
| 64.txt | AC | 32 ms | 7368 KiB |
| 65.txt | AC | 49 ms | 8576 KiB |
| 66.txt | AC | 6 ms | 3536 KiB |
| 67.txt | AC | 2 ms | 3520 KiB |