Submission details
Task:Distances
Sender:saarixx
Submission time:2026-04-17 12:38:00 +0300
Language:C++ (C++23)
Status:READY
Result:10
Feedback
subtaskverdictscore
#10
#2ACCEPTED4
#3ACCEPTED6
#40
#50
#60
Test results
testverdicttimesubtask
#1ACCEPTED0.00 s1, 4, 6details
#2ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#3ACCEPTED0.00 s1, 3, 4, 5, 6details
#4ACCEPTED0.00 s1, 2, 4, 6details
#5ACCEPTED0.00 s1, 3, 4, 5, 6details
#6--1, 4, 6details
#7ACCEPTED0.00 s1, 4, 6details
#8ACCEPTED0.00 s1, 2, 4, 6details
#9ACCEPTED0.00 s1, 3, 4, 5, 6details
#10--1, 4, 5, 6details
#11--1, 4, 6details
#12--1, 4, 6details
#13ACCEPTED0.00 s1, 4, 6details
#140.00 s1, 6details
#15ACCEPTED0.00 s1, 2, 6details
#16--4, 6details
#17--4, 6details
#18ACCEPTED0.00 s3, 4, 5, 6details
#19--4, 5, 6details
#20--4, 5, 6details
#21--5, 6details
#22--5, 6details
#23ACCEPTED0.00 s2, 6details
#24ACCEPTED0.00 s3, 4, 5, 6details
#25--4, 5, 6details
#26--4, 5, 6details
#27--5, 6details
#28--5, 6details
#29ACCEPTED0.00 s2, 6details
#30ACCEPTED0.00 s3, 4, 5, 6details
#31--4, 5, 6details
#32--4, 5, 6details
#33--4, 5, 6details
#34--5, 6details
#35--5, 6details
#36--5, 6details
#37--6details
#38--6details
#39ACCEPTED0.00 s2, 6details
#40--6details
#41--6details
#42--6details
#43--6details
#44--6details

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool is_perfect_square(ll d2) {
  if (d2 < 0) return false;
  if (d2 == 0) return true;
  ll s = round(sqrtl(d2));
  return s * s == d2;
}

int main() {
  int n;
  ll k;
  cin >> n >> k;
  if (n == 1) {
    cout << "0 0" << endl;
    return 0;
  }
  if (k == 0) {
    for (int i = 0; i < n; i++) {
      cout << i << " " << (ll)i * i << endl;
    }
    return 0;
  }
  ll max_possible = (ll)n * (n - 1) / 2;
  if (k == max_possible) {
    for (int i = 0; i < n; i++) {
      cout << i << " " << 0 << endl;
    }
    return 0;
  }
  vector<vector<pair<ll, ll>>> components;
  ll cur_k = k;
  ll cur_p = n;
  while (cur_k > 0 && cur_p > 0) {
    // Compute largest possible line clique size
    ll s = 2;
    while (s * (s - 1) / 2 <= cur_k && s <= cur_p) s++;
    s--;
    bool added = false;
    if (s >= 3) {
      ll t = s * (s - 1) / 2;
      ll rem_k = cur_k - t;
      ll rem_p = cur_p - s;
      // Only add if remaining is safe (0 or enough points for at least rem_k edges with small gadgets)
      if (rem_k == 0 || (rem_p >= 2 && rem_k <= rem_p)) {
        vector<pair<ll, ll>> comp;
        for (ll j = 0; j < s; j++) comp.emplace_back(j, 0);
        components.push_back(comp);
        cur_k -= t;
        cur_p -= s;
        added = true;
      }
    }
    if (!added && cur_k >= 4 && cur_p >= 4) {
      vector<pair<ll, ll>> comp = {{0, 0}, {1, 0}, {2, 0}, {0, 1}};
      components.push_back(comp);
      cur_k -= 4;
      cur_p -= 4;
      added = true;
    }
    if (!added && cur_k >= 2 && cur_p >= 3) {
      vector<pair<ll, ll>> comp = {{0, 0}, {1, 0}, {1, 1}};
      components.push_back(comp);
      cur_k -= 2;
      cur_p -= 3;
      added = true;
    }
    if (!added && cur_k >= 1 && cur_p >= 2) {
      vector<pair<ll, ll>> comp = {{0, 0}, {1, 0}};
      components.push_back(comp);
      cur_k -= 1;
      cur_p -= 2;
      added = true;
    }
    if (!added) {
      // Cannot add more edges safely; stop (isolates will be added below)
      break;
    }
  }
  // Add remaining isolates as single-point components
  for (ll i = 0; i < cur_p; i++) {
    vector<pair<ll, ll>> comp = {{0, 0}};
    components.push_back(comp);
  }
  // Place all components with sufficient separation to avoid extra integer distances
  vector<pair<ll, ll>> points;
  ll current_offset = 0;
  for (auto& comp : components) {
    ll offset = current_offset;
    while (true) {
      bool good = true;
      for (auto& p : comp) {
        ll px = p.first + offset;
        ll py = p.second;
        for (auto& ex : points) {
          ll dx = px - ex.first;
          ll dy = py - ex.second;
          ll d2 = dx * dx + dy * dy;
          if (is_perfect_square(d2)) {
            good = false;
            break;
          }
        }
        if (!good) break;
      }
      if (good) break;
      offset++;
    }
    // Add shifted points
    for (auto& p : comp) {
      points.emplace_back(p.first + offset, p.second);
    }
    // Update offset for next component
    ll max_x = 0;
    for (auto& pt : points) max_x = max(max_x, pt.first);
    current_offset = max_x + 100;  // generous gap for safety
  }
  // Output
  for (auto& p : points) {
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}

Test details

Test 1

Subtask: 1, 4, 6

Verdict: ACCEPTED

input
3 2

correct output
1 1
1 2
2 2

user output
0 0
1 0
1 1

Test 2

Subtask: 1, 2, 3, 4, 5, 6

Verdict: ACCEPTED

input
1 0

correct output
1 0

user output
0 0

Test 3

Subtask: 1, 3, 4, 5, 6

Verdict: ACCEPTED

input
2 0

correct output
1 0
804289383 846930886

user output
0 0
1 1

Test 4

Subtask: 1, 2, 4, 6

Verdict: ACCEPTED

input
2 1

correct output
1 0
2 0

user output
0 0
1 0

Test 5

Subtask: 1, 3, 4, 5, 6

Verdict: ACCEPTED

input
3 0

correct output
1 0
804289383 846930886
681692777 714636915

user output
0 0
1 1
2 4

Test 6

Subtask: 1, 4, 6

Verdict:

input
3 1

correct output
1 0
2 0
804289383 846930886

user output
(empty)

Test 7

Subtask: 1, 4, 6

Verdict: ACCEPTED

input
3 2

correct output
1 1
1 2
2 2

user output
0 0
1 0
1 1

Test 8

Subtask: 1, 2, 4, 6

Verdict: ACCEPTED

input
3 3

correct output
1 0
2 0
3 0

user output
0 0
1 0
2 0

Test 9

Subtask: 1, 3, 4, 5, 6

Verdict: ACCEPTED

input
4 0

correct output
1 0
804289383 846930886
681692777 714636915
957747793 424238335

user output
0 0
1 1
2 4
3 9

Test 10

Subtask: 1, 4, 5, 6

Verdict:

input
4 1

correct output
1 0
2 0
804289383 846930886
681692777 714636915

user output
(empty)

Test 11

Subtask: 1, 4, 6

Verdict:

input
4 2

correct output
21392 0
1 0
0 510510
804289383 846930886

user output
(empty)

Test 12

Subtask: 1, 4, 6

Verdict:

input
4 3

correct output
1 0
2 0
3 0
804289383 846930886

user output
(empty)

Test 13

Subtask: 1, 4, 6

Verdict: ACCEPTED

input
4 4

correct output
21392 0
1 0
2 0
0 510510

user output
0 0
1 0
2 0
0 1

Test 14

Subtask: 1, 6

Verdict:

input
4 5

correct output
21392 0
22600 0
1 0
0 510510

user output
0 0
1 0
2 0
0 1

Test 15

Subtask: 1, 2, 6

Verdict: ACCEPTED

input
4 6

correct output
1 0
2 0
3 0
4 0

user output
0 0
1 0
2 0
3 0

Test 16

Subtask: 4, 6

Verdict:

input
5 5

correct output
21392 0
22600 0
1 0
0 510510
804289383 846930886

user output
(empty)

Test 17

Subtask: 4, 6

Verdict:

input
6 5

correct output
21392 0
22600 0
1 0
0 510510
804289383 846930886
...

user output
(empty)

Test 18

Subtask: 3, 4, 5, 6

Verdict: ACCEPTED

input
98 0

correct output
1 0
804289383 846930886
681692777 714636915
957747793 424238335
719885386 649760492
...

user output
0 0
1 1
2 4
3 9
4 16
...

Test 19

Subtask: 4, 5, 6

Verdict:

input
98 97

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 20

Subtask: 4, 5, 6

Verdict:

input
98 98

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 21

Subtask: 5, 6

Verdict:

input
98 1185

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 22

Subtask: 5, 6

Verdict:

input
98 1188

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 23

Subtask: 2, 6

Verdict: ACCEPTED

input
98 4753

correct output
1 0
2 0
3 0
4 0
5 0
...

user output
0 0
1 0
2 0
3 0
4 0
...

Test 24

Subtask: 3, 4, 5, 6

Verdict: ACCEPTED

input
99 0

correct output
1 0
804289383 846930886
681692777 714636915
957747793 424238335
719885386 649760492
...

user output
0 0
1 1
2 4
3 9
4 16
...

Test 25

Subtask: 4, 5, 6

Verdict:

input
99 98

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 26

Subtask: 4, 5, 6

Verdict:

input
99 99

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 27

Subtask: 5, 6

Verdict:

input
99 1201

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 28

Subtask: 5, 6

Verdict:

input
99 1212

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 29

Subtask: 2, 6

Verdict: ACCEPTED

input
99 4851

correct output
1 0
2 0
3 0
4 0
5 0
...

user output
0 0
1 0
2 0
3 0
4 0
...

Test 30

Subtask: 3, 4, 5, 6

Verdict: ACCEPTED

input
100 0

correct output
1 0
804289383 846930886
681692777 714636915
957747793 424238335
719885386 649760492
...

user output
0 0
1 1
2 4
3 9
4 16
...

Test 31

Subtask: 4, 5, 6

Verdict:

input
100 1

correct output
1 0
2 0
804289383 846930886
681692777 714636915
957747793 424238335
...

user output
(empty)

Test 32

Subtask: 4, 5, 6

Verdict:

input
100 5

correct output
21392 0
22600 0
1 0
0 510510
804289383 846930886
...

user output
(empty)

Test 33

Subtask: 4, 5, 6

Verdict:

input
100 100

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 34

Subtask: 5, 6

Verdict:

input
100 1000

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 35

Subtask: 5, 6

Verdict:

input
100 1232

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 36

Subtask: 5, 6

Verdict:

input
100 1237

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 37

Subtask: 6

Verdict:

input
100 2222

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 38

Subtask: 6

Verdict:

input
100 3395

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 39

Subtask: 2, 6

Verdict: ACCEPTED

input
100 4950

correct output
1 0
2 0
3 0
4 0
5 0
...

user output
0 0
1 0
2 0
3 0
4 0
...

Test 40

Subtask: 6

Verdict:

input
100 4949

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 41

Subtask: 6

Verdict:

input
100 4948

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 42

Subtask: 6

Verdict:

input
100 4930

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 43

Subtask: 6

Verdict:

input
100 4920

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)

Test 44

Subtask: 6

Verdict:

input
100 4900

correct output
21392 0
22600 0
30056 0
34848 0
38584 0
...

user output
(empty)