Submission #435144

#TimeUsernameProblemLanguageResultExecution timeMemory
435144sumit_kk10Pairs (IOI07_pairs)C++14
37 / 100
4075 ms2252 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define ld long double using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; void solve(){ long long b, n, d, m; cin >> b >> n >> d >> m; long long ans = 0; if(b == 1){ long long a[n]; for(int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); for(int i = 0; i < n; ++i){ int low = i + 1, ok = -1, high = n - 1; while(low <= high){ int mid = (low + high) / 2; if(a[mid] - a[i] <= d){ ok = mid; low = mid + 1; } else high = mid - 1; } if(ok != -1) ans += (ok - i); } cout << ans << '\n'; } else if(b == 2){ pair<long long, long long> a[n]; for(int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second; for(int i = 0; i < n; ++i){ for(int j = i + 1; j < n; ++j){ long long dis = abs(a[i].first - a[j].first); dis += abs(a[i].second - a[j].second); ans += (dis <= d); } } cout << ans << '\n'; } } int main(){ fast; int t = 1; // cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...