답안 #202171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202171 2020-02-14T03:39:23 Z Segtree Bulldozer (JOI17_bulldozer) C++14
75 / 100
986 ms 66584 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<complex>
#include<math.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef complex<long double> C;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define PI acosl(-1)
#define N 2048
ll n,x[N],y[N],w[N];

ll dat1[2*N],dat2[2*N],dat3[2*N];
void init(){
    rep(i,2*N){
	dat1[i]=1e17;
	dat2[i]=-1e17;
	dat3[i]=0;
    }
}
void upd(ll i,ll x){
    //cout<<"update"<<i<<" "<<x<<" ";
    i+=N;
    dat1[i]=dat2[i]=x;
    for(;i>1;i>>=1){
	dat1[i/2]=min(dat1[i],dat1[i^1]);
	dat2[i/2]=max(dat2[i],dat2[i^1]);
	int a=i,b=i^1; if(a>b)swap(a,b);
	dat3[i/2]=max(dat2[b]-dat1[a],max(dat3[a],dat3[b]));
    }
    //cout<<dat3[1]<<endl;
}
ll rsm(){
    return dat3[1];
}
/*ll rsm(){
    ll mi=0,res=0;
    rep(i,n){
	chmin(mi,dat1[N+i+1]);
	chmax(res,dat1[N+i+1]-mi);
    }
    assert(res>=dat3[1]);
    return res;
}*/

ll pl[N];
ll swp(int a,int b){//cout<<"swp"<<w[a]<<" "<<w[b]<<endl;
    if(pl[a]>pl[b])swap(a,b);
    upd(pl[a]+1,dat1[N+pl[a]]+w[b]);
    swap(pl[a],pl[b]);//cout<<"rsm"<<rsm()<<endl;
    return rsm();
}

struct qry{
    ld arg;
    ll a,b;
    bool operator<(const qry&key)const{
	return this->arg<key.arg;
    }
};

