QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660066#7878. Matrix Distancessh-sho1katWA 0ms3540kbC++201.6kb2024-10-20 04:25:352024-10-20 04:25:36

Judging History

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

  • [2024-10-20 04:25:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3540kb
  • [2024-10-20 04:25:35]
  • 提交

answer

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

// 2024-10-20 01:55:02
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define inf (1LL << 62)
#define all(x) x.begin(), x.end(), greater<ll>()
#define eb push_back
#define ff first
#define ss second
#define yes cout << "YES" << nl
#define no cout << "NO" << nl
#define dtob(bits, n) bitset<bits>(n).to_string()
#define btod(bin) stoll(bin, nullptr, 2)
#define ok cout << "Eureka" << nl
#define nl '\n'
#define SH 0
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;

int main()
{
    fastio;
    ll n, m;
    cin >> n >> m;
    ll a[n + 5][m + 5];
    map<ll, ll> mp;
    ll cnt = 0;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= m; j++)
        {
            ll p;
            cin >> p;
            if (!mp[p])
                mp[p] = ++cnt;
            a[i][j] = mp[p];
        }
    }
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= m; j++)
        {
            cout << a[i][j] << " ";
        }
        cout << nl;
    }

    vl v1[cnt + 5], v2[cnt + 5];

    for (ll i = 1; i <= n; i++)
        for (ll j = 1; j <= m; j++)
            v1[a[i][j]].eb(i), v2[a[i][j]].eb(j);
    ll sum = 0;
    for (ll i = 1; i <= cnt; i++)
    {
        sort(all(v1[i]));
        sort(all(v2[i]));
        ll p = v1[i].size();
        --p;
        for (ll j = 0; j < v1[i].size(); j++)
        {
            sum += p * v1[i][j];
            sum += p * v2[i][j];
            p -= 2;
        }
    }
    cout << sum*2 << nl;

    return SH;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3540kb

input:

2 2
1 1
2 2

output:

1 1 
2 2 
4

result:

wrong answer 1st numbers differ - expected: '4', found: '1'