QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#236444 | #4425. Cake | sgrcn | WA | 3603ms | 122468kb | C++17 | 1.4kb | 2023-11-03 23:25:01 | 2023-11-03 23:25:02 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define fwd(i,a,b) for(int i=(a); i<(b);i++)
#define ford(i,a,b) for(int i=(a); i>(b);i--)
#define foreach(i,v) for(auto& (i) : (v))
#define rep(i,n) fwd(i,0,n)
vector<int> A, B, C, D;
map<pair<int, int>, vector<int>> M, N;
int n;
void solve() {
rep(i, n) {
if (i & 1) {
M[{A[i], B[i]}].emplace_back(i);
} else {
M[{B[i], A[i]}].emplace_back(i);
}
}
rep(i, n) {
if (i & 1) {
N[{C[i], D[i]}].emplace_back(i);
} else {
N[{D[i], C[i]}].emplace_back(i);
}
}
long long ans = 0;
for (const auto &[x, X]: M) {
int a = x.first, b = x.second;
vector<int>& V = N[{a,b}];
if(X.size() != V.size()) {
cout << "-1\n"; return;
}
for(int i = 0 ; i < (int)X.size() ; ++i) {
ans += abs(X[i]-V[i]);
}
}
cout << ans/2 << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
int t;
cin >> t;
while(t--) {
cin >> n;
A = B = C = D = vector<int>(n);
M.clear(); N.clear();
rep(i, n) cin >> A[i];
rep(i, n) cin >> B[i];
rep(i, n) cin >> C[i];
rep(i, n) cin >> D[i];
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3603ms
memory: 122468kb
input:
4 500000 471518156 319758862 812815356 520822448 129241996 461169933 796713727 608641317 281180101 953966756 749634941 274104949 996181952 88142916 998544672 125597509 991731126 974767231 338911715 674197249 167602044 682799026 226927279 703198907 216742488 8185420 94921423 690039818 859329736 45428...
output:
0 -1 62500000000 41706497177
result:
wrong answer 3rd lines differ - expected: '124999750000', found: '62500000000'