제출 #1174172

#제출 시각아이디문제언어결과실행 시간메모리
1174172InvMODGlobal Warming (CEOI18_glo)C++20
100 / 100
37 ms3780 KiB
#include<bits/stdc++.h> using namespace std; #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() void solve() { int n,x; cin >> n >> x; vector<int> a(n + 1); for(int i = 1; i <= n; i++){ cin >> a[i]; } /* + it's optimal to increase / decrease prefix or suffix of array + increase is the same as decrease + -> prefix LIS and suffix LDS <(") */ vector<int> lis, pref(n + 1), suf(n + 1); for(int i = 1; i <= n; i++){ if(!sz(lis)){ pref[i] = 1; lis.push_back(a[i]); } else{ int p = lower_bound(all(lis), a[i]) - lis.begin(); pref[i] = p + 1; if(p == sz(lis)){ lis.push_back(a[i]); } else lis[p] = a[i]; } } vector<int> lds; for(int i = n; i >= 1; i--){ if(!sz(lds)){ suf[i] = 1; // increase all suffix by x lds.push_back(-(a[i] + x)); } else{ int place_i = lower_bound(all(lds), -a[i]) - lds.begin() - 1; suf[i] = place_i + 2; int p = lower_bound(all(lds), -(a[i] + x)) - lds.begin(); if(p == sz(lds)){ lds.push_back(-(a[i] + x)); } else lds[p] = -(a[i] + x); } } int answer = 0; for(int i = 1; i <= n; i++){ answer = max(answer, pref[i] + suf[i] - 1); } cout << answer << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } solve(); return 0; }

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

glo.cpp: In function 'int32_t main()':
glo.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(name".OUT", "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...