답안 #382764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382764 2021-03-28T07:14:58 Z kshitij_sodani Aliens (IOI16_aliens) C++14
4 / 100
3 ms 620 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[100001];
llo cnt[100001];
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;
}
vector<pair<llo,llo>> ss;
pair<llo,llo> check(llo mid){
   vector<pair<llo,llo>> ee;
      llo ind=0;
      map<llo,llo> xz;
      for(llo j=0;j<ss.size();j++){
         dp[j]=(ss[j].b-ss[0].a+1);
         dp[j]*=dp[j];
         cnt[j]=1;
         /*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;
               }
            }
            llo ac=eval(ee[ind],ss[j].b)+ss[j].b*ss[j].b;
            if(ac<dp[j]){
               dp[j]=ac;
               cnt[j]=1+cnt[xz[ee[ind].a]];
            }
         }
        /* if(mid==1023 and j==2){
            cout<<ind<<",,"<<endl;
            for(auto j:ee){
               cout<<j.a<<"::"<<j.b<<endl;
            }
         }*/
         dp[j]+=mid;
         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];
            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});
            xz[ne.a]=j;
         }
      }
    /*  cout<<mid<<"::";
      for(int i=0;i<ss.size();i++){
         cout<<dp[i]<<",";
      }
      cout<<endl;*/
      return {cnt[ss.size()-1],dp[ss.size()-1]-mid*cnt[ss.size()-1]};
}
long long take_photos(xx n, xx m, xx k,vector<xx> aa,vector<xx> bb) {
	  ss.clear();
    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(auto j:ss){
         cout<<j.a<<"::"<<j.b<<endl;
      }*/
      k=min(k,(int)ss.size());
   	/*for(int i=0;i<ss.size();i++){
   		for(int j=1;j<=k+1;j++){
   			dp[i].pb(0);
   		}
   	}*/
      llo low=0;
      for(llo i=39;i>=0;i--){
            if(i>0){
               if((1LL<<(i-1))>m*m){
                  continue;
               }
            }
         //if(low-(1LL<<i)>=0){
            if(check(low+(1LL<<i)).a>=k){
               low+=(1LL<<i);
            }
         //}
      }
      assert(check(low).a==k);

     // cout<<low<<"::"<<endl;
     // cout<<check(low).a<<":"<<check(low).b<<endl;

      //cout<<check(low).a<<"::"<<endl;

      return check(low).b;
   /*	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);
   			}
   			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 'std::pair<long long int, long long int> check(llo)':
aliens.cpp:34:20: 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]
   34 |       for(llo j=0;j<ss.size();j++){
      |                   ~^~~~~~~~~~
aliens.cpp:42:24: 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]
   42 |             while(ind+1<ee.size()){
      |                   ~~~~~^~~~~~~~~~
aliens.cpp:63:16: 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]
   63 |          if(j+1<ss.size()){
      |             ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 364 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 364 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 364 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 364 KB Correct answer: answer = 10000
19 Correct 2 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
# 결과 실행 시간 메모리 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 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 Runtime error 3 ms 620 KB Execution killed with signal 6
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 364 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 364 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 364 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 364 KB Correct answer: answer = 10000
19 Correct 2 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 364 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 Runtime error 3 ms 620 KB Execution killed with signal 6
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 364 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 364 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 364 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 364 KB Correct answer: answer = 10000
19 Correct 2 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 364 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 Runtime error 3 ms 620 KB Execution killed with signal 6
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 364 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 364 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 364 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 364 KB Correct answer: answer = 10000
19 Correct 2 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 364 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 Runtime error 3 ms 620 KB Execution killed with signal 6
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 364 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 364 KB Correct answer: answer = 7550
15 Correct 1 ms 364 KB Correct answer: answer = 7220
16 Correct 1 ms 364 KB Correct answer: answer = 7550
17 Correct 1 ms 364 KB Correct answer: answer = 10000
18 Correct 1 ms 364 KB Correct answer: answer = 10000
19 Correct 2 ms 364 KB Correct answer: answer = 624
20 Correct 1 ms 364 KB Correct answer: answer = 10000
21 Correct 1 ms 364 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 Runtime error 3 ms 620 KB Execution killed with signal 6
29 Halted 0 ms 0 KB -