답안 #169155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169155 2019-12-18T17:54:40 Z tselmegkh Money (IZhO17_money) C++14
0 / 100
2 ms 376 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> mergesort(vector<int> a, vector<int> b){
	int i = 0, j = 0;
	vector<int> res;
	while(i < a.size() && j < b.size()){
		if(a[i] < b[j]){
			res.push_back(a[i]);
			i++;
		}else{
			res.push_back(b[j]);
			j++;
		}
	}
	while(i < a.size()){
		res.push_back(a[i]);
		i++;
	}
	while(j < b.size()){
		res.push_back(b[j]);
		j++;
	}
	return res;
}
int main(){
	int n;
	cin >> n;
	vector<int> a(n);

	int ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int j = 1;
	vector<int> b;
	b.push_back(a[0]);
	while(a[j] >= a[j - 1] && j < n){
		b.push_back(a[j]);
		j++;
	}
	int cnt = 0, bound = 0;
	vector<int> cursegment;
	while(j < n){
		int l = 0, r = b.size() - 1;
		if(cnt == 0){
			while(l != r){
				int mid = (l + r + 1) / 2;
				if(b[mid] <= a[j]){
					l = mid;
				}else{
					r = mid - 1;
				}
			}
			if(l < n - 1){
				bound = l + 1;
			}else{
				bound = 1e9;
			}
			cnt++;
			cursegment.push_back(a[j]);
			j++;
		}else{
			if(a[j] < a[j - 1]){
				cnt = 0;
				b = mergesort(b, cursegment);
				cursegment.clear();
				ans++;
				continue;
			}else{
				if(a[j] <= bound){
					cursegment.push_back(a[j]);
					cnt++;
					j++;
				}else{
					cnt = 0;
					b = mergesort(b, cursegment);
					cursegment.clear();
					ans++;
				}
			}
		}	
	}
	cout << ans << '\n';
}

Compilation message

money.cpp: In function 'std::vector<int> mergesort(std::vector<int>, std::vector<int>)':
money.cpp:7:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < a.size() && j < b.size()){
        ~~^~~~~~~~~~
money.cpp:7:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < a.size() && j < b.size()){
                        ~~^~~~~~~~~~
money.cpp:16:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < a.size()){
        ~~^~~~~~~~~~
money.cpp:20:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(j < b.size()){
        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -