QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689992 | #7878. Matrix Distances | zyq_313# | TL | 0ms | 3684kb | C++14 | 676b | 2024-10-30 19:36:26 | 2024-10-30 19:36:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define BUG cout << "HERE IS A BUG !!!!\n"
#define endl '\n'
#define ll long long
const int N = 1010;
int n, m;
map<int, vector<pair<int, int>>> a;
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= m; j ++){
int x;
cin >> x;
a[x].push_back({i,j});
}
}
ll ans=0;
for(auto [b, a] : a){
for(int j=0;j<a.size();j++){
for(int k=j+1;k<a.size();k++){
ans=ans+abs(a[j].first-a[k].first)+abs(a[j].second-a[k].second);
}
}
}
cout<<ans*2;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3684kb
input:
2 2 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
4 4 1 3 2 4 2 1 2 3 1 3 3 2 3 2 1 4
output:
152
result:
ok 1 number(s): "152"
Test #3:
score: -100
Time Limit Exceeded
input:
1000 1000 227980299 227980299 227980299 227980299 227980299 776958596 227980299 227980299 227980299 227980299 227980299 227980299 227980299 227980299 227980299 227980299 776958596 227980299 227980299 329001637 227980299 227980299 227980299 329001637 227980299 227980299 227980299 227980299 227980299 ...