답안 #577085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577085 2022-06-14T03:26:54 Z vqpahmad Exam (eJOI20_exam) C++14
0 / 100
1000 ms 168296 KB
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
using namespace std;
const int N = 1e6 + 15;
int mx ;
int n;
vector<int> b;
vector<int> a;
void solve(int pos,vector<int> v){
    vector<int> temp = v;
    if (pos==n){
        int cnt =0;
        for (int i=0;i<n;i++){
            if (v[i]==b[i])cnt++;
        }
        mx = max(mx,cnt);
        return ;
    }
    bool can = 1;
    int cur = pos;
    while (v[cur]!=b[pos]){
        if (v[cur]>b[pos]) {
            can = 0;
            break;
        }
        cur--;
        if (cur==-1) {
            can = 0;
            break;
        }
    }
    if (can){
        for (int i=cur;i<=pos;i++){
            v[i] = b[pos];
        }
        solve(pos+1,v);
        v = temp;
    }
    cur = pos;
    can = 1;
    while (v[cur]!=b[pos]){
        if (v[cur]>b[pos]) {
            can = 0;
            break;
        }
        cur++;
        if (cur==n) {
            can = 0;
            break;
        }
    }
    if (can){
        for (int i=pos;i<=cur;i++){
            v[i] = b[pos];
        }
        solve(cur+1,v);
    }
    solve(pos+1,temp);
    return;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    a.resize(n);
    b.resize(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for (int i=0;i<n;i++){
        cin >> b[i];
    }
    solve(0,a);
    cout << mx ;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 8024 KB Time limit exceeded
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 Execution timed out 1096 ms 168296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -