답안 #441528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441528 2021-07-05T10:16:39 Z elazarkoren Exam (eJOI20_exam) C++17
0 / 100
1000 ms 332 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#define x first
#define y second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define all(v) v.begin(), v.end()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int MAX_N = 1e5 + 1;

//int a[MAX_N];
int b[MAX_N];

void update(int l, int r, vi &v) {
    if (l > r) swap(l, r);
    int x = 0;
    for (int i = l; i <= r; i++) {
        chkmax(x, v[i]);
    }
    for (int i = l; i <= r; i++) {
        v[i] = x;
    }
}

int n;

int Count(vi &v) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == b[i]) ans++;
    }
    return ans;
}

int main() {
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    vi per(n);
    for (int i = 0; i < n; i++) per[i] = i;
    int ans = 0;
    do {
        vi curr = a;
        for (int i = 0; i + 1 < n; i++) {
            update(per[i], per[i + 1], curr);
            chkmax(ans, Count(curr));
        }
    } while (next_permutation(all(per)));
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Execution timed out 1008 ms 276 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Execution timed out 1008 ms 276 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Execution timed out 1008 ms 276 KB Time limit exceeded
5 Halted 0 ms 0 KB -