답안 #441542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441542 2021-07-05T10:46:48 Z elazarkoren Exam (eJOI20_exam) C++17
14 / 100
1000 ms 20156 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<bool> vb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long ll;

const int MAX_N = 10;
const int mod = 1e9 + 7;
const int MAX = 1e9;

int b[MAX_N];

int 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 Count(vi &v) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == b[i]) ans++;
    }
    return ans;
}

set<pair<ll, short>> visit;

ll Val(vi &v) {
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans * MAX % mod + v[i]) % mod;
    }
    return ans;
}

int ans = 0;

void Solve(vi &curr, short visited, int i) {
    if (!visit.insert({Val(curr), visited}).y) return;
    chkmax(ans, Count(curr));
    if (i == n) return;
    for (int j = 0; j < n; j++) {
        if (!((visited >> j) & 1)) {
            for (int k = j + 1; k < n; k++) {
                vi next = curr;
                update(j, k, next);
//                visited += (1 << j);
                Solve(next, visited + (1 << j), i);
//                visited -= (1 << j);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    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];
//    vb visited(n);
    Solve(a, 0, 0);
//    vi per(2 * n);
//    for (int i = 0; i < n; i++) per[i] = i;
//    for (int i = n; i < 2 * n; i++) per[i] = i - n;
//    do {
//        vi curr = a;
//        for (int i = 0; i < 2 * n; i += 2) {
//            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 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 27 ms 680 KB Output is correct
6 Correct 751 ms 13076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 20156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 11
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 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 27 ms 680 KB Output is correct
6 Correct 751 ms 13076 KB Output is correct
7 Correct 286 ms 3080 KB Output is correct
8 Execution timed out 1093 ms 1096 KB Time limit exceeded
9 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 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 27 ms 680 KB Output is correct
6 Correct 751 ms 13076 KB Output is correct
7 Execution timed out 1091 ms 20156 KB Time limit exceeded
8 Halted 0 ms 0 KB -