Submission #954501

#TimeUsernameProblemLanguageResultExecution timeMemory
954501GrandTiger1729Sličnost (COI23_slicnost)C++17
17 / 100
3017 ms14528 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, K, q; cin >> n >> K >> q; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (int i = 0; i < n; i++) { cin >> b[i]; b[i]--; } vector<int> aa(n), bb(n); for (int i = 0; i < n; i++) { aa[a[i]] = i; bb[b[i]] = i; } vector<vector<int>> add(n + 1), del(n + 1); for (int i = 0; i < n; i++) { add[max(0, aa[i] - (K - 1)) + (K - 1)].push_back(i); del[min(n, aa[i] + K)].push_back(i); } long long ans = 0, cnt = 0; vector<long long> dd(n); for (int t = 0; t <= n; t++) { for (int id : add[t]) { int l = max(0, bb[id] - (K - 1)) + (K - 1), r = min(n, bb[id] + K); for (int i = l; i < r; i++) { dd[i]++; } } for (int id : del[t]) { int l = max(0, bb[id] - (K - 1)) + (K - 1), r = min(n, bb[id] + K); for (int i = l; i < r; i++) { dd[i]--; } } long long res = 0, cc = 0; for (int i = K - 1; i < n; i++) { if (res < dd[i]) { res = dd[i]; cc = 1; } else if (res == dd[i]) { cc++; } } if (res > ans) { ans = res; cnt = cc; } else if (res == ans) { cnt += cc; } } cout << ans << ' ' << cnt << '\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...