제출 #465286

#제출 시각아이디문제언어결과실행 시간메모리
465286CyberCowExam (eJOI20_exam)C++17
26 / 100
29 ms1112 KiB
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <string> #include <cmath> #include <map> #include <unordered_map> #include <fstream> #include <iomanip> #include <iterator> #include <stack> using namespace std; using ll = long long; const int maxn = 100005; int a[maxn]; int b[maxn]; bool stug[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, i, j; cin >> n; for ( i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { cin >> b[i]; } if (n <= 10) { int erk = 1, ma = 0; for ( i = 0; i < n; i++) { erk *= 2; } for (int mask = 0; mask < erk; mask++) { int kop = mask; for ( i = 0; i < n; i++) { if ((kop & 1) == 1) stug[i] = 1; else stug[i] = 0; kop >>= 1; } int g = 1, ans = 0; for ( i = 0; i < n; i++) { if (stug[i] == 1) { ans++; int sm = 0, se = 0, km = 0, ke = 0, maa; j = i, maa = a[i]; while (j >= 0) { if (maa == b[i]) { sm = 1; break; } if (stug[j] == 1 && b[j] < b[i]) km = 1; j--; maa = max(maa, a[j]); } j = i, maa = a[i]; while (j < n) { if (maa == b[i]) { se = 1; break; } if (stug[j] == 1 && b[j] < b[i]) ke = 1; j++; maa = max(maa, a[j]); } if (!((sm && !km) || (se && !ke))) { g = 0; break; } } } if (g) ma = max(ma, ans); } cout << ma; } else { for ( i = 0; i < n; i++) { if (a[i] == b[0]) { j = i - 1; while (j >= 0 && a[j] != b[0] && a[j] <= b[0]) { a[j] = b[0]; j--; } j = i + 1; while (j < n && a[j] != b[0] && a[j] <= b[0]) { a[j] = b[0]; j++; } } } int ans = 0; for ( i = 0; i < n; i++) { if (a[i] == b[0]) ans++; } cout << ans; } 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...