AtCoder Grand Contest 012

Submission #1354018

Source codeソースコード

#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cassert>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

template <typename UnaryPredicate>
ll binsearch(ll l, ll r, UnaryPredicate p) { // [l, r), p is monotone
    assert (l < r);
    -- l;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        (p(m) ? r : l) = m;
    }
    return r; // = min { x | p(x) }
}

int main() {
    // input
    int n, v; scanf("%d%d", &n, &v);
    vector<int> x(n); repeat (i, n) scanf("%d", &x[i]);
    // solve
    vector<int> vs;
    for (int cur_v = v; cur_v > 0; cur_v /= 2) vs.push_back(cur_v);
    vs.push_back(0);
    whole(reverse, vs);
    int k = vs.size();
    vector<vector<pair<int, int> > > range(k); // [l, r]
    repeat (l, n) {
        range[0].emplace_back(l, l);
    }
    repeat (i, k-1) {
        int v = vs[i+1]; // shadowing
        for (int j = 0; j < range[i].size(); ) {
            int l1, r1; tie(l1, r1) = range[i][j];
            ++ j;
            while (j < range[i].size()) {
                int l2, r2; tie(l2, r2) = range[i][j];
                assert (r1 + 1 == l2);
                if (x[l2] - x[r1] <= v) {
                    r1 = r2;
                    ++ j;
                } else {
                    break;
                }
            }
            range[i+1].emplace_back(l1, r1);
        }
    }
    vector<int> dp_l(1 << (k-1));
    vector<int> dp_r(1 << (k-1), n-1);
    repeat (s, 1 << (k-1)) {
        repeat (i, k-1) if (not (s & (1 << i))) {
            int t = s | (1 << i);
            int jr = binsearch(0, range[i].size(), [&](ll j) {
                int l, r; tie(l, r) = range[i][j];
                return dp_l[s] < l;
            }) - 1;
            int jl = binsearch(0, range[i].size(), [&](ll j) {
                int l, r; tie(l, r) = range[i][j];
                return dp_r[s] <= r;
            });
            setmax(dp_l[t], jr < range[i].size() ? range[i][jr].second + 1 :  n);
            setmin(dp_r[t], jl < range[i].size() ? range[i][jl].first  - 1 : -1);
        }
    }
    // output
    for (auto it : range[k-1]) {
        int l, r; tie(l, r) = it;
        bool possible = false;
        repeat (s, 1 << (k-1)) {
            int t = ((1 << (k-1)) - 1) & ~ s;
            if (l <= dp_l[s] and dp_r[t] <= r) {
                possible = true;
                break;
            }
        }
        repeat (i, r - l + 1) {
            printf("%s\n", possible ? "Possible" : "Impossible");
        }
    }
    return 0;
}

Submission

Task問題 E - Camel and Oases
User nameユーザ名 うさぎ
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 1000
Source lengthソースコード長 2928 Byte
File nameファイル名
Exec time実行時間 251 ms
Memory usageメモリ使用量 8304 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt,00_example_03.txt
All 1000 / 1000 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_example_01.txt AC 4 ms 504 KB
00_example_02.txt AC 1 ms 256 KB
00_example_03.txt AC 1 ms 256 KB
01.txt AC 114 ms 2304 KB
02.txt AC 28 ms 768 KB
03.txt AC 110 ms 2304 KB
04.txt AC 26 ms 768 KB
05.txt AC 109 ms 2304 KB
06.txt AC 211 ms 3836 KB
07.txt AC 54 ms 2044 KB
08.txt AC 209 ms 3324 KB
09.txt AC 49 ms 1916 KB
10.txt AC 213 ms 3456 KB
11.txt AC 107 ms 2684 KB
12.txt AC 215 ms 3456 KB
13.txt AC 247 ms 7536 KB
14.txt AC 91 ms 2304 KB
15.txt AC 23 ms 768 KB
16.txt AC 87 ms 2304 KB
17.txt AC 21 ms 768 KB
18.txt AC 79 ms 2304 KB
19.txt AC 45 ms 1280 KB
20.txt AC 216 ms 4348 KB
21.txt AC 53 ms 2300 KB
22.txt AC 205 ms 3708 KB
23.txt AC 51 ms 2428 KB
24.txt AC 206 ms 3712 KB
25.txt AC 104 ms 2556 KB
26.txt AC 215 ms 4348 KB
27.txt AC 246 ms 8176 KB
28.txt AC 217 ms 4092 KB
29.txt AC 52 ms 2172 KB
30.txt AC 229 ms 4860 KB
31.txt AC 103 ms 2688 KB
32.txt AC 211 ms 3840 KB
33.txt AC 106 ms 2940 KB
34.txt AC 213 ms 4220 KB
35.txt AC 251 ms 8304 KB
36.txt AC 98 ms 2304 KB
37.txt AC 23 ms 768 KB
38.txt AC 99 ms 2304 KB
39.txt AC 23 ms 768 KB
40.txt AC 88 ms 2304 KB
41.txt AC 46 ms 1280 KB
42.txt AC 89 ms 2304 KB
43.txt AC 46 ms 1280 KB
44.txt AC 94 ms 2304 KB
45.txt AC 43 ms 1280 KB
46.txt AC 49 ms 2044 KB
47.txt AC 202 ms 3836 KB
48.txt AC 96 ms 2556 KB
49.txt AC 191 ms 3964 KB
50.txt AC 97 ms 2432 KB
51.txt AC 186 ms 3584 KB
52.txt AC 92 ms 2432 KB
53.txt AC 190 ms 3584 KB
54.txt AC 93 ms 2560 KB
55.txt AC 192 ms 3840 KB
56.txt AC 44 ms 1664 KB
57.txt AC 186 ms 3712 KB
58.txt AC 92 ms 2556 KB
59.txt AC 176 ms 3328 KB
60.txt AC 90 ms 2556 KB
61.txt AC 173 ms 3708 KB
62.txt AC 88 ms 2560 KB
63.txt AC 172 ms 3580 KB
64.txt AC 85 ms 2556 KB
65.txt AC 178 ms 3708 KB
66.txt AC 1 ms 256 KB
67.txt AC 1 ms 256 KB