Submission #41258

# Submission time Handle Problem Language Result Execution time Memory
41258 2018-02-15T07:50:03 Z grumpy_gordon Sparklers (JOI17_sparklers) C++14
100 / 100
106 ms 28460 KB
/*
                     .:*+=%@@@@@@=-.
                 .:=@#@@@#@@#######%==*.
              .-=####@######%*-.....:%##%.
            .*@###########%+:--........-%@-
          .*@##############@+--.........-:%-
        .+##################@==%%%%=+*:----+.
      .-@####################%++%@@@@@=+**%@@*
      .%###################@%%@@@###@%+:--%@@%.
     -@###################@%%%%*::*%++:-----=@+.
    -#####################@%=++++++*:-------.-=:
   .+####################@%++*::-:::--::*:::***=:
   .@#####################%=++*::::-:::++*=##@@#@-
  ..#####################@%%=++**:::::**+%@#@%%##-..
   .%####################@@%=+++*+****::*=@######@.
  .=######################@%%==+==++**+=@%@##@###+:...
  -#######################@@@%%%===++=@@@%=++===*::--...
  -########################@@@@@@@%==%%=++==@@:::::*:--.
..:#########################@@@@@@%%======++++::-..:-.--...
%#############################@###@%%@@%==%=%*----.--.::---.
#############################################*-:*:-:---*---- .
#############################################*--*--:---*---:-.
#############################################+--::--::-*::-::.
###########################################+:*-.---.---.:---*-..
###########################################**:-----------------.
##########################################@::**:--::::::--:::::-
###########################################:--:*:::::::::**::*+*
###########################################=:::***::::::**:::*+*
############################@@@@@@#########@+****::::********+++
############################@%%%%%@@@@@@@###%+***::::::::***+==+
############################@%%%%%%%%%%%@####=+:::-::::-::*+=%%+
#############################@%%%%%%%%%%@#####=::--------:*=%@%+
%###########################@%%%%==%%%%%%@##@#=:------..-:+%@@%=
----------------------------------------------
--------------------------------------------
----------------------------------------------
--------------------------------------------
----------------------------------------------

         o###########oo
      o##"          ""##o
    o#"                "##
  o#"                    "#o
 #"  ##              ##   "##
#"                          ##
#  ###################       #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#o                           #
"#o                         ##
 "#o                       ##
  "#o                    o#"
   "#o                  ##
     "#o              o#"
       "#ooo      ooo#######oo
        ###############   "######o
     o###""        "###o      # ###
   o###o     oooo    ###    oo####"
 o###**#     #**#   ############"
 ""##""""""""""###########    #
    # oooooooo#"#**     ##    #
    # #       # # **    ##    #
    #o#       #o#  *****###ooo#
                        ##
                        ##   o###o
                        ## o##***##
               o########## #***#**##o
             o##"   ""###  #***##***#
 o#######o  ###   oo####   ##**####*#
o##"  ""#############""     ##****###
##"         ##              ##*##*###
##          ###              ##### ##
##           ###              # ##  #
##            ##                 #
##             ##
##             ###
##              ###oo
###              ""###
 ###
  ###
*/
#include <bits/stdc++.h>

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
//float __attribute__((aligned(32)))

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

int mysqrt(ll x){
    int l = 0, r = 1e9 + 1;
    while (r - l > 1){
        int m = (l + r) / 2;
        if (m * (ll)m <= x)
            l = m;
        else
            r = m;
    }
    return l;
}

mt19937 rnd(1337);

ll AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;

ll myrand(){
    ll ZR = (XR * AR + YR * BR + CR) % MODR;
    XR = YR;
    YR = ZR;
    return ZR;
}

const int Mod = 1e9 + 7;

int bpow(int x, int y){
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    int ret = bpow(x, y >> 1);
    ret = (ret * (ll)ret) % Mod;
    if (y & 1)
        ret = (ret * (ll)x) % Mod;
    return ret;
}

int bdiv(int x, int y){
    return (x * (ll)bpow(y, Mod - 2)) % Mod;
}

void setmin(int &x, int y){
    x = min(x, y);
}

void setmax(int &x, int y){
    x = max(x, y);
}

void setmin(ll &x, ll y){
    x = min(x, y);
}

void setmax(ll &x, ll y){
    x = max(x, y);
}

int gcd(int a, int b){
    return a ? gcd(b % a, a) : b;
}

const ll llinf = 2e18 + 100;

const double eps = 1e-9;

const int maxn = 1e5 + 100, maxw = 1e6 + 100, inf = 2e9 + 100, sq = 300, mod = 1e9 + 7, LG = 17;

int n, k, t;

int a[maxn];

pair<ll, ll> q[4 * maxn];

void build(int v, int l, int r, vector<ll> &arr){
    if (l == r){
        q[v] = make_pair(arr[l], arr[l]);
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m, arr);
    build(2 * v + 1, m + 1, r, arr);
    q[v] = make_pair(max(q[2 * v].first, q[2 * v + 1].first), min(q[2 * v].second, q[2 * v + 1].second));
}

int get(int v, int tl, int tr, int l, int r, ll val){
    if (l > r || q[v].first < val)
        return -1;
    if (tl == tr)
        return tl;
    int m = (tl + tr) / 2;
    int ret = get(2 * v + 1, m + 1, tr, max(l, m + 1), r, val);
    if (ret != -1)
        return ret;
    return get(2 * v, tl, m, l, min(r, m), val);
}

int get1(int v, int tl, int tr, int l, int r, ll val){
    if (l > r || q[v].second >= val)
        return -1;
    if (tl == tr)
        return tl;
    int m = (tl + tr) / 2;
    int ret = get1(2 * v, tl, m, l, min(r, m), val);
    if (ret != -1)
        return ret;
    return get1(2 * v + 1, m + 1, tr, max(l, m + 1), r, val);
}

