QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#778935 | #7878. Matrix Distances | ShallowMaple | RE | 443ms | 59732kb | C++14 | 1.7kb | 2024-11-24 16:50:38 | 2024-11-24 16:50:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl '\n'
int t;
//int g[1005][1005];
//int r[1005][1005]; //cnt
//int c[1005][1005]; //cnt
//int precntr[1005][1005];
//int precntc[1005][1005];
//int prer[1005][1005];
//int prec[1005][1005];
void solve(){
int n, m;
cin >> n >> m;
vector<vector<int>> g(n + 10, vector<int>(m + 10));
vector<vector<int>> r(n + 10, vector<int>(m + 10));
vector<vector<int>> c(n + 10, vector<int>(m + 10));
vector<vector<int>> precntr(n + 10, vector<int>(m + 10));
vector<vector<int>> precntc(n + 10, vector<int>(m + 10));
vector<vector<int>> prer(n + 10, vector<int>(m + 10));
vector<vector<int>> prec(n + 10, vector<int>(m + 10));
map<int, int> mp;
int cnt = 0;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
cin >> g[i][j];
if(!mp[g[i][j]]) mp[g[i][j]] = 1;
}
}
for(auto [x, y] : mp){
mp[x] = ++cnt;
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
r[i][mp[g[i][j]]] ++;
c[j][mp[g[i][j]]] ++;
}
}
for(auto [x, y] : mp){
for(int i = 1; i <= n; i ++){
precntr[i][y] = precntr[i - 1][y] + r[i][y];
prer[i][y] = prer[i - 1][y] + r[i][y] * i;
}
for(int i = 1; i <= m; i ++){
precntc[i][y] = precntc[i - 1][y] + c[i][y];
prec[i][y] = prec[i - 1][y] + c[i][y] * i;
}
}
int ans = 0ll;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
{
ans += (precntr[i-1][mp[g[i][j]]] * i - prer[i-1][mp[g[i][j]]]) * 2;
ans += (precntc[j-1][mp[g[i][j]]] * j - prec[j-1][mp[g[i][j]]]) * 2;
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
t=1;
//cin>>t;
while(t--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
input:
2 2 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
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: 0
Accepted
time: 78ms
memory: 59360kb
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:
506784086339644
result:
ok 1 number(s): "506784086339644"
Test #4:
score: 0
Accepted
time: 96ms
memory: 59280kb
input:
1000 1000 701031019 701031019 902550481 515963342 902550481 701031019 902550481 701031019 701031019 701031019 701031019 701031019 701031019 902550481 701031019 701031019 701031019 902550481 701031019 902550481 701031019 902550481 902550481 902550481 902550481 515963342 701031019 701031019 701031019 ...
output:
293351133301656
result:
ok 1 number(s): "293351133301656"
Test #5:
score: 0
Accepted
time: 98ms
memory: 59364kb
input:
1000 1000 584147147 584147147 771066621 584147147 814776600 814776600 584147147 814776600 814776600 814776600 771066621 814776600 814776600 771066621 584147147 814776600 814776600 771066621 814776600 584147147 771066621 584147147 814776600 771066621 814776600 584147147 814776600 584147147 771066621 ...
output:
222221591276684
result:
ok 1 number(s): "222221591276684"
Test #6:
score: 0
Accepted
time: 98ms
memory: 59316kb
input:
1000 1000 451748258 451748258 205399494 451748258 451748258 451748258 451748258 451748258 953934338 451748258 580264463 451748258 451748258 451748258 451748258 588594555 451748258 451748258 451748258 451748258 451748258 451748258 451748258 451748258 451748258 451748258 953934338 451748258 451748258 ...
output:
450794820267988
result:
ok 1 number(s): "450794820267988"
Test #7:
score: 0
Accepted
time: 113ms
memory: 59500kb
input:
1000 1000 548583482 635446288 548583482 635446288 635446288 548583482 548583482 635446288 801198618 548583482 635446288 635446288 548583482 635446288 548583482 548583482 548583482 548583482 635446288 635446288 635446288 635446288 635446288 635446288 548583482 726064808 635446288 801198618 548583482 ...
output:
237272499061426
result:
ok 1 number(s): "237272499061426"
Test #8:
score: 0
Accepted
time: 119ms
memory: 59344kb
input:
1000 1000 596800174 215475167 727165477 215475167 596800174 479596632 596800174 479596632 340778824 596800174 340778824 340778824 596800174 727165477 792552295 215475167 825136342 215475167 15133890 15133890 792552295 215475167 15133890 15133890 215475167 792552295 186221070 596800174 825136342 7925...
output:
66666979915604
result:
ok 1 number(s): "66666979915604"
Test #9:
score: 0
Accepted
time: 140ms
memory: 59496kb
input:
1000 1000 283321818 144879541 144879541 144879541 144879541 144879541 144879541 144879541 351529453 755622562 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 144879541 ...
output:
429192094084416
result:
ok 1 number(s): "429192094084416"
Test #10:
score: 0
Accepted
time: 141ms
memory: 59340kb
input:
1000 1000 161743512 416078170 855756681 889314339 416481165 889314339 855756681 889314339 855756681 889314339 855756681 264524276 855756681 855756681 855756681 889314339 855756681 889314339 889314339 889314339 494796476 889314339 889314339 889314339 889314339 855756681 855756681 855756681 855756681 ...
output:
216113198146626
result:
ok 1 number(s): "216113198146626"
Test #11:
score: 0
Accepted
time: 213ms
memory: 59356kb
input:
1000 1000 111711290 83219409 652958381 160096781 438510184 979014841 96096837 793714095 266288718 28912730 675001370 464693704 642313963 565598413 429830978 233570610 775904524 969001190 158819374 451251731 210397449 83219409 766749559 473545004 517036030 851023554 166176740 96096837 160096781 63151...
output:
6666591233498
result:
ok 1 number(s): "6666591233498"
Test #12:
score: 0
Accepted
time: 227ms
memory: 59676kb
input:
1000 1000 206885994 206885994 206885994 206885994 206885994 206885994 206885994 206885994 206885994 484082914 206885994 737061221 206885994 206885994 206885994 206885994 206885994 206885994 206885994 206885994 206885994 206885994 206885994 885540330 206885994 15312403 206885994 206885994 206885994 2...
output:
426348228198774
result:
ok 1 number(s): "426348228198774"
Test #13:
score: 0
Accepted
time: 244ms
memory: 59680kb
input:
1000 1000 119021511 262340498 119021511 571262579 262340498 119021511 119021511 262340498 262340498 262340498 262340498 262340498 119021511 119021511 119021511 262340498 262340498 262340498 119021511 119021511 16968046 262340498 262340498 119021511 616963806 119021511 119021511 119021511 616963806 2...
output:
213349390292676
result:
ok 1 number(s): "213349390292676"
Test #14:
score: 0
Accepted
time: 443ms
memory: 59732kb
input:
1000 1000 294834416 710159087 71576000 771158418 734800928 519231261 66958341 846593614 842762889 266263223 449970247 393627406 452797162 702159979 103716509 528121669 411977733 41875663 181065802 366920699 973794257 627741675 408432509 319085147 24347426 209592388 529269033 798345726 138118120 1776...
output:
666600092404
result:
ok 1 number(s): "666600092404"
Test #15:
score: -100
Runtime Error
input:
1000 1000 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 991718494 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 774400533 ...