Submission #373935

# Submission time Handle Problem Language Result Execution time Memory
373935 2021-03-06T07:59:46 Z rrrr10000 Bulldozer (JOI17_bulldozer) C++14
0 / 100
2 ms 748 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<PP> vpp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define pb emplace_back
#define fi first
#define se second
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
const ll inf=1001001001001001001;
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
class segtree{
    vi seg;ll N=1;
public:
    segtree(vi v){
        while(N<v.size())N*=2;
        seg=vi(N*2-1);
        rep(i,v.size())seg[i+N-1]=v[i];
        for(ll i=N-2;i>=0;i--)seg[i]=max(seg[i*2+1],seg[i*2+2]);
    }
    void add(ll i,ll x){
        i+=N-1;
        seg[i]+=x;
        while(i>0){
            i=(i-1)/2;
            seg[i]=max(seg[i*2+1],seg[i*2+2]);
        }
    }
    ll get(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if(r==-1)r=N;
        if(a<=l&&r<=b)return seg[k];
        if(r<=a||b<=l)return 0;
        ll c1=get(a,b,k*2+1,l,(l+r)/2);
        ll c2=get(a,b,k*2+2,(l+r)/2,r);
        return max(c1,c2);
    }
    void debug(ll n){
        vi res;
        rep(i,n)res.pb(seg[i+N-1]);
        outv(res);
    }
};
int main(){
    ll n;cin>>n;
    vvi tmp(n,vi(3));
    rep(i,n)rep(j,3)cin>>tmp[i][j];
    sort(all(tmp));
    vp v(n);vi val(n);rep(i,n)v[i]=P(tmp[i][0],tmp[i][1]);rep(i,n)val[i]=tmp[i][2];
    vpp srt;
    rep(i,n)rep(j,i){
        ll a=v[i].fi-v[j].fi,b=v[i].se-v[j].se;
        if(a!=0){
            ll g=gcd(abs(a),abs(b));
            a/=g;b/=g;
            srt.pb(P(a,b),P(j,i));
        }
        else srt.pb(P(1,1001001001),P(j,i));
    }
    auto cmp=[&](PP a,PP b){
        if(a.fi!=b.fi)return a.fi.se*b.fi.fi<a.fi.fi*b.fi.se;
        return a.se<b.se;
    };
    sort(all(srt),cmp);
    ll ans=0;
    for(ll x:val)chmax(ans,x);
    vi num(n),mun(n);
    rep(i,n)num[i]=i;
    rep(i,n)mun[i]=i;
    rep(i,srt.size()){
        ll a=srt[i].se.fi,b=srt[i].se.se;
        ll A=mun[a],B=mun[b];
        assert(B==A+1);
        chmax(ans,val[a]+val[b]);
        ll t=val[a]+val[b];
        for(int i=A-1;i>=0;i--){
            t+=val[num[i]];chmax(ans,t);
        }
        t=val[a]+val[b];
        for(int i=B+1;i<n;i++){
            t+=val[num[i]];chmax(ans,t);
        }
        swap(num[A],num[B]);
        swap(mun[a],mun[b]);
    }
    out(ans);
}

Compilation message

bulldozer.cpp: In constructor 'segtree::segtree(vi)':
bulldozer.cpp:34:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         while(N<v.size())N*=2;
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -