QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630674#7878. Matrix DistancesLianYanTL 1ms3696kbC++20726b2024-10-11 19:53:112024-10-11 19:53:15

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 19:53:15]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3696kb
  • [2024-10-11 19:53:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1005;
int a[N][N];
typedef pair<int, int> PII;
map<int, vector<PII>> mp;

void solve()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            mp[a[i][j]].push_back({i, j});
        }
    }

    int sum = 0;
    for (auto [i, j] : mp)
    {
        for (auto it : j)
        {
            for (auto k : j)
            {
                sum += abs(it.first - k.first) + abs(it.second - k.second);
            }
        }
    }
    cout << sum << endl;
}

signed main()
{
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3676kb

input:

2 2
1 1
2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3696kb

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 ...

output:


result: