제출 #955256

#제출 시각아이디문제언어결과실행 시간메모리
955256GithubGlobal Warming (CEOI18_glo)C++17
100 / 100
49 ms4808 KiB
#include <iostream> #include <vector> #include <queue> #include <cstring> #include <map> #include <climits> #include <cmath> #include <algorithm> #include <stack> #include <set> using namespace std; #define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define ll long long #define pr printf #define sc scanf #define fi first #define si second const ll MOD = 1e9+7; const ll INF = 1e17; void setIO(string s){ freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } int find_lis(vector<int> a){ vector<int> dp; for (int i: a){ int pos = lower_bound(dp.begin(), dp.end(), i)-dp.begin(); if (pos == dp.size()){ dp.push_back(i); }else{ dp[pos] = i; } } return dp.size(); } int main() { speedup int n, d; cin >> n >> d; vector<int> a(n); for (int i = 0; i < n; i++){ cin >> a[i]; } vector<int> pref(n); vector<int> dp; for (int i = 0; i < n; i++){ int pos = lower_bound(dp.begin(), dp.end(), a[i])-dp.begin(); pref[i] = pos+1; if (pos == dp.size()){ dp.push_back(a[i]); }else{ dp[pos] = a[i]; } } int ans = dp.size(); dp.clear(); for (int i = n-1; i >= 0; i--){ int pos = lower_bound(dp.begin(), dp.end(), -a[i]+d) - dp.begin(); ans = max(pref[i]+pos, ans); pos = lower_bound(dp.begin(), dp.end(), -a[i]) - dp.begin(); if (pos == dp.size()){ dp.push_back(-a[i]); }else{ dp[pos] = -a[i]; } } cout << ans << endl; return 0; }

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

glo.cpp: In function 'int find_lis(std::vector<int>)':
glo.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if (pos == dp.size()){
      |             ~~~~^~~~~~~~~~~~
glo.cpp: In function 'int main()':
glo.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         if (pos == dp.size()){
      |             ~~~~^~~~~~~~~~~~
glo.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         if (pos == dp.size()){
      |             ~~~~^~~~~~~~~~~~
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...