Submission #577084

# Submission time Handle Problem Language Result Execution time Memory
577084 2022-06-14T03:26:36 Z vqpahmad Exam (eJOI20_exam) C++14
0 / 100
1000 ms 168244 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 ;

}
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 7976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 168244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -