답안 #364767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364767 2021-02-10T01:16:53 Z nandonathaniel Aliens (IOI16_aliens) C++14
4 / 100
1 ms 492 KB
#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long LL;
typedef pair<LL,LL> pii;
typedef pair<pii,LL> piii;
vector<pii> V,point;
vector<piii> line;
LL N,M,K,dp[100005],opt[100005];

bool cmpV(pii A,pii B){
	if(A.fi!=B.fi)return A.fi<B.fi;
	return A.se>B.se;
}

pii tpot(pii satu,pii dua){
	pii jwb;
	jwb.fi=dua.se-satu.se;
	jwb.se=satu.fi-dua.fi;
	return jwb;
}

bool cmp(pii a,pii b){
	return a.fi*b.se<=a.se*b.fi;
}

LL sq(LL a){
	return a*a;
}

LL F(LL penalty){
	line.clear();
	for(LL i=1;i<=N;i++){
		LL x=V[i].se;
		LL intersect;
		if(V[i].first>V[i-1].second)intersect=0;
		else intersect=sq(V[i-1].second-V[i].first+1);
		piii now={{2*V[i].fi,-(V[i].fi*V[i].fi-2*V[i].fi+1-intersect+dp[i-1])},i-1};
		LL skg=line.size()-1,prev=line.size()-2;
		while(skg>0 && cmp(tpot(now.fi,line[skg].fi),tpot(now.fi,line[prev].fi))){
			//hapus yang gamasuk hull
			line.pop_back();
			skg--;
			prev--;
		}
		line.push_back(now);
		LL ki=1,ka=(LL)line.size()-1,add=-1e18,id;
		while(ki<=ka){
			LL mid=(ki+ka)/2;
			LL l=line[mid-1].fi.fi*x+line[mid-1].fi.se;
			LL r=line[mid].fi.fi*x+line[mid].fi.se;
			if(l>add){
				add=l;
				id=line[mid-1].se;
			}
			if(r>add){
				add=r;
				id=line[mid].se;
			}
			if(l>r)ka=mid-1;
			else ki=mid+1;
		}
		if(line.size()==1){
			add=line[0].fi.fi*x+line[0].fi.se;
//			cout << "takdir " << add << '\n';
			id=line[0].se;
		}
		dp[i]=-add+sq(V[i].se)+2*V[i].se+penalty;
		opt[i]=id;
//		cout << "yuhu " << dp[i] << " " << opt[i] << '\n';
	}
	LL noww=N,byk=0;
	while(noww!=0){
		byk++;
		noww=opt[noww];
	}
	return byk;
}

LL take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
	N=(LL)n;M=(LL)m;K=(LL)k;
	for(LL i=0;i<N;i++){
		if(r[i]>c[i])swap(r[i],c[i]);
		point.push_back(make_pair((LL)r[i],(LL)c[i]));
	}
	sort(point.begin(),point.end(),cmpV);
	point.erase(unique(point.begin(),point.end()),point.end());
	V.push_back(make_pair(-1,-1));
	V.push_back(point[0]);
	pii last=point[0];
	for(LL i=1;i<N;i++){
		if(point[i].se>last.se){
			V.push_back(point[i]);
			last=point[i];
		}
	}
	N=V.size()-1;
	K=min(K,N);
	LL ki=0,ka=1e12,res;
	while(ki<ka){
		LL mid=(ki+ka+1)/2;
		if(F(mid)>=K)ki=mid;
		else ka=mid-1;
	}
	F(ki);
	res=dp[N]-ki*K;
	return res;
}

Compilation message

aliens.cpp: In function 'LL F(LL)':
aliens.cpp:71:9: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |   opt[i]=id;
      |   ~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Correct answer: answer = 4
