답안 #777560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777560 2023-07-09T10:41:32 Z a_aguilo Sails (IOI07_sails) C++14
50 / 100
1000 ms 4024 KB
#include<bits/stdc++.h>

using namespace std;

int N;
long long ans;
const int maxN = 100002;
const int maxH = 100002;
pair<int, int> masts[maxN];

vector<int> merge(vector<int>& V1, vector<int>& V2){
	int pos1 = 0;
	int pos2 = 0;
	vector<int> res;
	for(int i = 0; i < (V1.size() + V2.size()); ++i){
		if(pos1 < V1.size() && pos2 < V2.size()){
			if(V1[pos1] > V2[pos2]){
				res.push_back(V1[pos1]);
				pos1++;
			}else{
				res.push_back(V2[pos2]);
				pos2++;
			}
		}else if(pos1 < V1.size()){
			res.push_back(V1[pos1]);
			pos1++;
		}else{
			res.push_back(V2[pos2]);
			pos2++;
		}
	}
	return res;
}

int main(){
	ans = 0;
	cin >> N;
	for(int i = 0; i < N; ++i) cin >> masts[i].first >> masts[i].second;
	vector<int> occupation;
	sort(masts, masts+N);
	for(int i = 0; i < N; ++i){
		int h = masts[i].first;
		int k = masts[i].second;
		vector<int> prov;
		while(occupation.size() < h)occupation.push_back(0);
		for(int j = 0; j < k; ++j){
			prov.push_back(occupation[occupation.size()-1] + 1);
			ans += occupation[occupation.size()-1];
			occupation.pop_back();
		}
		reverse(prov.begin(), prov.end());
		occupation = merge(occupation, prov);
	}
	cout << ans << endl;
	return 0;
}

Compilation message

sails.cpp: In function 'std::vector<int> merge(std::vector<int>&, std::vector<int>&)':
sails.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int i = 0; i < (V1.size() + V2.size()); ++i){
      |                 ~~^~~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:16:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   if(pos1 < V1.size() && pos2 < V2.size()){
      |      ~~~~~^~~~~~~~~~~
sails.cpp:16:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   if(pos1 < V1.size() && pos2 < V2.size()){
      |                          ~~~~~^~~~~~~~~~~
sails.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   }else if(pos1 < V1.size()){
      |            ~~~~~^~~~~~~~~~~
sails.cpp: In function 'int main()':
sails.cpp:45:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |   while(occupation.size() < h)occupation.push_back(0);
      |         ~~~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 340 KB Output is correct
2 Correct 139 ms 2092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 478 ms 1072 KB Output is correct
2 Correct 326 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 1252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 1812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1067 ms 4024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 2596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1072 ms 2796 KB Time limit exceeded
2 Halted 0 ms 0 KB -