Submission #441532

#TimeUsernameProblemLanguageResultExecution timeMemory
441532elazarkorenExam (eJOI20_exam)C++17
0 / 100
1089 ms460 KiB
#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 = 10; int b[MAX_N]; //struct Seg{ // int l, r, mid, val = 0, lazy_val = 0; // Seg *lp, *rp; // Seg(int l, int r): l(l), r(r), mid((l + r) / 2) { // if (l + 1 != r) { // lp = new Seg(l, mid); // rp = new Seg(mid, r); // } // } // void push() { // if (lazy_val) { // lp->val = lp->lazy_val = lazy_val; // rp->val = rp->lazy_val = lazy_val; // } // } // void pull() { // val = max(lp->val, rp->val); // } // int query(int a, int b) { // if (a <= l && r <= b) return val; // if (r <= a || b <= l) return 0; // push(); // return max(lp->query(a, b), rp->query(a, b)); // } // void update(int a, int b, int x) { // if (a <= l && r <= b) { // val = x; // lazy_val = x; // return; // } // if (r <= a || b <= l) return; // push(); // lp->update(a, b, x), rp->update(a, b, x); // pull(); // } // int Count() { // if (l + 1 == r) { // return val == b[l]; // } // push(); // return lp->Count() + rp->Count(); // } //}; 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; } 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]; vi per(n + 1); for (int i = 0; i <= n; i++) per[i] = i; int ans = 0; do { vi curr = a; for (int i = 0; i < n; i++) { update(per[i], per[i + 1], curr); chkmax(ans, Count(curr)); } } while (next_permutation(all(per))); cout << ans; }
#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...