ll sp[17][maxn];

int lg[maxn];

bool check(int S){
    vector<ll> A, B;
    A.push_back(0);
    for (int i = k - 1; i >= 0; i--)
        A.push_back(-a[i] + 2 * S * t);
    B.push_back(0);
    for (int i = k; i < n; i++)
        B.push_back(B.back() - a[i] + 2 * S * t);
    build(1, 0, B.size() - 1, B);
    vector<ll> C(B.size());
    C[0] = 0;
    for (int i = 1; i < C.size(); i++)
        C[i] = min(C[i - 1], B[i]);
    int last = 0;
    int l, r;
    l = -1, r = C.size();
    while (r - l > 1){
        int m = (l + r) / 2;
        if (C[m] >= 0)
            l = m;
        else
            r = m;
    }
    last = l;
    ll sum = 0;
    for (int i = 1; i < A.size(); i++){
        int val = A[i];
        sum += val;
        if (val >= 0){
            int vs = get1(1, 0, B.size() - 1, last, B.size() - 1, -sum);
            if (vs == -1)
                vs = B.size();
            last = vs - 1;
        }
        else{
            last = get(1, 0, B.size() - 1, 0, last, -sum);
            if (last == -1)
                return 0;
        }
    }
    return last == B.size() - 1;
}

int main()
{
    #ifdef ONPC
    //ifstream cin("a.in");
    //ofstream cout("a.out");
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
    #else
    //ifstream cin("sprinklers.in");
    //ofstream cout("sprinklers.out");
    //freopen("road.in", "r", stdin);
    //freopen("road.out", "w", stdout);
    #endif // ONPC
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k >> t;
    k--;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if (i)
            a[i - 1] = a[i] - a[i - 1];
    }
    n--;
    int l = -1, r = (1e9 + (ll)2 * t - 1) / (2 * t);
    while (r - l > 1){
        int m = (l + r) / 2;
        if (check(m))
            r = m;
        else
            l = m;
    }
    cout << r;
}

Compilation message

sparklers.cpp: In function 'bool check(int)':
sparklers.cpp:225:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < C.size(); i++)
                       ^
sparklers.cpp:239:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < A.size(); i++){
                       ^
sparklers.cpp:254:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     return last == B.size() - 1;
                 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 308 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 1 ms 664 KB Output is correct
10 Correct 1 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 1 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 664 KB Output is correct
17 Correct 1 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 1 ms 664 KB Output is correct
21 Correct 2 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 308 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 1 ms 664 KB Output is correct
10 Correct 1 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 1 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 664 KB Output is correct
17 Correct 1 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 1 ms 664 KB Output is correct
21 Correct 2 ms 664 KB Output is correct
22 Correct 2 ms 664 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 844 KB Output is correct
29 Correct 3 ms 844 KB Output is correct
30 Correct 2 ms 844 KB Output is correct
31 Correct 2 ms 844 KB Output is correct
32 Correct 2 ms 844 KB Output is correct
33 Correct 2 ms 844 KB Output is correct
34 Correct 2 ms 844 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 2 ms 844 KB Output is correct
37 Correct 2 ms 844 KB Output is correct
38 Correct 2 ms 844 KB Output is correct
39 Correct 2 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 308 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 500 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 1 ms 664 KB Output is correct
10 Correct 1 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 1 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 664 KB Output is correct
17 Correct 1 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 1 ms 664 KB Output is correct
21 Correct 2 ms 664 KB Output is correct
22 Correct 2 ms 664 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 844 KB Output is correct
29 Correct 3 ms 844 KB Output is correct
30 Correct 2 ms 844 KB Output is correct
31 Correct 2 ms 844 KB Output is correct
32 Correct 2 ms 844 KB Output is correct
33 Correct 2 ms 844 KB Output is correct
34 Correct 2 ms 844 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 2 ms 844 KB Output is correct
37 Correct 2 ms 844 KB Output is correct
38 Correct 2 ms 844 KB Output is correct
39 Correct 2 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 45 ms 2412 KB Output is correct
42 Correct 3 ms 2412 KB Output is correct
43 Correct 18 ms 2412 KB Output is correct
44 Correct 102 ms 8296 KB Output is correct
45 Correct 90 ms 8296 KB Output is correct
46 Correct 106 ms 10408 KB Output is correct
47 Correct 102 ms 11404 KB Output is correct
48 Correct 90 ms 11404 KB Output is correct
49 Correct 101 ms 13208 KB Output is correct
50 Correct 87 ms 13208 KB Output is correct
51 Correct 97 ms 15252 KB Output is correct
52 Correct 82 ms 15252 KB Output is correct
53 Correct 96 ms 17072 KB Output is correct
54 Correct 77 ms 17072 KB Output is correct
55 Correct 90 ms 17072 KB Output is correct
56 Correct 101 ms 19996 KB Output is correct
57 Correct 84 ms 19996 KB Output is correct
58 Correct 77 ms 19996 KB Output is correct
59 Correct 72 ms 19996 KB Output is correct
60 Correct 81 ms 19996 KB Output is correct
61 Correct 73 ms 20680 KB Output is correct
62 Correct 96 ms 24984 KB Output is correct
63 Correct 79 ms 24984 KB Output is correct
64 Correct 79 ms 24984 KB Output is correct
65 Correct 86 ms 25248 KB Output is correct
66 Correct 91 ms 26180 KB Output is correct
67 Correct 80 ms 27276 KB Output is correct
68 Correct 77 ms 27396 KB Output is correct
69 Correct 77 ms 28460 KB Output is correct