답안 #476070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476070 2021-09-24T17:24:19 Z AdamGS Aliens (IOI16_aliens) C++14
4 / 100
1 ms 204 KB
#include "aliens.h"
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
const ll INF=1e18+7;
vector<pair<ll,ll>>V;
ll dp[LIM], ile[LIM];
ll wynik(int a, int b, ll c) {
	ll x=abs(V[b].nd-V[a].st)+1;
	x=x*x+c;
	if(a) {
		x+=dp[a-1];
		ll y=abs(V[a].st-V[a-1].nd)+1;
		if(V[a].st<=V[a-1].nd) x-=y*y;
	}
	return x;
}
void licz(ll c) {
	int n=V.size();
	rep(i, n) {
		dp[i]=wynik(i, i, c);
		ile[i]=1;
		if(i) ile[i]+=ile[i-1];
		if(!i) continue;
		int p=0, k=i-1;
		while(p<k) {
			int sr=(p+k)/2;
			if(wynik(sr, i, c)>wynik(sr+1, i, c)) p=sr+1; else k=sr;
		}
		if(wynik(p, i, c)<=dp[i]) {
			dp[i]=wynik(p, i, c);
			ile[i]=1;
			if(p) ile[i]+=ile[p-1];
		}
	}
}
ll take_photos(int N, int M, int K, vector<int>r, vector<int>c) {
	ll n=N, m=M, k=K;
	vector<pair<int,int>>S;
	rep(i, n) {
		if(r[i]<=c[i]) S.pb({r[i], -c[i]});
		else S.pb({c[i], -r[i]});
	}
	sort(all(S));
	int ma=-1;
	for(auto i : S) {
		if(ma>=-i.nd) continue;
		V.pb({i.st, -i.nd});
		ma=max(ma, -i.nd);
	}
	if(k==1) {
		ll x=abs(V[0].st-V.back().nd)+1;
		return x*x;
	}
	ll po=0, ko=10000000000000;
	while(po<ko) {
		ll sr=(po+ko)/2;
		licz(sr);
		if(ile[V.size()-1]<=k) ko=sr; else po=sr+1;
	}
	licz(po);
	return dp[V.size()-1]-po*k;
}

Compilation message

aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:45:10: warning: unused variable 'm' [-Wunused-variable]
   45 |  ll n=N, m=M, k=K;
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 0 ms 204 KB Correct answer: answer = 4
3 Correct 0 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 0 ms 204 KB Correct answer: answer = 52
6 Correct 0 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Correct 0 ms 204 KB Correct answer: answer = 7696
9 Correct 0 ms 204 KB Correct answer: answer = 1
10 Correct 0 ms 204 KB Correct answer: answer = 2374
11 Correct 0 ms 204 KB Correct answer: answer = 9502
12 Correct 0 ms 204 KB Correct answer: answer = 49
13 Correct 1 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 0 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 0 ms 204 KB Correct answer: answer = 10000
18 Correct 0 ms 204 KB Correct answer: answer = 10000
19 Correct 0 ms 204 KB Correct answer: answer = 624
20 Correct 0 ms 204 KB Correct answer: answer = 10000
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 1
2 Correct 0 ms 204 KB Correct answer: answer = 4
3 Correct 0 ms 204 KB Correct answer: answer = 1
4 Correct 1 ms 204 KB Correct answer: answer = 5
5 Correct 1 ms 204 KB Correct answer: answer = 41
6 Incorrect 0 ms 204 KB Wrong answer: output = 91891, expected = 71923
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 0 ms 204 KB Correct answer: answer = 4
3 Correct 0 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 0 ms 204 KB Correct answer: answer = 52
6 Correct 0 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Correct 0 ms 204 KB Correct answer: answer = 7696
9 Correct 0 ms 204 KB Correct answer: answer = 1
10 Correct 0 ms 204 KB Correct answer: answer = 2374
11 Correct 0 ms 204 KB Correct answer: answer = 9502
12 Correct 0 ms 204 KB Correct answer: answer = 49
13 Correct 1 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 0 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 0 ms 204 KB Correct answer: answer = 10000
18 Correct 0 ms 204 KB Correct answer: answer = 10000
19 Correct 0 ms 204 KB Correct answer: answer = 624
20 Correct 0 ms 204 KB Correct answer: answer = 10000
21 Correct 0 ms 204 KB Correct answer: answer = 1
22 Correct 0 ms 204 KB Correct answer: answer = 4
23 Correct 0 ms 204 KB Correct answer: answer = 1
24 Correct 1 ms 204 KB Correct answer: answer = 5
25 Correct 1 ms 204 KB Correct answer: answer = 41
26 Incorrect 0 ms 204 KB Wrong answer: output = 91891, expected = 71923
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 0 ms 204 KB Correct answer: answer = 4
3 Correct 0 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 0 ms 204 KB Correct answer: answer = 52
6 Correct 0 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Correct 0 ms 204 KB Correct answer: answer = 7696
9 Correct 0 ms 204 KB Correct answer: answer = 1
10 Correct 0 ms 204 KB Correct answer: answer = 2374
11 Correct 0 ms 204 KB Correct answer: answer = 9502
12 Correct 0 ms 204 KB Correct answer: answer = 49
13 Correct 1 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 0 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 0 ms 204 KB Correct answer: answer = 10000
18 Correct 0 ms 204 KB Correct answer: answer = 10000
19 Correct 0 ms 204 KB Correct answer: answer = 624
20 Correct 0 ms 204 KB Correct answer: answer = 10000
21 Correct 0 ms 204 KB Correct answer: answer = 1
22 Correct 0 ms 204 KB Correct answer: answer = 4
23 Correct 0 ms 204 KB Correct answer: answer = 1
24 Correct 1 ms 204 KB Correct answer: answer = 5
25 Correct 1 ms 204 KB Correct answer: answer = 41
26 Incorrect 0 ms 204 KB Wrong answer: output = 91891, expected = 71923
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 0 ms 204 KB Correct answer: answer = 4
3 Correct 0 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 0 ms 204 KB Correct answer: answer = 52
6 Correct 0 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Correct 0 ms 204 KB Correct answer: answer = 7696
9 Correct 0 ms 204 KB Correct answer: answer = 1
10 Correct 0 ms 204 KB Correct answer: answer = 2374
11 Correct 0 ms 204 KB Correct answer: answer = 9502
12 Correct 0 ms 204 KB Correct answer: answer = 49
13 Correct 1 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 0 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 0 ms 204 KB Correct answer: answer = 10000
18 Correct 0 ms 204 KB Correct answer: answer = 10000
19 Correct 0 ms 204 KB Correct answer: answer = 624
20 Correct 0 ms 204 KB Correct answer: answer = 10000
21 Correct 0 ms 204 KB Correct answer: answer = 1
22 Correct 0 ms 204 KB Correct answer: answer = 4
23 Correct 0 ms 204 KB Correct answer: answer = 1
24 Correct 1 ms 204 KB Correct answer: answer = 5
25 Correct 1 ms 204 KB Correct answer: answer = 41
26 Incorrect 0 ms 204 KB Wrong answer: output = 91891, expected = 71923
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Correct answer: answer = 4
2 Correct 0 ms 204 KB Correct answer: answer = 4
3 Correct 0 ms 204 KB Correct answer: answer = 4
4 Correct 0 ms 204 KB Correct answer: answer = 12
5 Correct 0 ms 204 KB Correct answer: answer = 52
6 Correct 0 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Correct 0 ms 204 KB Correct answer: answer = 7696
9 Correct 0 ms 204 KB Correct answer: answer = 1
10 Correct 0 ms 204 KB Correct answer: answer = 2374
11 Correct 0 ms 204 KB Correct answer: answer = 9502
12 Correct 0 ms 204 KB Correct answer: answer = 49
13 Correct 1 ms 204 KB Correct answer: answer = 151
14 Correct 1 ms 204 KB Correct answer: answer = 7550
15 Correct 0 ms 204 KB Correct answer: answer = 7220
16 Correct 1 ms 204 KB Correct answer: answer = 7550
17 Correct 0 ms 204 KB Correct answer: answer = 10000
18 Correct 0 ms 204 KB Correct answer: answer = 10000
19 Correct 0 ms 204 KB Correct answer: answer = 624
20 Correct 0 ms 204 KB Correct answer: answer = 10000
21 Correct 0 ms 204 KB Correct answer: answer = 1
22 Correct 0 ms 204 KB Correct answer: answer = 4
23 Correct 0 ms 204 KB Correct answer: answer = 1
24 Correct 1 ms 204 KB Correct answer: answer = 5
25 Correct 1 ms 204 KB Correct answer: answer = 41
26 Incorrect 0 ms 204 KB Wrong answer: output = 91891, expected = 71923
27 Halted 0 ms 0 KB -