이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define sz(s) s.size()
#define mkp make_pair
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const int mod = 1000000007;
const int infmax = INT32_MAX, infmin = INT32_MIN;
const ll Infmax = INT64_MAX, Infmin = INT64_MIN;
//-------------------KarginCode------------------------\\
const int N = 300005;
int a[N], dp[N], ans[N], mx[N];
void KarginSolve() {
int n, d;
cin >> n >> d;
for (int i = 0;i < n;i++) {
cin >> a[i];
}
if (n == d) {
int lenght = 1;
dp[0] = a[0];
for (int i = 1; i < n; i++) {
auto it = lower(dp, dp + lenght, a[i]);
if (it == dp + lenght) {
dp[lenght++] = a[i];
}
else {
*it = a[i];
}
}
cout << lenght;
}
else if (d == 1) {
stack<int> st;
int ans = 0;
for (int i = n - 1;i >= 0;i--) {
if (st.empty()) {
st.push(a[i]);
}
else {
while (!st.empty()) {
int x = st.top();
if (x >= a[i] + 1) {
break;
}
st.pop();
}
st.push(a[i]);
}
ans = max(ans,(int) st.size());
}
cout << ans << endl;
}
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
cout << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
Main.cpp:9:1: warning: multi-line comment [-Wcomment]
9 | //------------------KarginDefines--------------------\\
| ^
Main.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
Main.cpp:28:1: warning: multi-line comment [-Wcomment]
28 | //-------------------KarginCode------------------------\\
| ^
# | 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... |