From d69dbf968c4bde6de88c8b545a070749027ba7de Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 12 Sep 2022 21:35:45 +0800 Subject: [PATCH] =?UTF-8?q?1990=20-=20=E6=8E=92=E9=98=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 77472 --- bjtu/1990/1990.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 bjtu/1990/1990.cpp diff --git a/bjtu/1990/1990.cpp b/bjtu/1990/1990.cpp new file mode 100644 index 00000000..f3851603 --- /dev/null +++ b/bjtu/1990/1990.cpp @@ -0,0 +1,38 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e5 + 5; + +int n, a[N], b[N], s1[N], s2[N], ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (int i = 1; i <= n; i++) { + cin >> b[i]; + } + + for (int i = 1; i <= n; i++) { + s1[i] = s1[i - 1] + (a[i] == b[i]); + s2[i] = s2[i - 1] + (a[i] == b[i - 1]); + } + + ans = s2[n]; + for (int i = 1; i <= n; i++) { + ans = std::max(ans, s1[i - 1] + s2[n] - s2[i] + (a[i] == b[n])); + } + + cout << ans << endl; + + return 0; +}