QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667753 | #7878. Matrix Distances | Faruk982 | WA | 116ms | 19140kb | C++23 | 3.0kb | 2024-10-23 06:15:49 | 2024-10-23 06:15:49 |
Judging History
answer
// gfsgfsdg
// ffff
// faruk
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define YES cout << "Yes\n";
#define NO cout << "No\n";
#define SetBit(x, k) (x |= (1ll << k))
#define ClearBit(x, k) (x &= ~(1ll << k))
#define CheckBit(x, k) ((x >> k) & 1)
#define CC(x) cout << "Case " << ++x << ": ";
#define all(x) x.begin(), x.end()
#define INF 1e12 + 10
#define pi pair<ll, ll>
ll i, j, k, a, b, c, d, e, f, n, l, m, w;
vector<ll> vk;
// // PBDS start
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <class K, class V>
// using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// // less<T> for uniqe elements ,, less_equal<T> for duplicate
// // PBDS end
const ll M = 1e9 + 7;
const int N = 5e3 + 10;
const int Ni = 1e4 + 10;
long long int binE(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = (res * a) % M;
a = (a * a) % M;
b >>= 1;
}
return res;
}
map<ll, ll> vis, vis1;
bool cmp(pair<string, pi> p1, pair<string, pi> p2)
{
if (p1.second.first == p2.second.first)
{
return p1.second.second < p2.second.second;
}
else
return p1.second.first > p2.second.first;
}
void solve()
{
map<ll,ll>x_val,y_val,nu;
cin>>n>>m;
map<ll,vector<ll>>distx,disty;
vector<ll>colors;
ll matr[n+1][m+1];
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
cin>>matr[i][j];
x_val[matr[i][j]]+=i;
y_val[matr[i][j]]+=j;
// if(distx[matr[i][j]].empty())colors.push_back(matr[i][j]);
distx[matr[i][j]].push_back(i);
disty[matr[i][j]].push_back(j);
}
}
ll ans=0;
for(auto yy:distx){
ll x=yy.first;
ll nn=distx[x].size();
ll now=nn;
// cout<<x<<endl;
sort(distx[x].rbegin(),distx[x].rend());
sort(disty[x].rbegin(),disty[x].rend());
ll i=0;
while (i<distx[x].size())
{
ll cur=distx[x][i];
// distx[x].pop();
ans+=abs(x_val[x]-cur*now)*2;
//cout<<x_val[x]<<" "<<cur<<" "<<now<<endl;
// cout<<ans<<endl;
x_val[x]-=cur;
i++;
now--;
}
// cout<<ans<<" ";
now=nn;
i=0;
while (i<disty[x].size())
{
ll cur=disty[x][i];
//disty[x].pop();
ans+=abs(y_val[x]-cur*now)*2;
y_val[x]-=cur;
now--;i++;
}
// cout<<" "<<ans<<endl;
}
cout<<ans<<endl;
}
int32_t main()
{
fastio;
int testcase = 1;
//cin >> testcase;
ll x = 0;
// fact[0]=1;
// for(ll i=1;i<=N;i++){
// fact[i]=(i*fact[0])%M;
// if(fact[i]<0)fact[i]+=M;
// }
// cout<<testcase<<endl;
while (testcase--)
{
// cout<<testcase<<endl;
vk.clear();
// CC(x)
// memset(dp,-1,sizeof(dp));
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3484kb
input:
2 2 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
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: 116ms
memory: 19140kb
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:
-579751876
result:
wrong answer 1st numbers differ - expected: '506784086339644', found: '-579751876'