int main(){
    cin>>n;
    rep(i,n){
	cin>>x[i]>>y[i]>>w[i];
    }
    rep(i,n)rep(j,n-1){
	bool sw=0;
	if(y[j]!=y[j+1])sw=y[j]>y[j+1];
	else if(x[j]!=x[j+1])sw=x[j]<x[j+1];
	if(sw){
	    swap(x[j],x[j+1]);
	    swap(y[j],y[j+1]);
	    swap(w[j],w[j+1]);
	}
    }
    init();
    ll rui=0;
    upd(0,rui);
    rep(i,n){
	rui+=w[i];
	upd(i+1,rui);
	pl[i]=i;
    }
    
    vector<qry> Q;
    rep(i,n)rep(j,i){
	ld vl=atan2(y[i]-y[j],x[i]-x[j]);
	ld vr=atan2(y[j]-y[i],x[j]-x[i]);
	//cout<<"atan"<<w[i]<<" "<<w[j]<<" "<<vl<<" "<<vr<<endl;
	Q.push_back((struct qry){max(vl,vr),i,j});
    }
    sort(all(Q));
    ll ans=0;
    chmax(ans,rsm());
    rep(i,Q.size()){
	chmax(ans,swp(Q[i].a,Q[i].b));
    }
    cout<<ans<<endl;
}


Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:18:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,n) for(int i=0;i<n;i++)
bulldozer.cpp:108:9:
     rep(i,Q.size()){
         ~~~~~~~~~~             
bulldozer.cpp:108:5: note: in expansion of macro 'rep'
     rep(i,Q.size()){
     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 7 ms 936 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 7 ms 888 KB Output is correct
6 Correct 7 ms 888 KB Output is correct
7 Correct 7 ms 888 KB Output is correct
8 Correct 7 ms 888 KB Output is correct
9 Correct 7 ms 888 KB Output is correct
10 Correct 7 ms 888 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 7 ms 888 KB Output is correct
22 Correct 7 ms 888 KB Output is correct
23 Correct 7 ms 892 KB Output is correct
24 Correct 7 ms 888 KB Output is correct
25 Correct 7 ms 888 KB Output is correct
26 Correct 7 ms 888 KB Output is correct
27 Correct 7 ms 888 KB Output is correct
28 Correct 7 ms 888 KB Output is correct
29 Correct 7 ms 888 KB Output is correct
30 Correct 7 ms 888 KB Output is correct
31 Correct 7 ms 888 KB Output is correct
32 Correct 7 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 7 ms 936 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 7 ms 888 KB Output is correct
6 Correct 7 ms 888 KB Output is correct
7 Correct 7 ms 888 KB Output is correct
8 Correct 7 ms 888 KB Output is correct
9 Correct 7 ms 888 KB Output is correct
10 Correct 7 ms 888 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 7 ms 888 KB Output is correct
22 Correct 7 ms 888 KB Output is correct
23 Correct 7 ms 892 KB Output is correct
24 Correct 7 ms 888 KB Output is correct
25 Correct 7 ms 888 KB Output is correct
26 Correct 7 ms 888 KB Output is correct
27 Correct 7 ms 888 KB Output is correct
28 Correct 7 ms 888 KB Output is correct
29 Correct 7 ms 888 KB Output is correct
30 Correct 7 ms 888 KB Output is correct
31 Correct 7 ms 888 KB Output is correct
32 Correct 7 ms 888 KB Output is correct
33 Correct 915 ms 66284 KB Output is correct
34 Correct 908 ms 66328 KB Output is correct
35 Correct 921 ms 66328 KB Output is correct
36 Correct 924 ms 66328 KB Output is correct
37 Correct 928 ms 66456 KB Output is correct
38 Correct 915 ms 66456 KB Output is correct
39 Correct 921 ms 66328 KB Output is correct
40 Correct 924 ms 66328 KB Output is correct
41 Correct 910 ms 66340 KB Output is correct
42 Correct 927 ms 66328 KB Output is correct
43 Correct 902 ms 66484 KB Output is correct
44 Correct 907 ms 66332 KB Output is correct
45 Correct 916 ms 66328 KB Output is correct
46 Correct 921 ms 66328 KB Output is correct
47 Correct 905 ms 66328 KB Output is correct
48 Correct 901 ms 66456 KB Output is correct
49 Correct 915 ms 66456 KB Output is correct
50 Correct 900 ms 66504 KB Output is correct
51 Correct 890 ms 66584 KB Output is correct
52 Correct 923 ms 66456 KB Output is correct
53 Correct 927 ms 66328 KB Output is correct
54 Correct 906 ms 66380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 888 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 7 ms 936 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 7 ms 888 KB Output is correct
6 Correct 7 ms 888 KB Output is correct
7 Correct 7 ms 888 KB Output is correct
8 Correct 7 ms 888 KB Output is correct
9 Correct 7 ms 888 KB Output is correct
10 Correct 7 ms 888 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 7 ms 888 KB Output is correct
22 Correct 7 ms 888 KB Output is correct
23 Correct 7 ms 892 KB Output is correct
24 Correct 7 ms 888 KB Output is correct
25 Correct 7 ms 888 KB Output is correct
26 Correct 7 ms 888 KB Output is correct
27 Correct 7 ms 888 KB Output is correct
28 Correct 7 ms 888 KB Output is correct
29 Correct 7 ms 888 KB Output is correct
30 Correct 7 ms 888 KB Output is correct
31 Correct 7 ms 888 KB Output is correct
32 Correct 7 ms 888 KB Output is correct
33 Correct 915 ms 66284 KB Output is correct
34 Correct 908 ms 66328 KB Output is correct
35 Correct 921 ms 66328 KB Output is correct
36 Correct 924 ms 66328 KB Output is correct
37 Correct 928 ms 66456 KB Output is correct
38 Correct 915 ms 66456 KB Output is correct
39 Correct 921 ms 66328 KB Output is correct
40 Correct 924 ms 66328 KB Output is correct
41 Correct 910 ms 66340 KB Output is correct
42 Correct 927 ms 66328 KB Output is correct
43 Correct 902 ms 66484 KB Output is correct
44 Correct 907 ms 66332 KB Output is correct
45 Correct 916 ms 66328 KB Output is correct
46 Correct 921 ms 66328 KB Output is correct
47 Correct 905 ms 66328 KB Output is correct
48 Correct 901 ms 66456 KB Output is correct
49 Correct 915 ms 66456 KB Output is correct
50 Correct 900 ms 66504 KB Output is correct
51 Correct 890 ms 66584 KB Output is correct
52 Correct 923 ms 66456 KB Output is correct
53 Correct 927 ms 66328 KB Output is correct
54 Correct 906 ms 66380 KB Output is correct
55 Correct 932 ms 66328 KB Output is correct
56 Correct 932 ms 66328 KB Output is correct
57 Correct 925 ms 66328 KB Output is correct
58 Correct 986 ms 66328 KB Output is correct
59 Correct 934 ms 66328 KB Output is correct
60 Correct 938 ms 66328 KB Output is correct
61 Correct 921 ms 66364 KB Output is correct
62 Correct 916 ms 66332 KB Output is correct
63 Correct 920 ms 66328 KB Output is correct
64 Correct 929 ms 66328 KB Output is correct
65 Correct 905 ms 66352 KB Output is correct
66 Correct 899 ms 66328 KB Output is correct
67 Correct 910 ms 66364 KB Output is correct
68 Correct 905 ms 66456 KB Output is correct
69 Correct 905 ms 66328 KB Output is correct
70 Correct 905 ms 66328 KB Output is correct
71 Correct 912 ms 66332 KB Output is correct
72 Correct 910 ms 66328 KB Output is correct
73 Correct 940 ms 66456 KB Output is correct
74 Correct 930 ms 66304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 888 KB Output isn't correct
2 Halted 0 ms 0 KB -