QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#61533 | #3860. Drone Photo | 2pal1rak# | AC ✓ | 439ms | 38760kb | C++14 | 1.1kb | 2022-11-13 21:46:38 | 2022-11-13 21:46:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax = 1505;
int smaller1[Nmax][Nmax], smaller2[Nmax][Nmax];
int a[Nmax][Nmax], b[Nmax][Nmax];
int n;
void compute(int a[Nmax][Nmax], int smaller[Nmax][Nmax]) // smaller[i][j] = # smaller values on row a[i] than a[i][j]
{
int i, j;
vector<int> ord(n);
iota(ord.begin(), ord.end(), 1);
for(i=1; i<=n; ++i)
{
sort(ord.begin(), ord.end(), [&] (int x, int y) { return a[i][x] < a[i][y]; });
for(j=0; j<n; ++j)
smaller[i][ord[j]] = j;
}
}
int main()
{
cin.tie(0); cin.sync_with_stdio(false);
cin >> n;
int i, j;
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
cin >> a[i][j];
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
b[i][j] = a[j][i];
compute(a, smaller1);
compute(b, smaller2);
ll ans = 0;
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
ans += (ll) smaller1[i][j] * (n - 1 - smaller2[j][i]) + (ll) smaller2[j][i] * (n - 1 - smaller1[i][j]);
cout << ans / 2 << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 9456kb
input:
2 1 3 4 2
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 3ms
memory: 9648kb
input:
2 3 2 4 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 5ms
memory: 9616kb
input:
3 9 2 4 1 5 3 7 8 6
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 228ms
memory: 38636kb
input:
1500 2248501 2248502 2248503 2248504 2248505 2248506 2248507 2248508 2248509 2248510 2248511 2248512 2248513 2248514 2248515 2248516 2248517 2248518 2248519 2248520 2248521 2248522 2248523 2248524 2248525 2248526 2248527 2248528 2248529 2248530 2248531 2248532 2248533 2248534 2248535 2248536 2248537...
output:
1263938062500
result:
ok single line: '1263938062500'
Test #5:
score: 0
Accepted
time: 239ms
memory: 38732kb
input:
1499 2247001 2245502 2242505 2242504 2241005 2239506 2238007 2236508 2235009 2233510 2232011 2230512 2229013 2227514 2226015 2224516 2223017 2221518 2220019 2079113 2211025 2215522 2214023 2212524 2217021 2209526 2208027 2206528 2205029 2203530 2202031 2200532 2199033 2197534 2196035 2194536 2193037...
output:
1237639616078
result:
ok single line: '1237639616078'
Test #6:
score: 0
Accepted
time: 248ms
memory: 38756kb
input:
1500 2248501 2247001 2245501 2244001 2242501 2181001 2239501 2238001 2236501 2235001 2233501 2232001 2230501 2229001 2227501 2226001 2224501 2223001 2221501 2220001 2218501 2217001 2215501 2214001 2212501 2211001 2209501 2208001 2206501 2205001 2203501 2202001 2200501 2199001 2197501 2196001 2194501...
output:
1263864653932
result:
ok single line: '1263864653932'
Test #7:
score: 0
Accepted
time: 2ms
memory: 9404kb
input:
2 2 1 4 3
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 36ms
memory: 20680kb
input:
500 98385 2209 73901 62830 109771 156465 246882 100403 203031 116661 75939 18177 161380 207027 74136 167721 187703 120443 127071 98894 5209 61624 187062 86977 88581 115114 167657 60246 233371 31844 189984 209184 248558 36050 244251 140478 161331 185453 41727 125284 118405 151906 131643 64183 91178 1...
output:
10374282899
result:
ok single line: '10374282899'
Test #9:
score: 0
Accepted
time: 439ms
memory: 38760kb
input:
1500 1325678 1423672 1889031 262212 363747 355567 132826 634046 2211541 1236130 1391581 1168021 708925 1309521 363352 1208748 1023128 2029396 1524939 613341 959252 41827 206731 1388854 2195436 2064215 622706 1121313 825049 360021 1443155 615388 249971 1227544 6033 2007227 310725 1919606 554227 29258...
output:
842632564705
result:
ok single line: '842632564705'
Test #10:
score: 0
Accepted
time: 437ms
memory: 38740kb
input:
1499 1228161 2106486 2151651 708102 270437 1640023 1830663 1178040 969988 397189 1858052 1291397 2136020 130574 895186 2101390 2244480 1136533 798189 1010546 721509 810126 1017483 1571912 760642 641402 947358 121367 430471 299474 128934 259312 1032545 127697 342257 1315317 487370 862201 1184679 2212...
output:
840374658273
result:
ok single line: '840374658273'
Test #11:
score: 0
Accepted
time: 251ms
memory: 38756kb
input:
1500 1500 3000 4500 6000 7500 9000 10500 12000 13500 15000 16500 18000 19500 21000 22500 24000 25500 27000 28500 30000 31500 33000 34500 36000 37500 39000 40500 42000 43500 45000 46500 48000 49500 51000 52500 54000 55500 57000 58500 60000 61500 63000 64500 66000 67500 69000 70500 72000 73500 75000 7...
output:
1263938062500
result:
ok single line: '1263938062500'
Test #12:
score: 0
Accepted
time: 254ms
memory: 38564kb
input:
1499 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
1260569673414
result:
ok single line: '1260569673414'