2 Correct 1 ms 364 KB Correct answer: answer = 4
3 Correct 1 ms 364 KB Correct answer: answer = 4
4 Correct 1 ms 364 KB Correct answer: answer = 12
5 Correct 1 ms 364 KB Correct answer: answer = 52
6 Correct 1 ms 364 KB Correct answer: answer = 210
7 Correct 1 ms 364 KB Correct answer: answer = 88
8 Correct 1 ms 364 KB Correct answer: answer = 7696
9 Correct 1 ms 384 KB Correct answer: answer = 1
10 Correct 1 ms 364 KB Correct answer: answer = 2374
11 Correct 1 ms 364 KB Correct answer: answer = 9502
12 Correct 1 ms 364 KB Correct answer: answer = 49
13 Correct 1 ms 364 KB Correct answer: answer = 151
14 Correct 1 ms 492 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 368 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 384 KB Correct answer: answer = 10000
19 Correct 1 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Correct answer: answer = 1
2 Correct 1 ms 364 KB Correct answer: answer = 4
3 Correct 1 ms 364 KB Correct answer: answer = 1
4 Correct 1 ms 364 KB Correct answer: answer = 5
5 Correct 1 ms 364 KB Correct answer: answer = 41
6 Correct 1 ms 364 KB Correct answer: answer = 71923
7 Correct 1 ms 364 KB Correct answer: answer = 77137
8 Incorrect 1 ms 364 KB Wrong answer: output = 759, expected = 764
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Correct answer: answer = 4
2 Correct 1 ms 364 KB Correct answer: answer = 4
3 Correct 1 ms 364 KB Correct answer: answer = 4
4 Correct 1 ms 364 KB Correct answer: answer = 12
5 Correct 1 ms 364 KB Correct answer: answer = 52
6 Correct 1 ms 364 KB Correct answer: answer = 210
7 Correct 1 ms 364 KB Correct answer: answer = 88
8 Correct 1 ms 364 KB Correct answer: answer = 7696
9 Correct 1 ms 384 KB Correct answer: answer = 1
10 Correct 1 ms 364 KB Correct answer: answer = 2374
11 Correct 1 ms 364 KB Correct answer: answer = 9502
12 Correct 1 ms 364 KB Correct answer: answer = 49
13 Correct 1 ms 364 KB Correct answer: answer = 151
14 Correct 1 ms 492 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 368 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 384 KB Correct answer: answer = 10000
19 Correct 1 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 384 KB Correct answer: answer = 1
22 Correct 1 ms 364 KB Correct answer: answer = 4
23 Correct 1 ms 364 KB Correct answer: answer = 1
24 Correct 1 ms 364 KB Correct answer: answer = 5
25 Correct 1 ms 364 KB Correct answer: answer = 41
26 Correct 1 ms 364 KB Correct answer: answer = 71923
27 Correct 1 ms 364 KB Correct answer: answer = 77137
28 Incorrect 1 ms 364 KB Wrong answer: output = 759, expected = 764
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Correct answer: answer = 4
2 Correct 1 ms 364 KB Correct answer: answer = 4
3 Correct 1 ms 364 KB Correct answer: answer = 4
4 Correct 1 ms 364 KB Correct answer: answer = 12
5 Correct 1 ms 364 KB Correct answer: answer = 52
6 Correct 1 ms 364 KB Correct answer: answer = 210
7 Correct 1 ms 364 KB Correct answer: answer = 88
8 Correct 1 ms 364 KB Correct answer: answer = 7696
9 Correct 1 ms 384 KB Correct answer: answer = 1
10 Correct 1 ms 364 KB Correct answer: answer = 2374
11 Correct 1 ms 364 KB Correct answer: answer = 9502
12 Correct 1 ms 364 KB Correct answer: answer = 49
13 Correct 1 ms 364 KB Correct answer: answer = 151
14 Correct 1 ms 492 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 368 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 384 KB Correct answer: answer = 10000
19 Correct 1 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 384 KB Correct answer: answer = 1
22 Correct 1 ms 364 KB Correct answer: answer = 4
23 Correct 1 ms 364 KB Correct answer: answer = 1
24 Correct 1 ms 364 KB Correct answer: answer = 5
25 Correct 1 ms 364 KB Correct answer: answer = 41
26 Correct 1 ms 364 KB Correct answer: answer = 71923
27 Correct 1 ms 364 KB Correct answer: answer = 77137
28 Incorrect 1 ms 364 KB Wrong answer: output = 759, expected = 764
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Correct answer: answer = 4
2 Correct 1 ms 364 KB Correct answer: answer = 4
3 Correct 1 ms 364 KB Correct answer: answer = 4
4 Correct 1 ms 364 KB Correct answer: answer = 12
5 Correct 1 ms 364 KB Correct answer: answer = 52
6 Correct 1 ms 364 KB Correct answer: answer = 210
7 Correct 1 ms 364 KB Correct answer: answer = 88
8 Correct 1 ms 364 KB Correct answer: answer = 7696
9 Correct 1 ms 384 KB Correct answer: answer = 1
10 Correct 1 ms 364 KB Correct answer: answer = 2374
11 Correct 1 ms 364 KB Correct answer: answer = 9502
12 Correct 1 ms 364 KB Correct answer: answer = 49
13 Correct 1 ms 364 KB Correct answer: answer = 151
14 Correct 1 ms 492 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 368 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 384 KB Correct answer: answer = 10000
19 Correct 1 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 384 KB Correct answer: answer = 1
22 Correct 1 ms 364 KB Correct answer: answer = 4
23 Correct 1 ms 364 KB Correct answer: answer = 1
24 Correct 1 ms 364 KB Correct answer: answer = 5
25 Correct 1 ms 364 KB Correct answer: answer = 41
26 Correct 1 ms 364 KB Correct answer: answer = 71923
27 Correct 1 ms 364 KB Correct answer: answer = 77137
28 Incorrect 1 ms 364 KB Wrong answer: output = 759, expected = 764
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Correct answer: answer = 4
2 Correct 1 ms 364 KB Correct answer: answer = 4
3 Correct 1 ms 364 KB Correct answer: answer = 4
4 Correct 1 ms 364 KB Correct answer: answer = 12
5 Correct 1 ms 364 KB Correct answer: answer = 52
6 Correct 1 ms 364 KB Correct answer: answer = 210
7 Correct 1 ms 364 KB Correct answer: answer = 88
8 Correct 1 ms 364 KB Correct answer: answer = 7696
9 Correct 1 ms 384 KB Correct answer: answer = 1
10 Correct 1 ms 364 KB Correct answer: answer = 2374
11 Correct 1 ms 364 KB Correct answer: answer = 9502
12 Correct 1 ms 364 KB Correct answer: answer = 49
13 Correct 1 ms 364 KB Correct answer: answer = 151
14 Correct 1 ms 492 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 368 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 384 KB Correct answer: answer = 10000
19 Correct 1 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 384 KB Correct answer: answer = 1
22 Correct 1 ms 364 KB Correct answer: answer = 4
23 Correct 1 ms 364 KB Correct answer: answer = 1
24 Correct 1 ms 364 KB Correct answer: answer = 5
25 Correct 1 ms 364 KB Correct answer: answer = 41
26 Correct 1 ms 364 KB Correct answer: answer = 71923
27 Correct 1 ms 364 KB Correct answer: answer = 77137
28 Incorrect 1 ms 364 KB Wrong answer: output = 759, expected = 764
29 Halted 0 ms 0 KB -