# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
892175 | Peter2017 | Financial Report (JOI21_financial) | C++14 | 691 ms | 198228 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18 + 69;
template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}
int n;
int k;
int D;
int a[N];
int f[(int)7e3 + 2][(int)7e3 + 2];
deque <int> dq[(int)7e3 + 2];
vector <int> value;
void load(){
cin.tie(0)->sync_with_stdio(0);
if (fopen(name".inp", "r")){
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
}
void input(){
cin >> n >> D;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
}
void compress(){
for (int i = 1; i <= n; i++)
value.push_back(a[i]);
sort(value.begin(), value.end());
value.erase(unique(value.begin(), value.end()), value.end());
for (int i = 1; i <= n; i++)
a[i] = lower_bound(value.begin(), value.end(), a[i]) - value.begin() + 1;
k = (int)value.size();
}
namespace subtask3{
void solve(){
mem(f, -0x3f);
for (int i = 1; i <= n; i++){
f[i][a[i]] = 1;
for (int j = 1; j <= k; j++){
if (dq[j].size() && dq[j].front() < i - D) dq[j].pop_front();
if (dq[j].size()) maxi(f[i][max(a[i], j)], f[dq[j].front()][j] + (j < a[i]));
}
for (int j = 1; j <= k; j++){
while (dq[j].size() && f[dq[j].back()][j] <= f[i][j])
dq[j].pop_back();
dq[j].push_back(i);
}
}
int ans = 0;
for (int i = 1; i <= k; i++)
maxi(ans, f[n][i]);
cout << ans;
}
}
namespace subtask4{
stack <int> st;
void solve(){
st.push(n);
int ans = 1;
for (int i = n - 1; i >= 1; i--){
while (st.size() && a[st.top()] <= a[i]) st.pop();
st.push(i);
maxi(ans, st.size());
}
cout << ans;
}
}
namespace subtask5{
int b[N];
void solve(){
mem(b, 0x3f);
int ans = 0;
for (int i = 1; i <= n; i++){
int id = lower_bound(b + 1, b + n + 1, a[i]) - b;
if (i == n) cout << id;
b[id] = a[i];
maxi(ans, id);
}
}
}
int main(){
load();
input();
compress();
if (n <= (int)7e3){
subtask3::solve();
return 0;
}
if (D == 1){
subtask4::solve();
return 0;
}
subtask5::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |