Submission #488535

# Submission time Handle Problem Language Result Execution time Memory
488535 2021-11-19T13:40:26 Z i_am_noob Sparklers (JOI17_sparklers) C++17
0 / 100
1 ms 204 KB
#pragma GCC target("avx2")
#include<bits/stdc++.h>
//#include<x86intrin.h>
//#include<immintrin.h>
//#pragma GCC optimize("unroll-loops")
using namespace std;

#define ll long long
#define int ll
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
//#define ceiling(a,b) (((a)+(b)-1)/(b))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif

inline char readchar(){
    const int maxn=1000000;
    static char buf[maxn],*p=buf,*q=buf;
    if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF;
    else return *p++;
}
inline int readint(){
    int c=readchar(),x=0,neg=0;
    while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar();
    if(c=='-') neg=1,c=readchar();
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar();
    return neg?-x:x;
}

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=100005;
//i_am_noob
//#define v8si __attribute__ (( vector_size(32) )) signed
int n,k,s,a[maxn];

pii Merge(pii x, pii y){
    return {max(x.first,y.first-x.second),x.second+y.second};
}

void orzck(){
    cin >> n >> k >> s;
    k--;
    rep(n) cin >> a[i];
    int l=1,r=490e8/s;
    while(l<r){
        int mid=l+r>>1;
        vector<pii> vec1,vec2;
        rep3(i,k-1,0){
            vec1.pb({max(-(2*s*mid-(a[i+1]-a[i])),0ll),2*s*mid-(a[i+1]-a[i])});
            while(sz(vec1)>1&&(vec1[sz(vec1)-2].second<=0||vec1.back().second>=0)){
                pii p=Merge(vec1[sz(vec1)-2],vec1.back());
                rep1(_,2) vec1.pop_back();
                vec1.pb(p);
            }
        }
        rep2(i,k+1,n){
            vec2.pb({max(-(2*s*mid-(a[i]-a[i-1])),0ll),2*s*mid-(a[i]-a[i-1])});
            while(sz(vec2)>1&&(vec2[sz(vec2)-2].second<=0||vec2.back().second>=0)){
                pii p=Merge(vec2[sz(vec2)-2],vec2.back());
                rep1(_,2) vec2.pop_back();
                vec2.pb(p);
            }
        }
        bug(mid);
        for(auto p: vec1) bug(p.first,p.second);
        for(auto p: vec2) bug(p.first,p.second);
        pii p={0,0},de[4];
        rep(4) de[i]={0,0};
        int cnt=0;
        if(sz(vec1)&&vec1[0].second>=0) de[0]=vec1[0];
        if(sz(vec2)&&vec2[0].second>=0) de[1]=vec2[0];
        if(sz(vec1)&&vec1.back().second<0) de[2]=vec1.back();
        if(sz(vec2)&&vec2.back().second<0) de[3]=vec2.back();
        p=min(Merge(de[0],de[1]),Merge(de[1],de[0]));
        p=Merge(p,min(Merge(de[2],de[3]),Merge(de[3],de[2])));
        if(p.first==0) r=mid;
        else l=mid+1;
    }
    cout << l << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    #ifdef i_am_noob
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    freopen("output2.txt","w",stderr);
    #endif
    cout << fixed << setprecision(15);
    orzck();
    return 0;
}

Compilation message

sparklers.cpp: In function 'void orzck()':
sparklers.cpp:64:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |         int mid=l+r>>1;
      |                 ~^~
sparklers.cpp:30:18: warning: statement has no effect [-Wunused-value]
   30 | #define bug(...) 826
      |                  ^~~
sparklers.cpp:82:9: note: in expansion of macro 'bug'
   82 |         bug(mid);
      |         ^~~
sparklers.cpp:30:18: warning: statement has no effect [-Wunused-value]
   30 | #define bug(...) 826
      |                  ^~~
sparklers.cpp:83:27: note: in expansion of macro 'bug'
   83 |         for(auto p: vec1) bug(p.first,p.second);
      |                           ^~~
sparklers.cpp:83:18: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   83 |         for(auto p: vec1) bug(p.first,p.second);
      |                  ^
sparklers.cpp:30:18: warning: statement has no effect [-Wunused-value]
   30 | #define bug(...) 826
      |                  ^~~
sparklers.cpp:84:27: note: in expansion of macro 'bug'
   84 |         for(auto p: vec2) bug(p.first,p.second);
      |                           ^~~
sparklers.cpp:84:18: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   84 |         for(auto p: vec2) bug(p.first,p.second);
      |                  ^
sparklers.cpp:87:13: warning: unused variable 'cnt' [-Wunused-variable]
   87 |         int cnt=0;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Incorrect 1 ms 204 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Incorrect 1 ms 204 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Incorrect 1 ms 204 KB Output isn't correct
11 Halted 0 ms 0 KB -