QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662436#7878. Matrix Distances111111qqqqqqWA 107ms17240kbC++231.8kb2024-10-21 00:13:342024-10-21 00:13:34

Judging History

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

  • [2024-10-21 00:13:34]
  • 评测
  • 测评结果:WA
  • 用时:107ms
  • 内存:17240kb
  • [2024-10-21 00:13:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cmin(a,b) a=min(a,b)
#define cmax(a,b) a=max(a,b)
#define modd(a,b) a=a%b
#define pb push_back
#define db double
#define lowbit(x) x&(-x)
#define cerr(x) cout<<#x<<"="<<x<<endl
const ll mod=1e9+7;
ll ksm(ll a,ll b) {ll ans=1,bs=a;while(b) {if(b&1) ans=ans*bs%mod;bs=bs*bs%mod;b>>=1;}return ans;}
#define fi first
#define se second
#define N 1010
int n,m;
int c[N][N],a[N];
vector<pair<int,int>>g[N];
void solve() {
    cin>>n>>m;
    int cnt=0;
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>c[i][j],a[++cnt]=c[i][j];
    sort(a+1,a+cnt+1);
    int tot=unique(a+1,a+cnt+1)-a-1;
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) {
        c[i][j]=lower_bound(a+1,a+tot+1,c[i][j])-a;
    }
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) {
        g[c[i][j]].pb(make_pair(i,j));
    }
    // for(int i=1;i<=n;i++,cout<<endl) for(int j=1;j<=m;j++) cout<<c[i][j]<<" ";
    ll ans=0;
    for(int i=1;i<=tot;i++) {
        if(g[i].size()<=1) continue;
        sort(g[i].begin(),g[i].end(),[&](pair<int,int>a,pair<int,int>b){
            return a.first<b.first;
        });
        for(int j=1;j<g[i].size();j++) {
            ans+=1ll*j*((int)g[i].size()-1-j+1)*(g[i][j].first-g[i][j-1].first);
        }
        sort(g[i].begin(),g[i].end(),[&](pair<int,int>a,pair<int,int>b) {
            return a.second<b.second;
        });
        for(int j=1;j<g[i].size();j++) {
            ans+=1ll*j*((int)g[i].size()-1-j+1)*(g[i][j].second-g[i][j-1].second);
        }
    }
    cout<<ans*2<<endl;
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // int T;
    // cin>>T;
    // while(T--) 
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

2 2
1 1
2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

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
Wrong Answer
time: 107ms
memory: 17240kb

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:

472735543532360

result:

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