답안 #169156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169156 2019-12-18T18:03:04 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 = 1;
	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){
			ans++;
			while(l != r){
				int mid = (l + r + 1) / 2;
				if(b[mid] <= a[j]){
					l = mid;
				}else{
					r = mid - 1;
				}
			}
			if(b[l] > a[j]){
				l = -1;
			}
			if(l < b.size() - 1){
				bound = b[l + 1];
			}else{
				bound = 1e9;
			}
			//cout << j << ' ' << l << '\n';
			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()){
        ~~^~~~~~~~~~
money.cpp: In function 'int main()':
money.cpp:59:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(l < b.size() - 1){
       ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -