Submission #899635

# Submission time Handle Problem Language Result Execution time Memory
899635 2024-01-06T15:44:19 Z Nonoze Pairs (IOI07_pairs) C++17
47 / 100
4000 ms 3420 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define sz(x) (int)(x.size())

using namespace std;
using namespace __gnu_pbds;

typedef
tree<
  int,
  null_type,
  less<int>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;

int b, n, d, m;

void subtask1() {
	vector<int> cos(n);
	for (auto &u: cos) cin >> u;
	sort(cos.begin(), cos.end());
	int pro=1;
	int ans=0;
	for (int i=0; i<n; i++) {
		pro=max(pro, i+1);
		while (pro<n && cos[pro]-cos[i]<=d) pro++;
		pro--;
		ans+=pro-i;
	}
	cout << ans << endl;
}


void subtask2() {
	vector<pair<int, int>> cos(n);
	for (auto &u: cos) cin >> u.first >> u.second;
	int ans=0;
	for (int i=0; i<n; i++) {
		for (int j=i+1; j<n; j++) {
			if (abs(cos[i].first-cos[j].first)+abs(cos[i].second-cos[j].second)<=d) ans++;
		}
	}
	cout << ans << endl;
}

void subtask3() {
	vector<pair<pair<int, int>, int>> cos(n);
	for (auto &u: cos) cin >> u.first.first >> u.first.second >> u.second;
	int ans=0;
	for (int i=0; i<n; i++) {
		for (int j=i+1; j<n; j++) {
			if (abs(cos[i].first.first-cos[j].first.first)
				+abs(cos[i].first.second-cos[j].first.second)
				+abs(cos[i].second-cos[j].second)<=d) ans++;
		}
	}
	cout << ans << endl;
}


void solve() {
	cin >> b >> n >> d >> m;
	if (b==1) subtask1();
	if (b==2) subtask2();
	if (b==3) subtask3();
	return;
}


signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tt=1;// cin >> tt;
	while(tt--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1628 KB Output is correct
2 Correct 10 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1884 KB Output is correct
2 Correct 16 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1884 KB Output is correct
2 Correct 14 ms 1876 KB Output is correct
3 Correct 14 ms 2012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4021 ms 2396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4046 ms 2652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4033 ms 3164 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 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4050 ms 3308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4017 ms 3416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4061 ms 3420 KB Time limit exceeded
2 Halted 0 ms 0 KB -