#pragma GCC optimize("O3")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000000
#define PI 3.14159265358979323846
using namespace std;
int inc[4][2]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
int DistanceSum(int N, int *X, int *Y)
{
long long ans=0;
for(int i = 0; i < N; i++)
{
//cout << i << ' ' << X[i] << ' ' << Y[i] << '\n';
set<int>s;
vector<int>v[N];
for(int j = 0; j < N; j++)
{
for(int k = j+1; k< N; k++)
{
long long x1=abs(X[j]-X[k]), y1=abs(Y[j]-Y[k]);
long long dis=x1+y1;
if(dis==1)
{
v[k].push_back(j);
v[j].push_back(k);
}
}
}
int nb=1, idx=0;
vector<int>bfs;
bfs.push_back(i);
bool ok=1;
s.insert(i);
while(bfs.size()!=N)
{
//cout << nb << '\n';
int l=bfs.size();
for(int j = idx; j < l; j++)
{
//cout << bfs[j].first << ' ' << bfs[j].second << '\n';
for(int k = 0; k < v[bfs[j]].size(); k++)
{
if(!s.count(v[bfs[j]][k]))
{
s.insert(v[bfs[j]][k]);
if(v[bfs[j]][k] < i)
ans+=nb;
}
}
}
nb++;
idx=l;
}
}
//ans*=( 1000000000);
ans%= 1000000000;
return ans;
}
Compilation message
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:49:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | while(bfs.size()!=N)
| ~~~~~~~~~~^~~
city.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int k = 0; k < v[bfs[j]].size(); k++)
| ~~^~~~~~~~~~~~~~~~~~
city.cpp:47:8: warning: unused variable 'ok' [-Wunused-variable]
47 | bool ok=1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
1792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
1608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |