제출 #385778

#제출 시각아이디문제언어결과실행 시간메모리
385778SansPapyrus683Global Warming (CEOI18_glo)C++17
100 / 100
120 ms3172 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;
/**
 * https://oj.uz/problem/view/CEOI18_glo
 * 8 10
 * 7 3 5 12 2 7 3 4 should output 5
 */
int main() {
    int temp_num;
    int max_cheating;
    std::cin >> temp_num >> max_cheating;
    vector<int> temps(temp_num);
    for (int t = 0; t < temp_num; t++) {
        std::cin >> temps[t];
    }
    
    vector<int> pref_longest(temp_num);
    vector<int> min_endings;
    for (int i = 0; i < temp_num; i++) {
        int t = temps[i];
		int pos = std::lower_bound(min_endings.begin(), min_endings.end(), t) - min_endings.begin();
		if (pos == min_endings.size()) {
            min_endings.push_back(t);
        } else {
            min_endings[pos] = t;
        }
        pref_longest[i] = pos + 1;
	}

    int longest = 0;
    vector<int> max_begins;
    for (int i = temp_num - 1; i >= 0; i--) {
        int t = temps[i];
        // negative to keep the binary search happy
        int pos = std::lower_bound(max_begins.begin(), max_begins.end(), -t) - max_begins.begin();
        longest = std::max(longest, pref_longest[i] + pos);
        
        int insert_pos = std::lower_bound(
            max_begins.begin(), max_begins.end(), -t - max_cheating
        ) - max_begins.begin();
        if (insert_pos == max_begins.size()) {
            max_begins.push_back(-t - max_cheating);
        } else {
            max_begins[insert_pos] = -t - max_cheating;
        }
    }
    cout << longest << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

glo.cpp: In function 'int main()':
glo.cpp:27:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   if (pos == min_endings.size()) {
      |       ~~~~^~~~~~~~~~~~~~~~~~~~~
glo.cpp:46:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (insert_pos == max_begins.size()) {
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...