Submission #1019995

# Submission time Handle Problem Language Result Execution time Memory
1019995 2024-07-11T12:00:29 Z coolboy19521 Exam (eJOI20_exam) C++17
0 / 100
1 ms 604 KB
#include <iostream>
#include <algorithm>
using namespace std;

const int MAX_SIZE = 20;

int a[MAX_SIZE], b[MAX_SIZE];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    // Input array a
    for (int i = 0; i < n; i++)
        cin >> a[i];

    // Input array b
    for (int i = 0; i < n; i++)
        cin >> b[i];

    int maxCount = 0;

    // Iterate over all possible subsets of indices
    for (int mask = 0; mask < (1 << n); mask++) {
        int count = 0;

        // We process each bit segment
        for (int i = 0; i < n; ) {
            bool currentBit = (mask & (1 << i)) != 0;
            int maxVal = 0;
            int j = i;

            // Find the maximum in the current segment where bits are the same
            while (j < n && ((mask & (1 << j)) != 0) == currentBit) {
                maxVal = max(maxVal, a[j]);
                j++;
            }

            // Count how many times the maximum appears in array b in the same segment
            for (int k = i; k < j; k++) {
                if (b[k] == maxVal) count++;
            }

            // Move to the next segment
            i = j;
        }

        // Update the maximum number of times a value appears
        maxCount = max(maxCount, count);
    }

    cout << maxCount << '\n';

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -