답안 #471936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471936 2021-09-11T21:56:00 Z sofapuden Aliens (IOI16_aliens) C++14
0 / 100
1 ms 204 KB
    #include "aliens.h"
    #include<bits/stdc++.h>
     
    using namespace std;
     
    typedef long long ll;
     
    const ll INF = (1ll<<60);
     
    bool cmp(pair<ll,ll> &a, pair<ll,ll> &b){
    	if(a.first == b.first)return a.second > b.second;
    	return a.first < b.first;
     
    }
     
    ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
    	vector<pair<ll,ll>> v(n);
    	for(int i = 0; i < n; ++i){
    		v[i] = {r[i],c[i]};
    	}
    	for(int i = 0; i < n; ++i){
    		if(v[i].first > v[i].second)swap(v[i].first,v[i].second);
    	}
    	sort(v.begin(),v.end(),cmp);
    	ll l = 0, ri = INF, ans = INF, bes, cnt;
    	while(l <= ri){
    		ll m = (l+ri)>>1;
    		ll st = v[0].first, cu = v[0].second;
    		ll su = (cu-st+1)*(cu-st+1);
    		ll cn = 1;
    		for(int i = 0; i < n; ++i){
    			if(v[i].second <= cu)continue;
    			ll un = 0;
    			if(v[i].first <= cu){
    				un = (cu-v[i].first+1)*(cu-v[i].first+1);
    			}
    			if((v[i].second-v[i].first+1)*(v[i].second-v[i].first+1)-un+m < (v[i].second-st+1)*(v[i].second-st+1)-(cu-st+1)*(cu-st+1)){
    				cn++;
    				su+=(v[i].second-v[i].first+1)*(v[i].second-v[i].first+1)-un;
    				st = v[i].first;
    				cu = v[i].second;
    			}
    			else{
    				su+=(v[i].second-st+1)*(v[i].second-st+1)-(cu-st+1)*(cu-st+1);
    				cu = v[i].second;
    			}
    		}
    		if(cn < k){
    			cnt = max(cn,cnt);
    			bes = max(m,bes);
    			ans = min(ans,su);
    			ri = m-1;
    		}
          	else if(cn == k){
              	cnt = cn;
              	bes = m;
              	ans = min(ans, su);
              	l = m+1;
            }
    		else{
    			l = m+1;
    		}
    	}
    	return ans-(cnt*bes);
    }

Compilation message

aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:25:42: warning: 'cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |      ll l = 0, ri = INF, ans = INF, bes, cnt;
      |                                          ^~~
aliens.cpp:25:37: warning: 'bes' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |      ll l = 0, ri = INF, ans = INF, bes, cnt;
      |                                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Wrong answer: output = -1152921504606846972, expected = 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Wrong answer: output = -1152921504606846975, expected = 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Wrong answer: output = -1152921504606846972, expected = 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Wrong answer: output = -1152921504606846972, expected = 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Wrong answer: output = -1152921504606846972, expected = 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Wrong answer: output = -1152921504606846972, expected = 4
2 Halted 0 ms 0 KB -