Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; const int INFint = 2147483647; const long long INF = 9223372036854775807ll; const long long MOD = 1000000007ll; int main() { ios_base::sync_with_stdio(0); long long n, k; cin >> n >> k; if (n * (n - 1) / 2 <= k) { cout << "no solution" << endl; return 0; } for (int i = 0; i < n; i++) { cout << 0 << ' ' << i << endl; } fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock() / CLOCKS_PER_SEC); return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j, n, k, mx; mx = 1000000000LL; cin >> n >> k; t = (n * (n - 1)) / 2; if (t <= k) { cout << "no solution"; } else { for (i = 0; i < n - 1; i++) { cout << "0 " << i << "\n"; } cout << mx << " " << mx; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { long n, k; cin >> n >> k; if (k >= n * (n - 1) / 2) { cout << "no solution"; return 0; } for (long i = 0; i < n; i++) cout << "0 " << i << endl; return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class C { BufferedReader reader; StringTokenizer tokenizer; PrintWriter out; public void solve() throws IOException { int N = nextInt(); int K = nextInt(); int max = (N-1)*N/2; if( max <= K){ out.println("no solution"); return; } int max_num = 100000000; out.println("0 0"); for(int i = 1; i < N; i++){ out.print(i + " "); out.print( max_num ); max_num -= (N+1); out.println(); } } /** * @param args */ public static void main(String[] args) { new C().run(); } public void run() { try { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; out = new PrintWriter(System.out); solve(); reader.close(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> int main() { int n, k; scanf("%d%d", &n, &k); if (k >= n * (n - 1) / 2) { printf("no solution\n"); return 0; } for (int i = 0; i < n; ++i) printf("0 %d\n", i); }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n * (n - 1) / 2 <= k) { cout << "no solution"; } else { for (int i = 0; i < n; i++) cout << "0 " << i << "\n"; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class ClosestPair { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); //READ---------------------------------------------------- int n = sc.nextInt(), k = sc.nextInt(); if((n*(n-1))/2<=k) System.out.println("no solution"); else{ StringBuilder sb = new StringBuilder(); for (int i = 0; i <= n-1; i++) { sb.append("0 "+i+"\n"); } System.out.print(sb); } //CLOSE---------------------------------------------------- sc.close(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n, k = map(int, raw_input().split()) n -= 1 if k >= n * (n + 1) / 2: print "no solution" else: for i in range(n+1): print 0, i
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int n, k, p1, p2; int main() { cin >> n >> k; int tot = 0; for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) ++tot; if (tot > k) { for (int i = 0; i < n; ++i) { cout << 0 << ' ' << i << endl; } } else cout << "no solution" << endl; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (k >= (n * (n - 1)) / 2) { cout << "no solution"; return 0; } for (int i = 0; i < n; i++) { cout << 0 << ' ' << i << endl; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n,k = [int(x) for x in raw_input().split()] if k >= (n-1)*(n)/2: print("no solution") else: while n: print(1),n n -= 1
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.InputStreamReader; import java.io.PrintWriter; import static java.lang.Math.*; import java.util.ArrayList; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author pttrung */ public class C { public static long Mod = 1000000009; public static void main(String[] args) { Scanner in = new Scanner(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int k = in.nextInt(); long total = (n - 1)*(n)/2; // System.out.println(total); if (total <= k) { out.println("no solution"); } else { /** * The solution will be in the line y = x */ out.println(0 + " " + 0); long x = 0, y = 0; for (int i = 1; i < n; i++) { x += 0; y += 1; out.println(x + " " + y); } } out.close(); } static void check(Point a, Point b, ArrayList<Point> p, Point[] rec, int index) { for (int i = 0; i < 4; i++) { int m = (i + index) % 4; int j = (i + 1 + index) % 4; Point k = intersect(minus(b, a), minus(rec[m], rec[j]), minus(rec[m], a)); if (k.x >= 0 && k.x <= 1 && k.y >= 0 && k.y <= 1) { Point val = new Point(k.x * minus(b, a).x, k.x * minus(b, a).y); p.add(add(val, a)); // System.out.println(a + " " + b + " " + rec[i] + " " + rec[j]); // System.out.println(add(val, a)); } } } static Point intersect(Point a, Point b, Point c) { double D = cross(a, b); if (D != 0) { return new Point(cross(c, b) / D, cross(a, c) / D); } return null; } static Point convert(Point a, double angle) { double x = a.x * cos(angle) - a.y * sin(angle); double y = a.x * sin(angle) + a.y * cos(angle); return new Point(x, y); } static Point minus(Point a, Point b) { return new Point(a.x - b.x, a.y - b.y); } static Point add(Point a, Point b) { return new Point(a.x + b.x, a.y + b.y); } static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } static class Point { double x, y; Point(double x, double y) { this.x = x; this.y = y; } @Override public String toString() { return "Point: " + x + " " + y; } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
[n,k]=[int(i) for i in raw_input().split()] if (n*(n-1)/2)<=k: print "no solution" else: x=0 y=0 j=0 for i in range(n): print 0,i ## print x,y ## j+=1 ## if j==n: ## break ## print x+1,y ## j+=1 ## if j==n: ## break ## print x+1,y+1 ## j+=1 ## if j==n: ## break ## print x,y+1 ## j+=1 ## if j==n: ## break ## x+=1 ## y+=1 ##epsilon=0.000000001 ##[a,b,c,d]=[float(i) for i in raw_input().split()] ##j=0 ##p=(a/b) ##q=((b-a)/b)*((d-c)/d) ##p1=p ##p2=p1+q*p ##i=2 ##while p2-p1>epsilon: ## p1=p2 ## p2=p2+(q**i)*p ## i+=1 ##print p2 ####n=int(raw_input()) ####for i in range(n): #### j=raw_input() #### ##print j[-1:-5:-1] #### if (j[-1:-6:-1]==".alal" and j[0:5]!="miao."): #### print "Freda's" #### elif (j[0:5]=="miao." and j[-1:-6:-1]!=".alal" ): #### print "Rainbow's" #### else: #### print "OMG>.< I don't know!" #### ####
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(), k = sc.nextInt(); if(1l*n*(n-1)/2 <= k) out.println("no solution"); else for (int i = 0; i < n; i++) { out.println("0 " + i); } out.flush(); out.close(); } static class Scanner { BufferedReader bf; StringTokenizer st; public Scanner(InputStream i) { bf = new BufferedReader(new InputStreamReader(i)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(bf.readLine()); return st.nextToken(); } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.math.BigInteger; import java.math.RoundingMode; public class a { public static int vertices=0; public static void main(String[] args) { Scanner s = new Scanner(System.in); int n=s.nextInt(); int k=s.nextInt(); if(k>=(n*n-n)/2) System.out.println("no solution"); else{ for(int i=0;i<n;i++) System.out.println("1"+" "+(3*i)); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
//package Ladder_C; /** * Created by CompuShop on 7/25/2017 at 3:13 PM. */ import java.util.*; public class C_312 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(),k=in.nextInt(); if(k >= (n * (n - 1)) / 2) { System.out.println("no solution"); return; } for (int i = 0; i < n; i++) { System.out.println(0+" "+i); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; char a[1000]; void solve() { int n, k; while (scanf("%d%d", &n, &k) != EOF) { if (((1 + n - 1) * (n - 1) / 2) <= k) { printf("no solution\n"); continue; } else { int temp = 0; for (int i = 1; i <= n; i++) { printf("0 %d\n", i); } } } } int main() { solve(); return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n, k = map(int, input().split()) if (k >= n * (n - 1) // 2): print("no solution") else: for i in range(n): print(0, i)
PYTHON3
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); CTheClosestPair solver = new CTheClosestPair(); solver.solve(1, in, out); out.close(); } static class CTheClosestPair { public void solve(int testNumber, Scanner sc, PrintWriter pw) { int n = sc.nextInt(); int k = sc.nextInt(); int num = n * (n - 1) / 2; if (k < num) { int i = 0; int j = 0; boolean f = false; while (n-- > 0) { pw.println(i + " " + j); j++; } } else pw.println("no solution"); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; string c; int main() { int i, j, k, n, m, l; scanf("%d%d", &n, &k); if (n * (n - 1) / 2 <= k) { puts("no solution"); return 0; } for (i = 1; i <= n; i++) printf("%d %d\n", 0, i); return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; struct node { int x; int y; }; node point[2000 + 10]; int n; int sum; void solve() { for (int i = 2; i <= n; ++i) { point[i].y = point[i - 1].y + 1; } for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) ++sum; } int main() { int k; int tem; scanf("%d%d", &n, &k); solve(); if (k >= sum) puts("no solution"); else { for (int i = 1; i <= n; ++i) { printf("%d %d\n", point[i].x, point[i].y); } } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7; long long n, k; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; long long mx = n * (n - 1) / 2; if (k >= mx) return cout << "no solution", 0; long long y = 0; for (long long i = 1; i < n; i++, y += 2) cout << 0 << " " << y << "\n"; cout << 0 << " " << y - 1; return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.Scanner; public class r185d2c { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k = scan.nextInt(); if((n*n-n)/2 <= k){ System.out.println("no solution"); } else { for(int i=0; i < n; i++){ System.out.println("0 " + i); } } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; inline long long inp() { long long n = 0, s = 1; char p = getchar(); if (p == '-') s = -1; while ((p < '0' || p > '9') && p != EOF && p != '-') p = getchar(); if (p == '-') s = -1, p = getchar(); while (p >= '0' && p <= '9') { n = (n << 3) + (n << 1) + (p - '0'); p = getchar(); }; return n * s; } long long power(long long a, long long b) { long long r = 1, x = a; if (a == 0) return 0; while (b) { if (b & 1) r = (r * x) % 1000000007; x = (x * x) % 1000000007; b >>= 1; } return r % 1000000007; } int gcd(int a, int b) { if (b == 0) return a; gcd(b, a % b); } long long distance(long long a, long long b, long long c, long long d) { double ans; ans = (a - c) * (a - c) + (b - d) * (b - d); ans = sqrt(ans); return ceil(ans); } int main() { long long i, j, k, t, r, w, x, y, z, ans = 0, n = 0, m, d, sum, test, c = 0; n = inp(); k = inp(); if (((n * (n - 1)) / 2) <= k) { printf("no solution\n"); return 0; } for (i = 0; i < n; i++) cout << "0 " << i << endl; return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class TheClosestPair implements Closeable { private InputReader in = new InputReader(System.in); private PrintWriter out = new PrintWriter(System.out); public void solve() { int n = in.ni(), k = in.ni(); if (n * (n - 1) <= 2 * k) { out.println("no solution"); return; } for (int i = 0; i < n; i++) { out.println(0 + " " + i); } } @Override public void close() throws IOException { in.close(); out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int ni() { return Integer.parseInt(next()); } public long nl() { return Long.parseLong(next()); } public void close() throws IOException { reader.close(); } } public static void main(String[] args) throws IOException { try (TheClosestPair instance = new TheClosestPair()) { instance.solve(); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> int main() { int n, k; scanf("%d%d", &n, &k); if ((n * (n - 1) / 2) <= k) { printf("no solution\n"); } else { int i; for (i = 0; i < n; i++) { printf("0 %d\n", i); } } }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; template <class T> inline T Max(T a, T b) { if (a > b) return a; else return b; } template <class T> inline T Min(T a, T b) { if (a < b) return a; else return b; } template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b / gcd(a, b)); } template <class T> inline T TripleMax(T a, T b, T c) { return Max(Max(a, b), c); } template <class T> inline T TripleMin(T a, T b, T c) { return Min(Min(a, b), c); } const long long llinfinity = 9223372036854775807LL; const long long llminusinfinity = -9223372036854775808LL; const int intinfinity = 2147483647; const int intminusinfinity = -2147483648; int n, k; int main(int argc, const char* argv[]) { scanf("%d%d", &n, &k); if (k >= (n * (n - 1) / 2)) { puts("no solution"); } else { for (int i = 0; i < n; ++i) { printf("%d %d\n", 0, i); } } }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> int x[2010], y[2010]; using namespace std; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) x[i] = 0, y[i] = i; int c = 0, tot = 0; int d = (1 << 29); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { tot++; int t = (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]); if ((x[j] - x[i]) * (x[j] - x[i]) >= d) break; if (d > t) d = t; } } if (tot <= k) cout << "no solution" << endl; else for (int i = 0; i < n; ++i) cout << x[i] << " " << y[i] << endl; return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
if __name__ == '__main__': n, k = [int(x) for x in raw_input().rstrip().split()] if n*(n-1) / 2 <= k: print 'no solution' else: for i in range(n): print '0 {}'.format(i)
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> int main() { int cn = 0, i, n, k, p; scanf("%d%d", &n, &k); if (k >= (n * (n - 1)) / 2) { printf("no solution\n"); return (0); } p = n; while (p--) { printf("0 %d\n", cn); cn++; } return (0); }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; int temp = n * (n - 1) / 2; if (temp <= k) { cout << "no solution\n"; return 0; } for (int i = 0; i < n; i++) { cout << 0 << " " << i << endl; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; const int MAX = 2001; int N, K; int main() { scanf("%d%d", &N, &K); if (K >= N * (N - 1) / 2) { puts("no solution"); } else { for (int i = 0; i < N; i++) { printf("0 %d\n", i); } } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import static java.util.Arrays.deepToString; import java.io.*; import java.math.*; import java.util.*; public class Main { static void solve() { int n = nextInt(); int k = nextInt(); int[] x = new int[n]; int[] y = new int[n]; if (n * (n - 1) <= 2 * k) { System.out.println("no solution"); } else { for (int i = 0; i < n; i++) { y[i] = i; } for (int i = 0; i < n; i++) { System.out.println(x[i] + " " + y[i]); } } } public static void main(String[] args) throws Exception { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); setTime(); solve(); printTime(); printMemory(); writer.close(); } static BufferedReader reader; static PrintWriter writer; static StringTokenizer tok = new StringTokenizer(""); static long systemTime; static void debug(Object... o) { System.err.println(deepToString(o)); } static void setTime() { systemTime = System.currentTimeMillis(); } static void printTime() { System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime)); } static void printMemory() { System.err.println("Memory consumed: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime() .freeMemory()) / 1000 + "kb"); } static String next() { while (!tok.hasMoreTokens()) { String w = null; try { w = reader.readLine(); } catch (Exception e) { e.printStackTrace(); } if (w == null) return null; tok = new StringTokenizer(w); } return tok.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static BigInteger nextBigInteger() { return new BigInteger(next()); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) struct point { int x, y; }; int n, k; int dx[2010], dy[2010]; int tot; int sqr(int x) { return x * x; }; int imin(int a, int b) { if (a < b) return a; return b; }; void algo() { int d = 2100000000; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { tot++; if (dx[j] - dx[i] >= d) break; d = imin(d, sqr(dx[i] - dx[j]) + sqr(dy[i] - dy[j])); }; }; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { dx[i] = 0; dy[i] = i; }; algo(); if (tot <= k) cout << "no solution"; else { for (int i = 0; i < n; i++) cout << dx[i] << " " << dy[i] << endl; }; return 0; };
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n, k = map(int, input().split()) tot = 0 for i in range(n): for j in range(i + 1, n): tot += 1 if tot <= k: print('no solution') else: for i in range(n): print(1, i)
PYTHON3
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n,k = map(int ,input().split()) if((n&1)==0) : time = (n//2)*(n-1) else : time = ((n-1)//2)*n if(k>=time): print("no solution") else : for i in range(n): print("0 "+str(i))
PYTHON3
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
/** * Created with IntelliJ IDEA. * User: Venky */ import java.io.*; import java.util.StringTokenizer; public class Main { static void solve() throws IOException { int n = nextInt(); int k = nextInt(); if( ((n-1)*n)/2 <= k) { out.println("no solution"); return; } for(int i=0;i<n;i++) { out.println(i + " " + (i*3000)); } } static BufferedReader br; static StringTokenizer st; static PrintWriter out; public static void main(String[] args) throws IOException { InputStream input = System.in; PrintStream output = System.out; br = new BufferedReader(new InputStreamReader(input)); out = new PrintWriter(output); solve(); out.close(); } static long nextLong() throws IOException { return Long.parseLong(nextToken()); } static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } static String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = br.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, i, k; int tot; cin >> n >> k; tot = (n * (n - 1)) / 2; if (tot <= k) { cout << "no solution\n"; return 0; } for (i = 0; i < n; i++) { cout << i << " " << i * 100000 << "\n"; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long tot; tot = (n * (n - 1)) / 2; if (tot <= k) { cout << "no solution"; return 0; } for (int i = 0; i < n; i++) cout << 0 << " " << i << endl; return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import sys import itertools def solve(n, k): comb = 0 for x in itertools.combinations([0]*n, 2): comb += 1 if comb<=k: return ["no solution"] res = [] #base = 2**n for i in xrange(n): #res.append(str(base/2**(i)) + " -" + str(base*2**(i))) res.append('0 -'+str(i+1)) return res n, k = map(int, sys.stdin.readline().split()) res = solve(n, k) for string in res: print string
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int l = n * (n - 1); l /= 2; if (k >= l) { cout << "no solution\n"; return 0; } pair<int, int> p; vector<pair<int, int> > v; int a = 0, b = 0; for (int i = 0; i < n; i++) { p = make_pair(b, a); v.push_back(p); a++; } for (int i = 0; i < n; i++) { cout << v[i].first << " " << v[i].second << endl; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String [] args ) { try{ String str; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedOutputStream bos = new BufferedOutputStream(System.out); String eol = System.getProperty("line.separator"); byte [] eolb = eol.getBytes(); byte[] spaceb= " ".getBytes(); str = br.readLine(); int blank = str.indexOf( " "); int n = Integer.parseInt(str.substring(0,blank)); int m = Integer.parseInt(str.substring(blank+1)); int tot = ( n * (n-1) ) / 2 ; if(m>= tot) { bos.write("no solution".getBytes()); bos.write(eolb); } else { for(int i = 0 ; i < n ; i++) { bos.write("0".getBytes()); bos.write(spaceb); bos.write(new Integer(i).toString().getBytes()); bos.write(eolb); } } bos.flush(); } catch(IOException ioe) { ioe.printStackTrace(); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.Scanner; public class C185 { public void run() { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); if (n * (n - 1) <= 2 * k) { System.out.println("no solution"); System.exit(0); } int x[] = new int[n + 100]; int y[] = new int[n + 100]; x[0] = -1000000000; y[0] = -1000000000; int d = 10000; for (int i = 1; i < n + 5; i++) { x[i] = x[0] + i; y[i] = y[0] + i * d; } int arr[] = new int[n + 10]; arr[0] = 1; arr[1] = 1; for (int i = 2; i < n + 10; i++) arr[i] = arr[i - 1] + i - 1; // for (int i = 0; i < n + 5; i++) // System.out.println(arr[i]); for (int i = 1; i < n + 5; i++) { //x[i] += arr[i]; y[i] += arr[i]; } for (int i = 0; i < n; i++) System.out.println(x[i] + " " + y[i]); } public static void main(String[] args) { // TODO Auto-generated method stub new C185().run(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.*; import java.util.*; public class C { String line; StringTokenizer inputParser; BufferedReader is; FileInputStream fstream; DataInputStream in; String FInput=""; void openInput(String file) { if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin else { try{ fstream = new FileInputStream(file); in = new DataInputStream(fstream); is = new BufferedReader(new InputStreamReader(in)); }catch(Exception e) { System.err.println(e); } } } void readNextLine() { try { line = is.readLine(); inputParser = new StringTokenizer(line, " "); //System.err.println("Input: " + line); } catch (IOException e) { System.err.println("Unexpected IO ERROR: " + e); } } int NextInt() { String n = inputParser.nextToken(); int val = Integer.parseInt(n); //System.out.println("I read this number: " + val); return val; } String NextString() { String n = inputParser.nextToken(); return n; } void closeInput() { try { is.close(); } catch (IOException e) { System.err.println("Unexpected IO ERROR: " + e); } } public void readFInput() { for(;;) { try { readNextLine(); FInput+=line+" "; } catch(Exception e) { break; } } inputParser = new StringTokenizer(FInput, " "); } long NextLong() { String n = inputParser.nextToken(); long val = Long.parseLong(n); return val; } public static void main(String [] argv) { String filePath=null; if(argv.length>0)filePath=argv[0]; new C(filePath); } boolean [] [] p; public C(String inputFile) { openInput(inputFile); readNextLine(); int n=NextInt(), k=NextInt(); if(n*n-n>k*2) { for(int i=0; i<n; i++) System.out.println(47+" "+i); } else System.out.println("no solution"); closeInput(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256777216") using namespace std; int main() { int n, k; cin >> n >> k; if (2 * k >= n * (n - 1)) { puts("no solution"); return 0; } for (int i = 1; i <= n; i++) { cout << 0 << " " << i << endl; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.*; // WA on 5 public class C185 { int INF = Integer.MAX_VALUE / 100; static Scanner sc = null; static BufferedReader br = null; static PrintStream out = null; static BufferedWriter bw = null; int N = 0; public void solve() throws Exception{ int n = sc.nextInt(); int k = sc.nextInt(); int sum = 0; for(int i = n-1; i >= 0; i--){ sum += i; } if(sum <= k){ out.println("no solution"); return; } for(int i = 0; i < n; i++){ out.println("0 " + i); } } public int[] readIntArray(int n) { int[] ret = new int[n]; for (int i = 0; i < n; i++) { ret[i] = sc.nextInt(); } return ret; } /** * @param args */ public static void main(String[] args) throws Exception{ File file = new File("input.txt"); if(file.exists()){ System.setIn(new BufferedInputStream(new FileInputStream("input.txt"))); } out = System.out; bw = new BufferedWriter(new PrintWriter(out)); sc = new Scanner(System.in); //br = new BufferedReader(new InputStreamReader(System.in)); C185 t = new C185(); t.solve(); bw.close(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.*; import java.util.*; public class SolutionC { BufferedReader in; StringTokenizer str; PrintWriter out; String SK; String next() throws IOException { while ((str == null) || (!str.hasMoreTokens())) { SK = in.readLine(); if (SK == null) return null; str = new StringTokenizer(SK); } return str.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } char[] charArray() throws IOException{ return next().toCharArray(); } public static void main(String[] args) throws IOException { new SolutionC().run(); } void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); //in = new BufferedReader(new FileReader("input.txt")); //out = new PrintWriter("output.txt"); solve(); out.close(); } void solve() throws IOException { long n = nextLong(); long k = nextLong(); if(n*(n-1)/2<=k){ out.println("no solution"); } else{ for (int i = 0; i < n; i++) { out.println(0+" "+i); } } } } class P{ int x; int y; }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int cnt = (n * (n - 1)) / 2; if (cnt <= k) cout << "no solution"; else { for (int i = 1; i <= n; i++) { cout << 0 << ' ' << i << '\n'; } } }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
ar = raw_input().split(" ") n = int(ar[0]) k = int(ar[1]) tot = (n*(n-1))/2 if tot <= k: print "no solution" else: t = n a = 0 b = 0 while t: print a, b a = a+1 b = b+n t-=1
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class C312 { static StringTokenizer st; static BufferedReader in; static PrintWriter pw; public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n = nextInt(); int k = nextInt(); if (n*(n-1)/2 <= k) System.out.println("no solution"); else { for (int i = 1; i <= n; i++) { System.out.println(0+" "+i); } } pw.close(); } private static int nextInt() throws IOException{ return Integer.parseInt(next()); } private static long nextLong() throws IOException{ return Long.parseLong(next()); } private static double nextDouble() throws IOException{ return Double.parseDouble(next()); } private static String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k, ax, bx, tot; cin >> n >> k; tot = (n * (n + 1)) / 2 - n; if (tot <= k) cout << "no solution" << endl; else { for (int i = 1; i <= n; i++) { cout << 0 << " " << i << endl; } } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; unsigned long long mod = 1000000007; int main() { int nop, k; cin >> nop >> k; int max_possi = nop * (nop - 1); max_possi /= 2; if (k >= max_possi) cout << "no solution" << "\n"; else { int x = 0, y = 0; while (nop--) cout << x << " " << y++ << "\n"; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; long long distance(long long x1, long long y1, long long x2, long long y2) { return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); } int main() { long long n, k, d, x, y, tot = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { tot++; } } if (tot <= k) cout << "no solution" << endl; else { for (int i = 0; i < n; i++) { cout << 0 << " " << i + 12345 << endl; } } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n * (n - 1) <= 2 * k) cout << "no solution" << endl; else for (int y = 0; y < n; y++) { cout << 0 << " " << y << endl; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; import java.io.*; public class third { public static void main(String args[]) { int n,k; Scanner sc = new Scanner(System.in); n=sc.nextInt(); k=sc.nextInt(); if(k>=((n*(n-1))/2)) { System.out.println("no solution"); } else { int f=0,t=0; while(t<n) { System.out.println(1+" "+t); t++; } } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.IOException; import java.io.InputStream; import java.util.InputMismatchException; public class CF { public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int N =sc.nextInt(); int K =sc.nextInt(); if(((N*(N-1))>>1)<=K){ System.out.println("no solution"); return; } for(int a=0;a<N;a++){ System.out.println(a+" "+(a*200000)); } } static class FasterScanner{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FasterScanner(){ stream = System.in; //stream = new FileInputStream(new File("dec.in")); } int read(){ if(numChars==-1) throw new InputMismatchException(); if(curChar>=numChars){ curChar = 0; try{ numChars = stream.read(buf); } catch (IOException e){ throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } boolean isSpaceChar(int c){ return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } boolean isEndline(int c){ return c=='\n'||c=='\r'||c==-1; } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String next(){ int c = read(); while(isSpaceChar(c)) c=read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c=read(); } while(!isSpaceChar(c)); return res.toString(); } String nextLine(){ int c = read(); while(isEndline(c)) c=read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c = read(); }while(!isEndline(c)); return res.toString(); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; long n, k; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; if (n * (n - 1) / 2 <= k) cout << "no solution" << endl; else for (int i = 0; i < n; i++) cout << 0 << " " << i << endl; cin.get(); cin.get(); return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int x = n - 1, tot = 0; tot = (x * (x + 1)) / 2; if (tot <= k) return cout << "no solution" << endl, 0; for (int i = 0; i < n; i++) cout << 1 << " " << i << endl; return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n, k = map(int, raw_input().split()) if n*(n-1)/2 <= k: print "no solution" else: for i in range(0, n): print 0, i
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
f = lambda n: n*(n-1)/2 n,k = map(int, raw_input().split()) if k>=f(n): print 'no solution' else: for i in xrange(n): print 0,i
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.Scanner; public class Main implements Runnable { StreamTokenizer ST; PrintWriter out; BufferedReader br; Scanner in; public static void main(String[] args) throws IOException { new Thread(new Main()).start(); } @Override public void run() { try { out = new PrintWriter(new BufferedOutputStream(System.out)); in = new Scanner(System.in); solve(); out.close(); } catch (IOException e) { throw new IllegalStateException(e); } } public void solve() throws IOException { int n = in.nextInt(); int k = in.nextInt(); if (k >= (n * (n - 1)) / 2) { out.println("no solution"); } else { int z = (int) 5e4; out.println("0 0"); int t = 0; for (int i = 1; i < n; ++i) { t += (z - (i + 1)); out.println("0 " + t); } } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; import java.io.*; public class C312 { class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public InputReader() throws FileNotFoundException { reader = new BufferedReader(new FileReader("d:/input.txt")); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){ return Long.parseLong(next()); } } public void run(){ InputReader reader = new InputReader(System.in); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = reader.nextInt(), k = reader.nextInt(); int max = (n-1)*n/2; if(k >= max){ out.println("no solution"); }else{ for(int i = 0 ; i < n ; i ++){ out.println(0+" "+i); } } out.flush(); } public static void main(String[] args) { new C312().run(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.math.*; import java.util.*; public class CF { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); if(((n * (n-1))/2) > k) { int m = 0; int j = 0; while(m++ < n) { System.out.println("0 " + j++); } } else { System.out.print("no solution"); return; } } public static int factorial(int a) { if(a == 1) return 1; return a * factorial(a-1); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, tot; scanf("%d%d", &n, &tot); if (n * (n - 1) / 2 <= tot) { printf("no solution"); return 0; } for (int i = 0; i < n; i++) printf("%d %d\n", 0, i); return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.Scanner; public class ProblemC { public void solve() { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k = scan.nextInt(); if ((n * (n - 1)) / 2 <= k) { System.out.println("no solution"); return; } for (int i = 1; i <= n; i++) { System.out.println("0 " + i); } } public static void main(String[] args) { ProblemC c = new ProblemC(); c.solve(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(s()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } /////////////////////////////////////////////////////////////////////////////////////////// // RRRRRRRRR AAA HHH HHH IIIIIIIIIIIII LLL // // RR RRR AAAAA HHH HHH IIIIIIIIIII LLL // // RR RRR AAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHHHHHHHHHH III LLL // // RRRRRR AAA AAA HHHHHHHHHHH III LLL // // RR RRR AAAAAAAAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIII LLLLLLLLLLLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIIIII LLLLLLLLLLLL // /////////////////////////////////////////////////////////////////////////////////////////// static int n; static long store[]; public static void main(String[] args)throws IOException { PrintWriter out= new PrintWriter(System.out); Reader sc=new Reader(); int n=sc.i(); int k=sc.i(); if(k>=(n*(n-1))/2) out.println("no solution"); else { for(int i=0;i<n;i++) out.println("0 "+i); } out.flush(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
# -*- coding: utf-8 -*- n, k = (int(x) for x in raw_input().split()) m = (n - 1) * n / 2 if k >= m: print 'no solution' else: for i in range(n): print '{} {}'.format(0, i)
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#!/usr/bin/env python import sys n, k = map(int, sys.stdin.readline().strip().split()) mx = (n-1)*n / 2 if k >= mx: print 'no solution' else: for i in xrange(n): print 0, i
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; public class ClosestPair { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int k=s.nextInt(); point[] p=new point[n]; int c=0; for(int i=0;i<n;i++) { point pt = new point(); pt.x=0; pt.y=c; c++; p[i]=pt; } Arrays.sort(p,point.ySort); double d=Integer.MAX_VALUE; int tot=0; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) { ++tot; if (p[j].x-p[i].x>=d) break; d=Math.min(d,distance(p[i],p[j])); } if(tot<=k) System.out.println("no solution"); else for(int i=0;i<n;i++) { System.out.println(p[i].x+" " + p[i].y); } } public static double distance(point p1,point p2) { return (Math.sqrt(Math.pow(p1.x-p2.x, 2)+Math.pow(p1.y-p2.y, 2))); } static class point implements Comparable<point> { int x,y; public point() { } public point(int x, int y) { this.x=x; this.y=y; } public int compareTo(point pt) { return this.x-pt.x; } public static Comparator<point> ySort =new Comparator<point>() { public int compare(point p1,point p2) { int x= p1.x-p2.x; if(p1.x!=p2.x) return x; else return p1.y-p2.y; } }; } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n,k = map(int, raw_input().split()) if n*(n-1)/2 <= k: print "no solution" else: for i in range(n): print 0,i
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int tot = (n) * (n - 1); tot /= 2; if (tot <= k) cout << "no solution" << endl; else { for (int i = 0; i < n; ++i) cout << 1 << " " << i + 1 << endl; } }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; double distance(pair<int, int> a, pair<int, int> b) { return pow(a.first - b.first, 2.0) + pow(a.second - b.second, 2.0); } int gettot(vector<pair<int, int> > v) { sort(v.begin(), v.end()); double d = 1e100; int tot = 0; for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { ++tot; if (v[j].first - v[i].first >= d) break; } } return tot; } int main() { int n = 4; int k = 3; cin >> n >> k; int count = 0; int max = (n - 1) * n / 2; if (k >= max) { cout << "no solution" << endl; return 0; } int ys = 0; vector<pair<int, int> > v; for (int i = 1; i <= n; i++) { cout << 1 << " " << ys << endl; ys += 10; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.*; import java.util.*; public class main { public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int sum = (n * (n-1)) / 2; if(sum <= k) { System.out.println("no solution"); } else { for(int i = 1; i <= n; i++) { System.out.println(i + " " + (i*30000)); } } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n,k=map(int,raw_input().split()) y=sum([x for x in range(1,n)]) if y>k: p=1 for i in range(n): print "0 "+str(p) p+=1 else: print "no solution"
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n,k=map(int,input().split()) if n*(n-1)/2<=k: print("no solution") else: for i in range(0,n):print(0,i) # Made By Mostafa_Khaled
PYTHON3
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if ((n * (n - 1)) / 2 <= k) { cout << "no solution\n"; } else { for (int i = 0; i < n; i++) { cout << "0 " << i << endl; } } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n,k = map(int, raw_input().split()) if k < n*(n-1)/2: for i in xrange(n): print 0, i else: print "no solution"
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n; long long k; while (~scanf("%d%I64d", &n, &k)) { long long t = (long long)n * (n - 1) / 2; if (k >= t) { printf("no solution\n"); continue; } int y = 1; for (i = 0; i < n; i++) printf("%d %d\n", 0, y), y++; } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter writer; static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } static long nextLong() throws IOException { return Long.parseLong(nextToken()); } static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } static boolean eof = false; static String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public static void main(String[] args) throws IOException { tokenizer = null; reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); banana(); reader.close(); writer.close(); } static int test(int a[], int b[]) { int sum = 0; for (int i = 0; i < a.length; ++i) sum += a[i] * b[i]; return sum; } static void banana() throws IOException { int n = nextInt(); int k = nextInt(); if (k >= n * (n - 1) / 2) System.out.println("no solution"); else { for (int i = 0; i < n; ++i) { System.out.println(i + " " +i * 2 * n) ; } } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; const int N = 105; const int M = 505; const int MOD = int(1e9) + 7; const int INF = 0x3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1.0); const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; template <class T> inline T Min(T a, T b) { return a < b ? a : b; } template <class T> inline T Max(T a, T b) { return a > b ? a : b; } template <class T> inline T Min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T Max(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T sqr(T a) { return a * a; } template <class T> inline T cub(T a) { return a * a * a; } template <class T> inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); } int main() { int a, b; while (scanf("%d%d", &a, &b) != EOF) { int i, tot = (a * (a - 1)) / 2; if (tot <= b) { printf("no solution\n"); } else { for (i = 0; i < a; i++) { printf("%d %d\n", 0, i); } } } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n,k = map(int,raw_input().split()) if n == 2 : print "no solution" exit() lim = n*(n-1)/2 if k>=lim: print "no solution" else: for _ in xrange(n): print "0 "+str(_)
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n, k = map(int, raw_input().split()) if k >= (n * (n - 1)) / 2: print 'no solution' exit() for i in range(n): print 0, i
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n * (n - 1) / 2 <= k) cout << "no solution"; else for (int i = 0; i < n; ++i) cout << "0 " << i << endl; return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> int main() { int n, k, i; scanf("%d %d", &n, &k); if (k < n * (n - 1) / 2) { for (i = 0; i < n; i++) printf("%d %d\n", 0, 3 * i); } else puts("no solution"); return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { // BufferedReader c = new BufferedReader(new InputStreamReader(System.in)); Scanner c=new Scanner(System.in); int n=c.nextInt(),k=c.nextInt(); int largestPossibleTime=(n*(n-1))/2; if (k>=largestPossibleTime) System.out.println("no solution"); else { for (int i=0;i<n;i++) System.out.println(0+" "+i); } } } //must declare new classes here
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; import java.util.Map.Entry; import java.io.*; import java.awt.Point; import java.math.BigInteger; import static java.lang.Math.*; public class Codeforces_Solution_C implements Runnable{ final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException{ if (ONLINE_JUDGE){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); }else{ in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } } String readString() throws IOException{ while(!tok.hasMoreTokens()){ try{ tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null; } } return tok.nextToken(); } int readInt() throws IOException{ return Integer.parseInt(readString()); } long readLong() throws IOException{ return Long.parseLong(readString()); } double readDouble() throws IOException{ return Double.parseDouble(readString()); } public static void main(String[] args){ new Thread(null, new Codeforces_Solution_C(), "", 128 * (1L << 20)).start(); } long timeBegin, timeEnd; void time(){ timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } long memoryTotal, memoryFree; void memory(){ memoryFree = Runtime.getRuntime().freeMemory(); System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB"); } void debug(Object... objects){ if (DEBUG){ for (Object o: objects){ System.err.println(o.toString()); } } } public void run(){ try{ timeBegin = System.currentTimeMillis(); memoryTotal = Runtime.getRuntime().freeMemory(); init(); solve(); out.close(); time(); memory(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } boolean DEBUG = false; void solve() throws IOException{ int n = readInt(); int k = readInt(); if (k>=(n*(n-1))/2) { out.println("no solution"); return; } for (int i=0; i<n; i++) out.println(i+" "+i*n); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import sys def main(): n, k = map(int, sys.stdin.readline().split()) if n * (n - 1) / 2 <= k: print "no solution" return for i in xrange(n): print 0, i return if __name__ == "__main__": main()
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.io.IOException; import java.util.Scanner; /** * Created with IntelliJ IDEA. * User: Alexander Shchegolev * Date: 26.05.13 * Time: 18:08 * To change this template use File | Settings | File Templates. */ public class Three { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); if (n * (n - 1) / 2 <= k) { System.out.println("no solution"); return; } for (int i = 0; i < n; i++) { int x = i / 500000000; int y = i % 500000000; System.out.printf("%d %d\n", x, y); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); int sum = (n * (n - 1)) / 2; if (sum <= k) { out.println("no solution"); return; } for (int i = 0; i < n; i++) { out.println("0 " + i); } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; import java.io.*; import java.math.*; public class C { public static Scanner scan = new Scanner(System.in); public static boolean bg = false; public static void main(String[] args) throws Exception { long n1 = Integer.parseInt(scan.next()); long n2 = Integer.parseInt(scan.next()); long bound = n1*(n1-1)/2; if (bg) System.out.println(bound); if (n2>=bound){ System.out.println("no solution"); } else { for (int i=0;i<n1;i++){ System.out.println(0+" "+i); } } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; long long k; cin >> n >> k; int ans = (n * (n - 1)) / 2; if (k >= ans) { cout << "no solution" << endl; return 0; } else { for (int i = 0; i < n; i++) { cout << 0 << ' ' << i << endl; } } }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
n, k = map(int, input().split()) up = (int)(n * (n - 1) / 2); if k >= up: print ("no solution") else: for i in range (0, n): print (0, i)
PYTHON3
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int k, n; int main() { int i, j; scanf("%d%d", &n, &k); if (k >= (n * (n - 1) / 2)) puts("no solution"); else { for (i = 1; i <= n; ++i) printf("0 %d\n", i); } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; string mirror = "AHIMOTUVWXY"; string letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int mxn = 1e6 + 5; const int mod = 1e9 + 7; int main() { long long n, m, i, j, k, x, y, t; cin >> n >> k; x = n * (n - 1) / 2; if (x <= k) { cout << "no solution" << endl; } else { for (i = 0; i < n; i++) cout << 0 << " " << i << endl; } }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.util.*; /** * * @author N-AssassiN */ public class Main { private static BufferedReader reader; private static BufferedWriter out; private static StringTokenizer tokenizer; //private final static String filename = "filename"; /** * call this method to initialize reader for InputStream and OututStream */ private static void init(InputStream input, OutputStream output) { reader = new BufferedReader(new InputStreamReader(input)); out = new BufferedWriter(new OutputStreamWriter(output)); //reader = new BufferedReader(new FileReader(filename + ".in")); //out = new BufferedWriter(new FileWriter(filename + ".out")); tokenizer = new StringTokenizer(""); } /** * get next word */ private static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { //TODO add check for eof if necessary tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { init(System.in, System.out); int n = nextInt(); //long startTime = System.currentTimeMillis(); int k = nextInt(); int maxTot = (n * (n - 1)) / 2; if (maxTot <= k) { out.write("no solution\n"); } else { for (int i = 0; i < n; i++) { out.write("0 " + i + "\n"); } } //long runTime = System.currentTimeMillis() - startTime; //out.write(runTime + "\n"); out.flush(); } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.Scanner; public class Main2 { public static void main(String args[]){ Scanner input = new Scanner(System.in); int n = input.nextInt(); int k = input.nextInt(); sentence(n,k); } public static void sentence(int n,int k){ if(n == 2 || k >= (n*(n-1))/2){ System.out.println("no solution"); }else{ for(int i = 0 ; i < n ; i++){ System.out.println(0+" "+i); } } } }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
a,b=map(int,raw_input().split()) if b >= a*(a-1)/2: print 'no solution' else: cnt = 0 for i in range(0,a): print 0,i
PYTHON
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
import java.util.*; import java.util.concurrent.LinkedBlockingDeque; import java.util.zip.ZipEntry; import javax.imageio.stream.MemoryCacheImageInputStream; import javax.security.auth.Subject; import javax.security.auth.kerberos.KerberosKey; import javax.swing.plaf.basic.BasicScrollPaneUI.HSBChangeListener; import javax.tools.JavaCompiler; import javax.xml.bind.SchemaOutputResolver; import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec; import org.omg.CORBA.TRANSACTION_MODE; import org.omg.IOP.TAG_CODE_SETS; import java.awt.font.GraphicAttribute; import java.io.*; import java.nio.channels.AcceptPendingException; import java.rmi.server.RMIClassLoader; import java.security.spec.DSAGenParameterSpec; import java.sql.PseudoColumnUsage; import java.time.Period; //all inclusive public class Main { public static void main(String[] args) throws Exception { int n=sc.nextInt(); int k=sc.nextInt(); if((n*n-n)/2<=k) { pw.println("no solution"); }else { for(int i=0;i<n;i++) { pw.println(0+" "+i); } } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if(this.x==other.x) { return Long.compare(other.y, this.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if(this.y==other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } public static long GCD(long a, long b) { if (b == 0) return a; if (a == 0) return b; return (a > b) ? GCD(a % b, b) : GCD(a, b % a); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } static long Pow(long a, long e, long mod) // O(log e) { a %= mod; long res = 1l; while (e > 0) { if ((e & 1) == 1) res = (res * a) % mod; a = (a * a) % mod; e >>= 1l; } return res; } public static long modinverse(long a,long mod) { return Pow(a, mod-2, mod); } static long nc(int n, int r) { if (n < r) return 0; long v = fac[n]; v *= Pow(fac[r], mod - 2, mod); v %= mod; v *= Pow(fac[n - r], mod - 2, mod); v %= mod; return v; } public static boolean isprime(long a) { if (a == 0 || a == 1) { return false; } if (a == 2) { return true; } for (int i = 2; i < Math.sqrt(a) + 1; i++) { if (a % i == 0) { return false; } } return true; } public static boolean isPal(String s) { boolean t = true; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) { t = false; break; } } return t; } public static long RandomPick(long[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static int RandomPick(int[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static void PH(String s, boolean reverse) { prelen = s.length(); HashsArray[HashsArrayInd] = new int[prelen + 1]; prepow = new int[prelen]; if (HashsArrayInd == 0) { int[] mods = { 1173017693, 1173038827, 1173069731, 1173086977, 1173089783, 1173092147, 1173107093, 1173114391, 1173132347, 1173144367, 1173150103, 1173152611, 1173163993, 1173174127, 1173204679, 1173237343, 1173252107, 1173253331, 1173255653, 1173260183, 1173262943, 1173265439, 1173279091, 1173285331, 1173286771, 1173288593, 1173298123, 1173302129, 1173308827, 1173310451, 1173312383, 1173313571, 1173324371, 1173361529, 1173385729, 1173387217, 1173387361, 1173420799, 1173421499, 1173423077, 1173428083, 1173442159, 1173445549, 1173451681, 1173453299, 1173454729, 1173458401, 1173459491, 1173464177, 1173468943, 1173470041, 1173477947, 1173500677, 1173507869, 1173522919, 1173537359, 1173605003, 1173610253, 1173632671, 1173653623, 1173665447, 1173675577, 1173675787, 1173684683, 1173691109, 1173696907, 1173705257, 1173705523, 1173725389, 1173727601, 1173741953, 1173747577, 1173751499, 1173759449, 1173760943, 1173761429, 1173762509, 1173769939, 1173771233, 1173778937, 1173784637, 1173793289, 1173799607, 1173802823, 1173808003, 1173810919, 1173818311, 1173819293, 1173828167, 1173846677, 1173848941, 1173853249, 1173858341, 1173891613, 1173894053, 1173908039, 1173909203, 1173961541, 1173968989, 1173999193}; mod = RandomPick(mods); int[] primes = { 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 }; prime = RandomPick(primes); } prepow[0] = 1; if (!reverse) { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod); } } else { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod); } } HashsArrayInd++; } public static int PHV(int l, int r, int n, boolean reverse) { if (l > r) { return 0; } int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod); if (!reverse) { val = (int) ((1l * val * prepow[prelen - l]) % mod); } else { val = (int) ((1l * val * prepow[r - 1]) % mod); } return val; } public static void genprime(int n) { boolean prime[] = new boolean[n+1]; for(int i=0;i<n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } for(int i = 2; i <= n; i++) { if(prime[i] == true) { primes.put(i,primes.size()); primes2.put(primes2.size(),i); } } } public static long LSB(long x) { return x&-x; } static class fenwick { long[] arr; public fenwick(Integer[] a) { arr=new long[a.length+1]; for(int i=1;i<=a.length;i++) { arr[i]+=a[i-1]; if(i+LSB(i)<=a.length) { arr[(int) (i+LSB(i))]+=arr[i]; } } } public fenwick(int[] a) { arr=new long[a.length+1]; for(int i=1;i<=a.length;i++) { arr[i]+=a[i-1]; if(i+LSB(i)<=a.length) { arr[(int) (i+LSB(i))]+=arr[i]; } } }public fenwick(long[] a) { arr=new long[a.length+1]; for(int i=1;i<=a.length;i++) { arr[i]+=a[i]; if(i+LSB(i)<=a.length) { arr[(int) (i+LSB(i))]+=arr[i]; } } } public void update(int ind,long x) { int i=ind; while(i<arr.length) { arr[i]+=x; i+=LSB(i); } } public long PrefixSum(int ind) { long sum=0; int i=ind; while(i>0) { sum+=arr[i]; i=(int) (i-LSB(i)); } return sum; } public long RangeQuerey(int l,int r) { return this.PrefixSum(r+1)-this.PrefixSum(l); } public long maxConsecutiveValue(int k) { long max=Long.MIN_VALUE; for(int i=k-1;i<arr.length-1;i++) { max= Math.max(max, this.RangeQuerey(i-k+1, i)); } return max; } public long minConsecutiveValue(int k) { long min=Long.MAX_VALUE; for(int i=k-1;i<arr.length-1;i++) { min= Math.min(min, this.RangeQuerey(i-k+1, i)); } return min; } public long value(int ind) { return arr[ind]; } } static void sieveLinear(int N) { ArrayList<Integer> primes = new ArrayList<Integer>(); lp = new int[N + 1]; //lp[i] = least prime divisor of i for(int i = 2; i <= N; ++i) { if(lp[i] == 0) { primes.add(i); lp[i] = i; } int curLP = lp[i]; for(int p: primes)//all primes smaller than or equal my lowest prime divisor if(p > curLP || p * 1l * i > N) break; else lp[p * i] = p; } } public static void primefactorization(int n) { int x=n; while(x>1) { int lowestDivisor=lp[x]; while(x%lowestDivisor==0) { primefactors.add(lowestDivisor); x/=lowestDivisor; } } } public static class SuffixArray { int[] SA; int[] AS; String SS; public SuffixArray(String S) //has a terminating character (e.g. '$') { SS=S; char[] s=new char[S.length()+1]; for(int i=0;i<S.length();i++) { s[i]=S.charAt(i); } s[S.length()]='$'; int n = s.length, RA[] = new int[n]; SA = new int[n]; for(int i = 0; i < n; ++i) { RA[i] = s[i]; SA[i] = i; } for(int k = 1; k < n; k <<= 1) { sort(SA, RA, n, k); sort(SA, RA, n, 0); int[] tmp = new int[n]; for(int i = 1, r = 0, s1 = SA[0], s2; i < n; ++i) { s2 = SA[i]; tmp[s2] = RA[s1] == RA[s2] && RA[s1 + k] == RA[s2 + k] ? r : ++r; s1 = s2; } for(int i = 0; i < n; ++i) RA[i] = tmp[i]; if(RA[SA[n-1]] == n - 1) break; } AS=new int[SA.length]; for(int i=0;i<SA.length;i++) { AS[SA[i]]=i; } } public String toString() { return Arrays.toString(SA); } public int get(int n) { return SA[n]; } public int Substring(String s) { // log(n)*|s| int low=0; int high=SA.length; int mid=(low+high)/2; int ind=-1; while(low<high-1) { if(SS.length()-SA[mid]<s.length()) { boolean less=false; for(int i=SA[mid];i<SS.length();i++) { if(SS.charAt(i)>s.charAt(i-SA[mid])) { less=true; break; } if(SS.charAt(i)<s.charAt(i-SA[mid])) { less=false; break; } } if(!less) { low=mid; }else { high=mid; } }else { boolean less=true; boolean equal=true; for(int i=SA[mid];i<SA[mid]+s.length();i++) { if(SS.charAt(i)<s.charAt(i-SA[mid])&&equal) { less=false; equal=false; break; } if(SS.charAt(i)!=s.charAt(i-SA[mid])){ equal=false; } } if(equal) { ind=SA[mid]; } if(!less) { low=mid; }else { high=mid; } } mid=(low+high)/2; } return ind; } public int LastSubstring(String s) { // log(n)*|s| int low=0; int high=SA.length; int mid=(low+high)/2; int ind=-1; while(low<high-1) { if(SS.length()-SA[mid]<s.length()) { boolean less=true; for(int i=SA[mid];i<SS.length();i++) { if(SS.charAt(i)<s.charAt(i-SA[mid])) { break; } if(SS.charAt(i)>s.charAt(i-SA[mid])) { less=false; break; } } if(less) { low=mid; }else { high=mid; } }else { boolean less=true; boolean equal=true; for(int i=SA[mid];i<SA[mid]+s.length();i++) { if(SS.charAt(i)>s.charAt(i-SA[mid])&&equal) { less=false; equal=false; break; } if(SS.charAt(i)!=s.charAt(i-SA[mid])){ equal=false; } } if(equal) { ind=SA[mid]; } if(less) { low=mid; }else { high=mid; } } mid=(low+high)/2; } return ind; } public int CountSubstring(String s) { int z=LastSubstring(s); if(z==-1) return 0; return AS[z]-AS[Substring(s)]+1; } public void sort(int[] SA, int[] RA, int n, int k) { int maxi = Math.max(256, n), c[] = new int[maxi]; for(int i = 0; i < n; ++i) c[i + k < n ? RA[i + k] : 0]++; for(int i = 0, sum = 0; i < maxi; ++i) { int t = c[i]; c[i] = sum; sum += t; } int[] tmp = new int[n]; for(int i = 0; i < n; ++i) { int j = SA[i] + k; tmp[c[j < n ? RA[j] : 0]++] = SA[i]; } for(int i = 0; i < n; ++i) SA[i] = tmp[i]; } } static LinkedList<Integer>primefactors=new LinkedList<>(); static TreeMap<Integer,Integer>primes=new TreeMap<Integer, Integer>(); static TreeMap<Integer,Integer>primes2=new TreeMap<Integer, Integer>(); static int[]lp; static int[][] HashsArray; static int HashsArrayInd = 0; static int[] prepow; static int prelen = 0; static int prime = 61; static long fac[]; static int mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
JAVA
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 100500; const int infi = (1 << 30); const long long infl = (1LL << 62); const double eps = 1e-9; const long long mod = 1000000007LL; const double pi = acos(-1.0); int n, k; int main() { cin >> n >> k; if (n * (n - 1) <= k * 2) { cout << "no solution\n"; } else { for (int i = 0; i < n; i++) { cout << 0 << " " << i << endl; } } return 0; }
CPP
312_C. The Closest Pair
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is <image>. The pseudo code of the unexpected code is as follows: input n for i from 1 to n input the i-th point's coordinates into p[i] sort array p[] by increasing of x coordinate first and increasing of y coordinate second d=INF //here INF is a number big enough tot=0 for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x>=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j])) output d Here, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded. You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded? Input A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109). Output If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held: * All the points must be distinct. * |xi|, |yi| ≤ 109. * After running the given code, the value of tot should be larger than k. Examples Input 4 3 Output 0 0 0 1 1 0 1 1 Input 2 100 Output no solution
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); if ((n * (n - 1) / 2 <= k)) printf("no solution\n"); else { for (int i = 0; i < n; i++) printf("0 %d\n", i); } return 0; }
CPP