QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#236434 | #4425. Cake | sgrcn | WA | 4960ms | 448496kb | C++17 | 1.3kb | 2023-11-03 23:07:58 | 2023-11-03 23:07:58 |
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, C]: M) {
int a = x.first, b = x.second;
vector<int> V = N[{a,b}];
if(C.size() != V.size()) {
cout << "-1\n"; return;
}
for(int i = 0 ; i < (int)C.size() ; ++i) {
ans += abs(C[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);
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4960ms
memory: 448496kb
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 -1 -1
result:
wrong answer 3rd lines differ - expected: '124999750000', found: '-1'