답안 #25345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25345 2017-06-21T08:34:24 Z RezwanArefin01 Aliens (IOI16_aliens) C++14
0 / 100
0 ms 2028 KB
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct seg {
	ll l, r; 
	bool operator < (const seg &p) const {
		return l == p.l ? r > p.r : l < p.l;
	}
}; 

struct CHT{
	vector<ll> m, b;
	int ptr = 0; 
	void clear() {
		m.clear(), b.clear(), ptr = 0;
	}
	bool bad(int l1, int l2, int l3) {
		return 1.0 * (b[l3] - b[l1]) * (m[l1] - m[l2]) <= 1.0 * (b[l2] - b[l1]) * (m[l1] - m[l3]); 
	}
	void add(int _m, int _b) {
		cout<<"@@ " << _m<<" " << _b<<endl;
		m.push_back(_m);
		b.push_back(_b); 
		int s = m.size(); 
		while(s >= 3 && bad(s-3, s-2, s-1)) {
			s--;
			m.erase(m.end()-2);
			b.erase(b.end()-2);
		} 
	} 
	ll f(int i, ll x) { return m[i] * x + b[i]; } 

	ll query(ll x) { cout<<"@@query " << x<<endl;
		if(ptr >= m.size()) ptr = m.size()-1;
		while(ptr < m.size()-1 && 
			f(ptr+1, x) < f(ptr, x)) ptr++;
		cout<<"@return " << f(ptr, x) << endl;
		return f(ptr, x);
	}
};

#define sq(a) ((a) * (a))

ll take_photos(int n, int m, int kk, std::vector<int> r, std::vector<int> c) { 
	vector<seg> tmp, v;
	for(int i=0; i<n; i++) {
		if(r[i] > c[i]) 
			swap(r[i], c[i]);
		tmp.push_back({r[i], c[i]});
	} sort(tmp.begin(), tmp.end());

	for(int i=0; i<n; i++) {
		if(v.size() && v.back().l <= tmp[i].l && tmp[i].r <= v.back().r) continue;
		v.push_back(tmp[i]); 
	}
	n = v.size(); 
	ll dp[kk+1][n+1];
	memset(dp, 0x3f, sizeof dp); 
	for(int i=1; i<=n; i++) {
		dp[1][i] = sq(v[i-1].r - v[0].l + 1);
	}
	ll Min = dp[1][n];
	CHT ds; 
	for(int k=2; k<=kk; k++) {
		ds.clear(); 
		ds.add(0, 0);
		for(int i=k; i<=n; i++) {
			dp[k][i] = ds.query(v[i-1].r) + sq(v[i-1].r); 

			ll c = 0; 
			int j = i - 1;
			if(v[j].l <= v[j-1].r) 
				c = sq(v[j-1].r - v[j].l);
			ds.add(-2 * (v[i].l - 1), dp[k-1][i] + sq(v[i].l - 1) - c);

			/*for(int j=0; j<i; j++) { 
				ll len = sq(v[i-1].r - v[j].l + 1);
				if(j && v[j].l <= v[j-1].r) 
					len -= sq(v[j-1].r - v[j].l+ 1);
				dp[k][i] = min(dp[k][i], dp[k-1][j] + len);
			}*/
		}
		Min = min(Min, dp[k][n]); 
		for(int i=1; i<=n; i++) cout<<dp[k][i]<<" "; 
		cout<<endl;
	} 
    return Min;
}

Compilation message

aliens.cpp: In member function 'll CHT::query(ll)':
aliens.cpp:36:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(ptr >= m.size()) ptr = m.size()-1;
          ^
aliens.cpp:37:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(ptr < m.size()-1 && 
             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Correct answer: answer = 4
2 Incorrect 0 ms 2028 KB Wrong secret!
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Correct answer: answer = 1
2 Correct 0 ms 2028 KB Correct answer: answer = 4
3 Incorrect 0 ms 2028 KB Wrong secret!
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Correct answer: answer = 4
2 Incorrect 0 ms 2028 KB Wrong secret!
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Correct answer: answer = 4
2 Incorrect 0 ms 2028 KB Wrong secret!
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Correct answer: answer = 4
2 Incorrect 0 ms 2028 KB Wrong secret!
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Correct answer: answer = 4
2 Incorrect 0 ms 2028 KB Wrong secret!
3 Halted 0 ms 0 KB -