///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define all(x) (x).begin(),(x).end()
void solvefor1(){
ll r;
int n,m,o,p;
cin>>n>>o>>m;
vector<int> v;
for(int i=0;i<n;i++){
cin>>p;
v.append(p);
}
sort(all(v));
for(int i=r=0;i<n;i++){
p=i;
for(int j=65536;j>0;j/=2){
if(p+j>=n) continue;
if(v[p+j]-v[i]<=o) p+=j;
}
r+=p-i;
}
cout<<r;
}
void solvefor2(){
int n,m,o,p,q,r;
cin>>n>>o>>m;
vector<int> x,y;
for(int i=0;i<n;i++){
cin>>p>>q;
x.append(p);
y.append(q);
}
for(int i=r=0;i<n;i++)
for(int j=i+1;j<n;j++)
r+=(abs(x[i]-x[j])+abs(y[i]-y[j])<=o);
cout<<r;
}
void solvefor3(){
int n,m,o,p,q,r;
cin>>n>>o>>m;
vector<int> x,y,z;
for(int i=0;i<n;i++){
cin>>p>>q>>r;
x.append(p);
y.append(q);
z.append(r);
}
for(int i=r=0;i<n;i++)
for(int j=i+1;j<n;j++)
r+=(abs(x[i]-x[j])+abs(y[i]-y[j])
+abs(z[i]-z[j])<=o);
cout<<r;
}
void solve(){
int t;
cin>>t;
if(t==1) solvefor1();
if(t==2) solvefor2();
if(t==3) solvefor3();
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1244 KB |
Output is correct |
2 |
Correct |
19 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
992 KB |
Output is correct |
2 |
Correct |
24 ms |
988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
988 KB |
Output is correct |
2 |
Correct |
18 ms |
988 KB |
Output is correct |
3 |
Correct |
19 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4066 ms |
1240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4057 ms |
1412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4006 ms |
1236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4067 ms |
1760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4011 ms |
1740 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4040 ms |
1744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |