답안 #646908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646908 2022-10-01T01:02:17 Z LeonaRaging Exam (eJOI20_exam) C++14
12 / 100
23 ms 3788 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 4;
const int INF = 1e9;

int n, a[maxn], b[maxn], L[maxn], R[maxn];
set<int> mySet;


void Sub2() {
    int res = 0, pre = 0;
    for (int i = 1; i <= n; i++)
        if (a[i] == b[i]) {
            res += R[i] - max(pre, L[i]) - 1;
            pre = R[i];
            i = R[i] - 1;
        }
    cout << res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        mySet.insert(b[i]);
    }
    stack<int> st;
    st.push(0);
    a[0] = a[n + 1] = INF + 1;
    for (int i = 1; i <= n; i++) {
        while (a[st.top()] <= a[i])
            st.pop();
        L[i] = st.top();
        st.push(i);
    }
    stack<int>().swap(st);
    st.push(n + 1);
    for (int i = n; i >= 1; i--) {
        while (a[st.top()] <= a[i])
            st.pop();
        R[i] = st.top();
        st.push(i);
    }
    if (mySet.size() == 1)
        Sub2();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 560 KB Output is correct
3 Correct 15 ms 2004 KB Output is correct
4 Correct 10 ms 1808 KB Output is correct
5 Correct 23 ms 1888 KB Output is correct
6 Correct 12 ms 2248 KB Output is correct
7 Correct 14 ms 2388 KB Output is correct
8 Correct 22 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -