Submission #399479

# Submission time Handle Problem Language Result Execution time Memory
399479 2021-05-05T22:01:09 Z duality Sparklers (JOI17_sparklers) C++11
0 / 100
1 ms 204 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int X[100000];
vplli L,R;
int main() {
    int i;
    int N,K,T;
    scanf("%d %d %d",&N,&K,&T),K--;
    for (i = 0; i < N; i++) scanf("%d",&X[i]);

    int s = 0,e = 1e9;
    while (s < e) {
        int m = (s+e) / 2;

        for (i = 1; i <= K; i++) {
            LLI d = 2*m-(X[i]-X[i-1]);
            if (d > 0) L.pb(mp(d,0));
            else {
                LLI m = d;
                while (!L.empty()) {
                    m = min(m,d+L.back().second);
                    d += L.back().first;
                    L.pop_back();
                    if (d > 0) break;
                }
                L.pb(mp(d,m));
            }
        }
        for (i = N-2; i >= K; i--) {
            LLI d = 2*m-(X[i+1]-X[i]);
            if (d > 0) R.pb(mp(d,0));
            else {
                LLI m = d;
                while (!R.empty()) {
                    m = min(m,d+R.back().second);
                    d += R.back().first;
                    R.pop_back();
                    if (d > 0) break;
                }
                R.pb(mp(d,m));
            }
        }
        reverse(L.begin(),L.end());
        reverse(R.begin(),R.end());
        int a = 0,b = 0;
        LLI ss = 0;
        while ((a < L.size()) || (b < R.size())) {
            if (a == L.size()) {
                if (ss+R[b].second < 0) break;
                else ss += R[b].first,b++;
            }
            else if (b == R.size()) {
                if (ss+L[a].second < 0) break;
                else ss += L[a].first,a++;
            }
            else if (L[a].second > R[b].second) {
                if (ss+L[a].second < 0) break;
                else ss += L[a].first,a++;
            }
            else {
                if (ss+R[b].second < 0) break;
                else ss += R[b].first,b++;
            }
            if (ss < 0) break;
        }
        if ((a == L.size()) && (b == R.size())) e = m;
        else s = m+1;
        L.clear(),R.clear();
    }
    printf("%d\n",(s+T-1)/T);

    return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:102:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         while ((a < L.size()) || (b < R.size())) {
      |                 ~~^~~~~~~~~~
sparklers.cpp:102:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         while ((a < L.size()) || (b < R.size())) {
      |                                   ~~^~~~~~~~~~
sparklers.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |             if (a == L.size()) {
      |                 ~~^~~~~~~~~~~
sparklers.cpp:107:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |             else if (b == R.size()) {
      |                      ~~^~~~~~~~~~~
sparklers.cpp:121:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |         if ((a == L.size()) && (b == R.size())) e = m;
      |              ~~^~~~~~~~~~~
sparklers.cpp:121:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |         if ((a == L.size()) && (b == R.size())) e = m;
      |                                 ~~^~~~~~~~~~~
sparklers.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     scanf("%d %d %d",&N,&K,&T),K--;
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:64:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |     for (i = 0; i < N; i++) scanf("%d",&X[i]);
      |                             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -