Submission #1019995

#TimeUsernameProblemLanguageResultExecution timeMemory
1019995coolboy19521Exam (eJOI20_exam)C++17
0 / 100
1 ms604 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...