답안 #68521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68521 2018-08-17T09:00:09 Z tempytemptemp 금 캐기 (IZhO14_divide) C++14
100 / 100
215 ms 3396 KB
/*
  We found Despacito 5 during contest (not clickbait)
*/
#include	<iostream>
#include	<cstdio>
#include	<vector>
#include 	<set>
#include	<map>
#include	<queue>
#include	<stack>
#include	<algorithm>
#include	<cstring>
#include	<cfloat>
#include	<cmath>
#include	<cassert>
#include	<locale>
#include	<string>
#include	<bitset>
#include	<functional>
#include	<climits>
#include	<iomanip>
using namespace std;

#define read(x)     freopen(x,"r",stdin)
#define write(x)    freopen(x,"w",stdout)
#define cl(a,b)	    memset(a,b,sizeof(a))
#define all(x)      x.begin(),x.end()
#define rall(x)     x.rbegin(),x.rend()
#define ll          long long
#define ld          long double
#define vec         vector
#define vi          vec<int>
#define heap        priority_queue
#define res         reserve
#define pb          push_back
#define f(x,y,z)    for(int x=(y); x<(z); x++)
#define fd(x,y,z)   for(int x=(y); x>=(z); x--)
#define fit(x,y)    for(auto x: y)
#define srt(x)      sort(all(x))
#define rsrt(x)     sort(rall(x))
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define pii         pair<int,int>
#define ppi         pair<pii,int>
#define pip         pair<int,pii>
#define mp          make_pair
#define f1          first
#define s2          second
#define cdbg(x)     cerr<<#x<<" = "<<x<<",\t";
#define cdbl        cerr<<"\n----------\n";
#define pow2(x)     ((x)*(x))
#define edist(x1, y1, x2, y2) (sqrt((pow2(x1-x2)+pow2(y1-y2))))
#define mdist(x1, y1, x2, y2) (abs((x1)-(x2))+abs((y1)-(y2)))
#define y1          FullSensei
#define left        (si<<1)
#define right       ((si<<1)+1)
#define pi          3.141592653589793
#define popcount    __builtin_popcount
#define spc			' '
#define endl		'\n'
#define in			insert
#define up_b		upper_bound
#define low_b 		lower_bound
#define Decimal		fixed<<setprecision(20)

bool checkbit(int x,int y){return (x&(1<<y));}
int setbit(int x,int y){return (x^(1<<y));}
const int dirs[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int mod=1e9+7;
const int p1=805306457;
const int p2=1610612741;
const int INF=1e9;
const int N=1e5;
struct mine{
	int x, g, d;
//	mine(int xx, int gg, int dd){
//		x=xx;
//		g=gg;
//		d=dd;
//	}
};
mine a[N+7];
int n;

ll preg[N+7];
ll pred[N+7];

int xlb(int ss, int se, int i){
	if(ss<1 || se>n)
		return -1;
	if(ss>se)
		return -1;
	if(ss==se){
		if(a[ss].x == i)
			return ss;
		else
			return -1;
	}
	int jump=1;
	while(ss+jump*2<=se)	jump*=2;
	for(;jump>0;jump/=2){
		int mid=ss+jump;
//		cerr<<ss<<spc<<jump<<spc<<mid<<spc<<se<<spc<<i<<endl;
		if(mid>se)
			continue;
		if(a[mid].x>i){
			se=mid-1;
		}
		else if(a[mid].x==i){
			return mid;
		}
		else{
			ss=mid;
		}
	}
	return ss;
}

int main(){
	scanf("%d",&n);
	f(i,1,n+1){
		cin>>a[i].x>>a[i].g>>a[i].d;
	}
	f(i,1,n+1){
		preg[i]=preg[i-1]+a[i].g;
		pred[i]=pred[i-1]+a[i].d;
	}
	ll ans=0;
	int r=0;
	f(i,1,n+1){
		fd(j,n,max(i,r+1)){
			ll totd=pred[j] - pred[i-1];
			if(totd >= a[j].x-a[i].x){
				ans=max(ans, preg[j] - preg[i-1]);
				r=j;
				break;
			}
			else{
				j=min(j,xlb(i,j,a[i].x+totd)+1);
				if(j<1 || j>n)
					break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:119:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 3 ms 540 KB Output is correct
11 Correct 3 ms 540 KB Output is correct
12 Correct 3 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 540 KB Output is correct
2 Correct 3 ms 672 KB Output is correct
3 Correct 3 ms 672 KB Output is correct
4 Correct 3 ms 672 KB Output is correct
5 Correct 5 ms 672 KB Output is correct
6 Correct 4 ms 672 KB Output is correct
7 Correct 4 ms 672 KB Output is correct
8 Correct 3 ms 712 KB Output is correct
9 Correct 5 ms 712 KB Output is correct
10 Correct 4 ms 712 KB Output is correct
11 Correct 14 ms 712 KB Output is correct
12 Correct 9 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 744 KB Output is correct
2 Correct 13 ms 860 KB Output is correct
3 Correct 15 ms 860 KB Output is correct
4 Correct 64 ms 1896 KB Output is correct
5 Correct 80 ms 2028 KB Output is correct
6 Correct 164 ms 3396 KB Output is correct
7 Correct 122 ms 3396 KB Output is correct
8 Correct 121 ms 3396 KB Output is correct
9 Correct 146 ms 3396 KB Output is correct
10 Correct 199 ms 3396 KB Output is correct
11 Correct 165 ms 3396 KB Output is correct
12 Correct 215 ms 3396 KB Output is correct