Submission #382368

# Submission time Handle Problem Language Result Execution time Memory
382368 2021-03-27T07:38:42 Z kshitij_sodani Aliens (IOI16_aliens) C++14
0 / 100
1 ms 364 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define xx int
//#define endl '\n'



#include "aliens.h"
int mi[1000001];
llo dp[4001][4001];
pair<llo,llo> sect(pair<llo,llo> aa,pair<llo,llo> bb){
	pair<llo,llo> cc={bb.b-aa.b,aa.a-bb.a};
	if(cc.b<0){
		cc.b=-cc.b;
		cc.a=-cc.a;
	}
	return cc;
}
llo eval(pair<llo,llo> aa,llo bb){
	return aa.a*bb+aa.b;
}
long long take_photos(xx n, xx m, xx k,vector<xx> aa,vector<xx> bb) {
	vector<pair<llo,llo>> ss;
    for(llo i=0;i<m;i++){
    	mi[i]=-1;
    }
    for(llo i=0;i<n;i++){
    	mi[min(aa[i],bb[i])]=max(mi[min(aa[i],bb[i])],max(aa[i],bb[i]));
    	
   	}
   	llo cur=-1;
   	for(llo i=0;i<m;i++){
   		if(mi[i]!=-1){
   			if(mi[i]>cur){
   				ss.pb({i,mi[i]});
   				cur=mi[i];
   			}
   		}
   	}
   	for(llo i=1;i<=k;i++){
   		vector<pair<llo,llo>> ee;
   		llo ind=0;
   		for(llo j=0;j<ss.size();j++){
   			dp[j][i]=(ss[j].b-ss[0].a+1);
   			dp[j][i]*=dp[j][i];
   			if(i==1){
   				continue;
   			}
   			if(ee.size()){
   				while(ind+1<ee.size()){
   					if(eval(ee[ind],ss[j].b)<=eval(ee[ind+1],ss[j].b)){
   						ind++;
   					}
   					else{
   						break;
   					}
   				}
   				dp[j][i]=min(dp[j][i],eval(ee[ind],ss[j].b)+ss[j].b*ss[j].b);
   			}
   			/*for(auto jj:ee){
   				dp[j][i]=min(dp[j][i],jj.a*ss[j].b+jj.b+ss[j].b*ss[j].b);
   			}*/
   			/*for(llo ii=0;ii<j;ii++){
   				llo cur=max(ss[ii].b+1-ss[ii+1].a,(llo)0);
   				cur*=cur;
   				
   				dp[j][i]=min(dp[j][i],dp[ii][i-1]+(ss[j].b-ss[ii+1].a+1)*(ss[j].b-ss[ii+1].a+1)-cur);
   			}*/
   			if(j+1<ss.size()){
   				llo a2=max(ss[j].b+1-ss[j+1].a,(llo)0);
   				a2*=a2;
   				a2=-a2;
   				a2+=(ss[j+1].a-1)*(ss[j+1].a-1);
   				a2+=dp[j][i-1];
   				llo mm=-2*(ss[j+1].a-1);
   				pair<llo,llo> ne={mm,a2};
   				while(ee.size()>=2){
   					pair<llo,llo> ac=sect(ee.back(),ee[ee.size()-2]);
   					pair<llo,llo> bc=sect(ee[ee.size()-2],ne);
   					//bc<ac
   					if(bc.a*ac.b<bc.b*ac.a){
   						ee.pop_back();
   					}
   					else{
   						break;
   					}
   				}
   				ee.pb({mm,a2});
   			}
   		}
   	}
  /* 	for(llo i=1;i<=k;i++){
   		for(llo j=0;j<ss.size();j++){
   			cout<<dp[j][i]<<",";
   		}
   		cout<<endl;
   	}*/
   	/*cout<<dp[0][1]<<"::"<<dp[1][1]<<endl;
   	for(auto j:ss){
   		cout<<j.a<<":"<<j.b<<endl;
   	}
   	cout<<endl;
*/
















    return dp[ss.size()-1][k];
}

Compilation message

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:49:19: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |      for(llo j=0;j<ss.size();j++){
      |                  ~^~~~~~~~~~
aliens.cpp:56:19: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |        while(ind+1<ee.size()){
      |              ~~~~~^~~~~~~~~~
aliens.cpp:75:13: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |       if(j+1<ss.size()){
      |          ~~~^~~~~~~~~~
# Verdict Execution time Memory 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 Incorrect 1 ms 364 KB Wrong answer: output = 56, expected = 52
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 Incorrect 1 ms 364 KB Wrong answer: output = 257, expected = 41
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 1 ms 364 KB Wrong answer: output = 56, expected = 52
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 1 ms 364 KB Wrong answer: output = 56, expected = 52
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 1 ms 364 KB Wrong answer: output = 56, expected = 52
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 1 ms 364 KB Wrong answer: output = 56, expected = 52
6 Halted 0 ms 0 KB -