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
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; void output() { for (int i = 0; i < n; i++) printf("%d ", a[i]); puts(""); } int check() { for (int i = 0; i < n; i++) if (a[a[i] - 1] != n - i) return 0; return 1; } int main() { cin >> n; for (int i = 0; i < n / 2; i += 2) a[i] = i + 2; for (int i = 1; i < n / 2; i += 2) a[i] = n + 1 - i; int j = 1; for (int i = n - 2; i >= n / 2; i -= 2, j += 2) a[i] = j; j = n - 1; for (int i = n - 1; i >= n / 2; i -= 2, j -= 2) a[i] = j; if (n & 1) a[n / 2] = n / 2 + 1; if (check() == 1) output(); else printf("-1\n"); return 0; }
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
import java.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String args[]) throws IOException { InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int N=in.readInt(); int A[]=new int[N+1]; Arrays.fill(A,-1); if(N%4!=0&&N%4!=1) { System.out.println("-1"); return; } if(N==1) { System.out.println("1"); return; } TreeSet<Integer> T=new TreeSet<Integer>(); for(int i=1;i<=N;i++) T.add(i); if(N%4==1) { A[(N+1)/2]=(N+1)/2; T.remove((N+1)/2); } for(int i=1;i<=N;i++) { if(A[i]==-1) { int ai=T.pollFirst(); if(ai==i) { int temp=T.pollFirst(); T.add(ai); ai=temp; } A[i]=ai; //System.out.println(i+" gets "+ai); A[ai]=N-i+1; //System.out.println(ai+" gets "+(N-i+1)); A[N-i+1]=N-ai+1; //System.out.println((N-i+1)+" gets "+(N-ai+1)); A[N-ai+1]=i; //System.out.println((N-ai+1)+" gets "+i); T.remove(ai); T.remove(N-i+1); T.remove(N-ai+1); T.remove(i); } } check(A); for(int i=1;i<=N;i++) out.print(A[i]+" "); out.println(); out.close(); } private static void check(int[] a) { int N=a.length-1; for(int i=1;i<=N;i++) { if(a[a[i]]!=N-i+1) { System.out.println((1/0)); } } } } class permGen { public int A[]; public permGen(int a[]) { A=new int[a.length]; for(int i=0;i<a.length;i++) A[i]=a[i]; } public int[] nextPerm() { //Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation. int N=A.length; int k=-1; for(int i=0;i<N-1;i++) { if(A[i]<A[i+1]) k=i; } if(k==-1) return null; //Find the largest index l such that a[k] < a[l]. Since k + 1 is such an index, l is well defined and satisfies k < l int l=-1; for(int i=k+1;i<N;i++) { if(A[k]<A[i]) l=i; } //Swap a[k] with a[l]. swap(A,k,l); //Reverse the sequence from a[k + 1] up to and including the final element a[n] int i=k+1; int j=N-1; while (i<=j) { swap(A,i,j); i++; j--; } return A; } private void swap(int A[],int i,int j) { int t=A[i]; A[i]=A[j]; A[j]=t; } } class InputReader { private InputStream stream; private byte[] buf=new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream=stream; } public 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++]; } public int readInt() { 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 boolean isSpaceChar(int c) { if(filter!=null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } public char readCharacter() { int c=read(); while (isSpaceChar(c)) c=read(); return (char) c; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; long p[100001]; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); long n; cin >> n; if (n % 4 == 2 || n % 4 == 3) cout << "-1"; else { if (n % 2) p[n / 2 + 1] = n / 2 + 1; for (int i = 1; i < n / 2; i += 2) { p[i] = i + 1; p[i + 1] = n - i + 1; p[n - i] = i; p[n - i + 1] = n - i; } for (int i = 1; i <= n; i++) cout << p[i] << " "; } return 0; }
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
import java.util.*; import java.io.*; public class Round176A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); if(n%4==2 || n%4==3){ System.out.println(-1); return; } if(n%4==0){ int[] p = new int[n+1]; int k = n/4; for(int i=1; i<=k; i++) p[2*i-1] = 2*i; for(int i=1; i<=k; i++) p[2*i] = 4*k+2-2*i; for(int i=2*k+1; i<=4*k; i++) p[i] = 4*k+1 - p[4*k+1-i]; for(int i=1; i<=n; i++) pw.print(p[i]+" "); pw.println(); pw.flush(); return; } int[] p = new int[n+1]; int k = n/4; for(int i=1; i<=k; i++) p[2*i-1] = 2*i; for(int i=1; i<=k; i++) p[2*i] = 4*k+3-2*i; for(int i=2*k+2; i<=4*k+1; i++) p[i] = 4*k+2-p[4*k+2-i]; p[2*k+1] = 2*k+1; for(int i=1; i<=n; i++) pw.print(p[i]+" "); pw.println(); pw.flush(); } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; if (n % 4 > 1) { cout << "-1\n"; return 0; } int p[n]; if (n % 4 == 1) { p[n / 2] = (n + 1) / 2; } if (n != 1) { p[0] = 2; p[1] = n; p[n - 2] = 1; p[n - 1] = n - 1; } for (int i = 2, j = n - 4; i < n / 2; i += 2, j -= 2) { p[i] = p[i - 2] + 2; p[i + 1] = p[i - 1] - 2; p[j] = p[i] - 1; p[j + 1] = p[i + 1] - 1; } for (int i : p) cout << i << " "; cout << endl; return 0; }
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
n=int(input()) if n==1: print (1) exit() if n%4>1: print (-1) exit() ans=[-1]*n left=n start=n-2 nums=1 nume=n while left>=4: ans[start]=nums ans[nums-1]=nums+1 ans[nums]=nume ans[nume-1]=nume-1 start-=2 nums+=2 nume-=2 left-=4 # print (ans) if left==1: ans[start+1]=start+2 print (*ans)
PYTHON3
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; return 0; } int i; if (n % 2 == 1) a[(n + 1) / 2] = (n + 1) / 2; for (i = 1; i <= n / 2;) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[n - i] = i; i += 2; } for (i = 1; i <= n; i++) { cout << a[i] << " "; } cout << endl; return 0; }
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; // Lucky Permutation // 2013/03/23 public class P286A{ Scanner sc=new Scanner(System.in); int n; void run(){ n=sc.nextInt(); solve(); } void solve(){ if(n%4==0||n%4==1){}else{ println("-1"); return; } TreeSet<Integer> set=new TreeSet<Integer>(); for(int i=0; i<n; i++){ set.add(i); } TreeSet<Integer> temp=new TreeSet<Integer>(); int[] a=new int[n]; fill(a, -1); for(int index=0; index<n/2; index++){ if(a[index]>-1){ continue; } int i; for(i=set.pollFirst(); index==i||n-1-index==i; i=set.pollFirst()){ temp.add(i); } a[index]=i; a[n-1-index]=n-1-i; a[a[index]]=n-1-index; a[a[n-1-index]]=index; set.addAll(temp); set.remove(i); set.remove(n-1-i); set.remove(n-1-index); set.remove(index); temp.clear(); } if(n%2==1){ a[n/2]=n/2; } StringBuilder sb=new StringBuilder(); for(int i=0; i<n; i++){ sb.append(a[i]+1); if(i<n-1){ sb.append(' '); } } println(sb.toString()); } void println(String s){ System.out.println(s); } public static void main(String[] args){ Locale.setDefault(Locale.US); new P286A().run(); } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author PM */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); if (n%4==2 || n%4==3) {out.println(-1); return;} int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = i+1; } for (int at = 0; at < n/2; at +=2) { int last = (n-1-at); int first = res[at]; res[at] = res[at+1]; res[at+1] = res[last]; res[last] = res[last-1]; res[last-1] = first; } for (int i = 0; i < n; i++) { out.print(res[i] + " "); } } } 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 nextInt() { return Integer.parseInt(next()); } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
import java.util.Scanner; public class CodeforcesRound176C { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner kde= new Scanner(System.in); int n=kde.nextInt(); if((n%4==2)||(n%4==3)) { System.out.println(-1); return; } int[] m= new int[n+1]; if (n % 4 == 0) { int t = n/4; for (int i = 1; i <= t; i++) { int odd = 2*i - 1; int even = 2*i; m[odd] = even; m[even] = n+1 - odd; m[n+1 - odd] = n+1 - even; m[n+1 - even] = odd; } } if (n % 4 == 1) { int t = (n - 1)/4; for (int i = 1; i <= t; i++) { int odd = 2*i-1; int even = 2*i; m[odd] = even; m[even] = n+1 - odd; m[n+1 - odd] = n+1 - even; m[n+1 - even] = odd; } m[(n+1)/2] = (n+1)/2; } for (int i = 1; i <= n; i++) { System.out.print(m[i]+" "); } System.out.println(); } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; inline bool xdy(double x, double y) { return x > y + 1e-9; } inline bool xddy(double x, double y) { return x > y - 1e-9; } inline bool xcy(double x, double y) { return x < y - 1e-9; } inline bool xcdy(double x, double y) { return x < y + 1e-9; } const long long int mod = 1000000007; int n; int ans[100005]; int main() { ios_base::sync_with_stdio(0); while (~scanf("%d", &n)) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } for (int i = 1; i <= n / 2; i += 2) { ans[i] = i + 1; ans[i + 1] = n - i + 1; ans[n - i + 1] = n - i; ans[n - i] = i; } if (n & 1) ans[n / 2 + 1] = n / 2 + 1; for (int i = 1; i <= n; i++) { printf("%d ", ans[i]); } printf("\n"); } }
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 4 > 1) { cout << -1; return 0; } int m = n / 4, perm[100001]; for (int i = 0; i < m; i++) { int a, b, c, d; a = 2 * i + 1; b = 2 * i + 2; c = n - 2 * i; d = n - 2 * i - 1; perm[a] = b; perm[b] = c; perm[c] = d; perm[d] = a; } if (n % 4 == 1) perm[n / 2 + 1] = n / 2 + 1; for (int i = 1; i <= n; i++) { cout << perm[i] << " "; } }
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { // Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in), 16000)); InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 64000)); // 2 8 4 6 3 5 1 7 // // 13 12 11 10 9 8 7 6 5 4 3 2 1 // 1 2 3 4 5 6 7 8 9 10 11 12 13 // 2 13 4 11 6 9 7 5 8 3 10 1 12 int n = in.nextInt(); boolean odd = false ; int oddV = 0 ; if(n % 2 != 0) { odd = true ; oddV = 1 ; n-- ; } if(n % 4 != 0){ out.println(-1); out.close(); return ; } for(int i = 2 ; i <= n / 2 ; i+=2){ out.println(i ); out.println(n + 2 + oddV - i ); } if(odd) out.println((n/ 2) + 1); for(int i = n / 2 + 1 ; i <= n - 1 ; i += 2) { out.println(n - i); out.println(i + oddV); } out.close(); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 64000); 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 long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
import java.io.PrintWriter; import java.util.Scanner; public class C { public static void main(String [] args){ Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); if(n%4==1 || n%4==0){ int a [] = new int[n+1]; for(int i = 1 ; i <= n/2 ; i+=2 ){ a[i]=i+1; a[n-i+1] = n-i; } for(int i = 2 ; i <= n/2 ; i+=2){ a[i]=n-i+2; a[n-i+1] = i - 1; } if(n%2 ==1){ a[n/2+1]= n/2+1; } out.print(a[1]); for(int i = 2 ; i <= n ; i++){ out.print(" "+a[i]); } } else{ out.print(-1); } out.close(); } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
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.BufferedReader; import java.util.LinkedList; 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; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); if (n % 4 < 2) { LinkedList<Integer> ans = new LinkedList<>(); int curN = 0; if (n % 4 == 1) { ans.add(1); curN = 1; } else { ans.add(2); ans.add(4); ans.add(1); ans.add(3); curN = 4; } while (ans.size() < n) { ans.addFirst(curN + 4); ans.addFirst(2); ans.addLast(1); ans.addLast(curN + 3); curN += 4; } int[] ansArr = new int[n]; int k = 0; for (int i : ans) { ansArr[k] = i; k++; } for (int i = 0; i < n / 4; i++) { ansArr[2 * i] += 2 * i; ansArr[2 * i + 1] += 2 * i; ansArr[n - 1 - 2 * i] += 2 * i; ansArr[n - 2 - 2 * i] += 2 * i; } if (n % 4 == 1) { ansArr[n / 2] += 2 * (n / 4); } for (int i : ansArr) { out.print(i + " "); } } else { out.println(-1); } } } static class InputReader { private StringTokenizer tokenizer; private BufferedReader reader; public InputReader(InputStream inputStream) { reader = new BufferedReader(new InputStreamReader(inputStream)); } private void fillTokenizer() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } } public String next() { fillTokenizer(); return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; int n; deque<int> ans; bool used[100500]; int add(int i, int n) { if (n % 2 == 0) { if (i >= n / 2) i = n - i - 1; return i / 2; } if (i > n / 2) i = n - i - 1; return i / 2; } int main() { cin >> n; if (n == 1) { cout << 1; return 0; } else if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } if (n % 4 == 1) { ans.push_back(1); while (ans.size() < n) { int sz = ans.size(); ans.push_front(sz + 4); ans.push_front(2); ans.push_back(1); ans.push_back(sz + 3); } for (int i = 0; i < ans.size() / 2; i++) ans[i] += 2 * (i / 2); for (int i = ans.size() / 2; i < ans.size(); i++) ans[i] += 2 * ((ans.size() - i - 1) / 2); } else { ans.push_back(2); ans.push_back(4); ans.push_back(1); ans.push_back(3); while (ans.size() < n) { int sz = ans.size(); ans.push_front(sz + 4); ans.push_front(2); ans.push_back(1); ans.push_back(sz + 3); } for (int i = 0; i < ans.size() / 2; i++) ans[i] += 2 * (i / 2); for (int i = ans.size() / 2; i < ans.size(); i++) ans[i] += 2 * ((ans.size() - i - 1) / 2); } for (int i = 0; i < ans.size(); i++) cout << ans[i] << " "; return 0; }
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the required permutation size. Output Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≀ pi ≀ n) after a space β€” the required permutation. If there are multiple answers, you can print any of them. Examples Input 1 Output 1 Input 2 Output -1 Input 4 Output 2 4 1 3 Input 5 Output 2 5 3 1 4
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) cout << -1 << endl; else if (n % 4 == 0) { for (int i = 1; i <= (n / 2); i++) { if ((i % 2) == 1) a[i] = i + 1; else a[i] = n - i + 2; } for (int i = n; i > (n / 2); i--) { if ((i % 2) == (n % 2)) a[i] = i - 1; else a[i] = n - i; } for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; } else { for (int i = 1; i <= (n / 2); i++) { if ((i % 2) == 1) a[i] = i + 1; else a[i] = n - i + 2; } for (int i = n; i > ((n + 1) / 2); i--) { if ((i % 2) == (n % 2)) a[i] = i - 1; else a[i] = n - i; } a[(n + 1) / 2] = (n + 1) / 2; for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << 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()) if n*(n-1) <= k*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
# -*- coding: utf-8 -*- """ Created on Sat Jul 06 18:16:44 2013 @author: workshop """ from __future__ import division; from bisect import *; from fractions import Fraction; import sys; from math import *; from fractions import *; import io; import re; INF = 987654321987654321987654321; def readint(delimiter=' ') : return map(int, raw_input().split(delimiter)); def readstr(delimiter=' ') : return raw_input().split(delimiter); def readfloat(delimiter=' ') : return map(float, raw_input().split(delimiter)); def index(a, x): 'Locate the leftmost value exactly equal to x' i = bisect_left(a, x) if i != len(a) and a[i] == x: return i raise ValueError def find_lt(a, x): 'Find rightmost value less than x' i = bisect_left(a, x) if i: return a[i-1] raise ValueError def find_le(a, x): 'Find rightmost value less than or equal to x' i = bisect_right(a, x) if i: return a[i-1] raise ValueError def find_gt(a, x): 'Find leftmost value greater than x' i = bisect_right(a, x) if i != len(a): return a[i] raise ValueError def find_ge(a, x): 'Find leftmost item greater than or equal to x' i = bisect_left(a, x) if i != len(a): return a[i] raise ValueError def bin_search(a, x, left, right) : while left<=right : mid = (left + right)//2; if a[mid] == x : return mid; elif a[mid] < x : left = mid + 1; elif a[mid] > x : right = mid - 1; pass return -1; pass def printf(format, *args): """Format args with the first argument as format string, and write. Return the last arg, or format itself if there are no args.""" sys.stdout.write(str(format) % args) pass if __name__ == '__main__': n, k = readint(); if (n-1)*(n)/2 <= k : print "no solution"; else : for ii in xrange(n) : print 0, ii; pass pass pass
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
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package Practice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author Rohan */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n,k; String[] S=br.readLine().split(" "); n=Integer.parseInt(S[0]); k=Integer.parseInt(S[1]); if(((n*(n-1))/2)<=k) System.out.println("no solution"); else{ int temp=1000000; for(int i=0;i<n;i++){ System.out.println(0 + " " + temp); temp+=(2*i+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
''' Created on 2013-5-27 @author: zhxfl ''' a, b = map(int,raw_input().split()); n = a * (a - 1) / 2; if b >= n: print 'no solution' else: for i in range(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
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.math.BigInteger; import java.util.*; import java.text.*; public class cf312C { static BufferedReader br; static Scanner sc; static PrintWriter out; public static void initA() { try { br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new FileReader("input.txt")); sc = new Scanner(System.in); //out = new PrintWriter("output.txt"); out = new PrintWriter(System.out); } catch (Exception e) { } } static boolean next_permutation(Integer[] p) { for (int a = p.length - 2; a >= 0; --a) { if (p[a] < p[a + 1]) { for (int b = p.length - 1;; --b) { if (p[b] > p[a]) { int t = p[a]; p[a] = p[b]; p[b] = t; for (++a, b = p.length - 1; a < b; ++a, --b) { t = p[a]; p[a] = p[b]; p[b] = t; } return true; } } } } return false; } public static void initB() { try { br = new BufferedReader(new FileReader("input.txt")); sc = new Scanner(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } catch (Exception e) { } } public static String getString() { try { return br.readLine(); } catch (Exception e) { } return ""; } public static Integer getInt() { try { return Integer.parseInt(br.readLine()); } catch (Exception e) { } return 0; } public static Integer[] getIntArr() { try { StringTokenizer temp = new StringTokenizer(br.readLine()); int n = temp.countTokens(); Integer temp2[] = new Integer[n]; for (int i = 0; i < n; i++) { temp2[i] = Integer.parseInt(temp.nextToken()); } return temp2; } catch (Exception e) { } return null; } public static Long[] getLongArr() { try { StringTokenizer temp = new StringTokenizer(br.readLine()); int n = temp.countTokens(); Long temp2[] = new Long[n]; for (int i = 0; i < n; i++) { temp2[i] = Long.parseLong(temp.nextToken()); } return temp2; } catch (Exception e) { } return null; } public static String[] getStringArr() { try { StringTokenizer temp = new StringTokenizer(br.readLine()); int n = temp.countTokens(); String temp2[] = new String[n]; for (int i = 0; i < n; i++) { temp2[i] = (temp.nextToken()); } return temp2; } catch (Exception e) { } return null; } public static int getMax(Integer[] ar) { int t = ar[0]; for (int i = 0; i < ar.length; i++) { if (ar[i] > t) { t = ar[i]; } } return t; } public static void print(Object a) { out.println(a); } public static void print(String s, Object... a) { out.printf(s, a); } public static int nextInt() { return sc.nextInt(); } public static double nextDouble() { return sc.nextDouble(); } public static void main(String[] ar) { initA(); solve(); out.flush(); } static long hitung(long l){ long byk_el = l-1; if(byk_el%2==0){ return (byk_el+1) * (byk_el/2); }else{ return ((byk_el+1)/2) * (byk_el); } } public static void solve() { Long xx[] = getLongArr(); long n = xx[0], tle = xx[1]; long milyar = 1000000000l; long maksimal = hitung(n); if(maksimal<=tle){ //print(maksimal); print("no solution"); return; } long needed ; for(int i =1 ;i <=n ;i++){ print(i+" "+i*5000); } } }
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 GCD(int a, int b) { if (!a) return b; return GCD(b % a, a); } vector<int> x(4000); vector<int> y(4000); void D(double x, double y, double x1, double y1) { double d = (x - x1) * (x - x1) + (y - y1) * (y - y1); cout << sqrt(d) << "\n"; } int main() { int n, k; cin >> n >> k; int tot = ((n - 1) * n) / 2; if (tot > k) { y[0] = 0; for (int i = 1; i < n; i++) { y[i] = y[i - 1] + (100000 - i); } for (int i = 0; i < n; i++) { printf("%d %d\n", i, y[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.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.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; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); if (k >= (n * (n - 1)) / 2) { out.println("no solution"); return; } for (int i = 0; i < n; i++) { out.println(0 + " " + i); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); 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()); } } }
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 i, n, k; cin >> n >> k; if (n * (n - 1) / 2 <= k) { puts("no solution"); return 0; } for (i = 1; 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() { long n, k; cin >> n >> k; long kc = 2001; if (k >= n * (n - 1) / 2) { cout << "no solution"; return 0; } long sum = 0; long ax[2005], ay[2005]; for (int i = 1; i <= n; i++) { sum += kc; ax[i] = 0; ay[i] = sum; cout << 0 << " " << sum << endl; --kc; } 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; template <class T> T gmin(T u, T v) { return (u < v) ? u : v; } template <class T> T gmax(T u, T v) { return (u > v) ? u : v; } template <class T> T gcd(T u, T v) { if (v == 0) return u; return (u % v == 0) ? v : gcd(v, u % v); } int main() { long long n, m, tmp; cin >> n >> m; tmp = n * (n - 1) / 2; if (tmp <= m) { puts("no solution"); return 0; } for (m = 1, tmp = 0; m <= n; ++m, tmp += n + 10) cout << m << " " << tmp << 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; 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; scanf("%d %d", &n, &k); if ((n * (n - 1)) / 2 <= k) { printf("no solution\n"); return 0; } for (int i = 0; i < (int)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.*; public class Pair{ public static void main(String[] args){ Scanner reader = new Scanner(System.in); int n = reader.nextInt(); int k = reader.nextInt(); Point[] p = new Point[n]; Point dir = new Point(1,2001); p[0] = new Point(0,0); for(int i = 1; i < n; i++) p[i] = p[i-1].add(dir); if((n*(n-1))/2 > k){ for(int i = 0; i < n; i++) System.out.println(p[i].x + " " + p[i].y); }else{ System.out.println("no solution"); } } public static boolean test(Point[] p, int k){ Arrays.sort(p); int n = p.length; int tot = 0; double d = 1e16; 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, p[i].dis(p[j])); } return tot > k; } public static class Point implements Comparable<Point>{ int x,y; public Point(int _x, int _y){ x = _x; y = _y; } public Point add(Point p){ return new Point(x+p.x, y+p.y); } public double dis(Point p){ return Math.sqrt(Math.pow(x-p.x,2)+Math.pow(y-p.y,2)); } public int compareTo(Point p){ if(x == p.x) return y-p.y; return x-p.x; } } }
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 n, k; int main() { cin >> n >> k; if (n * (n - 1) / 2 <= k) { cout << "no solution\n"; return 0; } for (int i = 1; i <= n; i++) { cout << 1 << " " << i + 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
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (((n) * (n - 1)) / 2 > k) { for (int i = 0; i < n; i++) cout << "0 " << i << endl; } else { cout << "no solution" << 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 - 1) * n / 2 <= k) { cout << "no solution" << endl; } else { int tot = 0; int i, j; for (i = 0; i <= 1e9; i++) for (j = 0; j <= 1e9; j++) { if (tot < n) { cout << i << " " << j << endl; tot++; } else j = 1e9, i = 1e9; } } }
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" << endl; 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=list(map(int,input().split())) if (n*n-n)//2<=k: print("no solution") else: x=0 y=0 store=[] count=0 store.append(str(x)+' '+str(y)) while len(store)<n: y+=1 store.append(str(x)+' '+str(y)) for j in store: print(j)
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 n, k; int main() { cin >> n >> k; if (((n * (n - 1)) >> 1) <= k) { cout << "no solution"; return 0; } for (int i = 0; i < n; ++i) { cout << i << ' ' << 1000000000 - i * 3000 << 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; while (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; } } } 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 n, k; cin >> n >> k; if (k >= n * (n - 1) / 2) { cout << "no solution\n"; } else { for (long long 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
#include <bits/stdc++.h> using namespace std; long long Min(long long i, long long j) { return i < j ? i : j; } long long Max(long long i, long long j) { return i > j ? i : j; } int main() { long long a, b, c, d, e, i, j, k, l, m, n; while (cin >> n >> k) { if (k >= (n * (n - 1)) / 2) cout << "no solution\n"; else { a = -2000000; for (i = 1; i <= n; i++) cout << 0 << ' ' << ++a << 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() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; if (n * (n - 1) / 2 <= k) { cout << "no solution" << '\n'; return 0; } else { for (int i = 1; i <= n; i++) { cout << "1 " << i + 1 << 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.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class CF { public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int n = in.nextInt(); int k = in.nextInt(); if (n * (n - 1) / 2 <= k) { out.println("no solution"); } else { int x = 0; int y = 0; for (int i = 0; i < n; i++) { out.println(x + " " + y); y += (n - x); x++; } } out.close(); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); 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()); } }
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 y, k, n, x, i; scanf("%d%d", &n, &k); n--; x = (n * (n + 1)) / 2; if (x > k) { for (i = 1; i <= n + 1; i++) printf("0 %d\n", i); } else printf("no solution\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
import java.util.Arrays; import java.util.Locale; import java.util.Scanner; public class NearestPairSolver { private int n; private int k; public static void main(String[] args) { NearestPairSolver solver = new NearestPairSolver(); solver.readData(); int[] solution = solver.solve(); if (solution[0] == -1) { solver.print("no solution"); } else { solver.print(solution); } } private void print(int[] values) { StringBuilder builder = new StringBuilder(); for (int value : values) { builder.append("0 "); builder.append(value); builder.append(System.getProperty("line.separator")); } print(builder); } private void print(Object value) { System.out.println(value); } private void readData() { Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); k = scanner.nextInt(); } private int[] solve() { int maxK = n * (n - 1) / 2; if (k >= maxK) { return new int[] {-1}; } int[] result = new int[n]; for (int i = 0; i < n; i++) { result[i] = i; } return result; } }
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); int tot = (n * n - n) / 2; if (tot <= K) { printf("no solution\n"); return 0; } int x = 0, y = 0; for (int i = 0; i < n; i++) { printf("%d %d\n", 0, y); y += 2; } 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*(n-1)/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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<pair<int, int>> v; int now = 1; for (int i = 1; i <= n - 1; ++i) { v.emplace_back(1, now); now += 2; } v.emplace_back(1, now); int tot = 0; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { ++tot; } } if (tot > k) { for (auto p : v) { printf("%d %d\n", p.first, p.second); } } else { cout << "no solution\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.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; public class TheClosestPair { public static void main(String[] args) { MyScanner sc = new MyScanner(); int N = sc.nextInt(); int K = sc.nextInt(); if (K >= N * (N - 1) / 2) { System.out.println("no solution"); return; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < N; i++) { sb.append("1 " + (9881747 - i) + "\n"); } System.out.print(sb.toString()); } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
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.math.BigInteger; import java.util.StringTokenizer; /** * Created by Leonti on 2016-03-12. */ public class C { public static void main(String[] args) { InputReader inputReader = new InputReader(System.in); PrintWriter printWriter = new PrintWriter(System.out, true); int n = inputReader.nextInt(); int k = inputReader.nextInt(); int max = ((n - 1) * n) / 2; max = max == 1 ? 1 : max == 2 ? 3 : max; if (max <= k) { printWriter.print("no solution"); } else { for (int i = 0; i < n; i++) { printWriter.println(0 + " " + i); } } printWriter.close(); } private static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } public int[] nextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; ++i) { array[i] = nextInt(); } return array; } public long[] nextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; ++i) { array[i] = nextLong(); } return array; } public double[] nextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; ++i) { array[i] = nextDouble(); } return array; } public String[] nextStringArray(int size) { String[] array = new String[size]; for (int i = 0; i < size; ++i) { array[i] = next(); } return array; } public boolean[][] nextBooleanTable(int rows, int columns, char trueCharacter) { boolean[][] table = new boolean[rows][columns]; for (int i = 0; i < rows; ++i) { String row = next(); assert row.length() == columns; for (int j = 0; j < columns; ++j) { table[i][j] = (row.charAt(j) == trueCharacter); } } return table; } public char[][] nextCharTable(int rows, int columns) { char[][] table = new char[rows][]; for (int i = 0; i < rows; ++i) { table[i] = next().toCharArray(); assert table[i].length == columns; } return table; } public int[][] nextIntTable(int rows, int columns) { int[][] table = new int[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { table[i][j] = nextInt(); } } return table; } public long[][] nextLongTable(int rows, int columns) { long[][] table = new long[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { table[i][j] = nextLong(); } } return table; } public double[][] nextDoubleTable(int rows, int columns) { double[][] table = new double[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { table[i][j] = nextDouble(); } } return table; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public BigInteger nextBigInteger() { return new BigInteger(next()); } public boolean hasNext() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String line = readLine(); if (line == null) { return false; } tokenizer = new StringTokenizer(line); } return true; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } public String readLine() { String line; try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } } }
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
def calk(n): return n*(n-1)/2 n,k = map(int,raw_input().split()) if calk(n) > k: for i in range(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
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class my_class { public static void main(String[] args) { Scanner ololo = new Scanner(System.in); int n = ololo.nextInt(), k = ololo.nextInt(); if((n*(n - 1) /2) <= k){ System.out.println("no solution"); }else{ for(int i = 0; i < n; i++){ System.out.println("1 " + 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder out = new StringBuilder(); String [] sp = br.readLine().split(" "); int n = Integer.parseInt(sp[0]); int k = Integer.parseInt(sp[1]); int max = (n) * (n-1); max /= 2; if(max <= k){ out.append("no solution"); }else{ for (int i = 0; i < n; i++) { out.append(0 + " " + i + "\n"); } } System.out.print(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; int main() { int i, j, k, l, m, n, x, y, z, r, ans = 0, mn = INT_MAX, mx = INT_MIN, res = 0; cin >> n >> k; if (k * 2 >= n * (n - 1)) cout << "no solution"; else { for (i = 0; i < n; ++i) { cout << 0 << " " << n + 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
#include <bits/stdc++.h> int main() { long long p, n; int i = 0, j = 2; scanf("%I64d %I64d", &n, &p); if (((n - 1) * n) / 2 <= p) printf("no solution\n"); else while (n--) { printf("%d %d\n", i, j); j += 2; } 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 C { private void solve() throws IOException { int n = ni(); int k = ni(); if (n * (n - 1) / 2 <= k) { prln("no solution"); return; } for (int i = 0; i < n; ++i) { prln(0 + " " + i); } } public static void main(String ... args) throws IOException { new C().run(); } private PrintWriter pw; private BufferedReader br; private StringTokenizer st; private void run() throws IOException { pw = new PrintWriter(System.out); br = new BufferedReader(new InputStreamReader(System.in)); solve(); br.close(); pw.close(); } private void pr(Object o) { pw.print(o); } private void prln(Object o) { pw.println(o); } private long nl() throws IOException { return Long.parseLong(nt()); } private double nd() throws IOException { return Double.parseDouble(nt()); } private int ni()throws IOException { return Integer.parseInt(nt()); } private String nt() throws IOException { if (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.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> #pragma GCC optimize("Ofast") using namespace std; long long power(long long b, long long e, long long m) { if (e == 0) return 1; if (e % 2) return b * power(b * b % m, (e - 1) / 2, m) % m; else return power(b * b % m, e / 2, m); } long long power(long long b, long long e) { if (e == 0) return 1; if (e % 2) return b * power(b * b, (e - 1) / 2); else return power(b * b, e / 2); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; if (n * (n - 1) / 2 <= k) cout << "no solution"; else { for (auto i = 1; i <= n; i++) { cout << i << " " << i + (n + 1) * 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
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; int N, K; void Read() { cin >> N >> K; } void Print() { if (K >= N * (N - 1) / 2) { cout << "no solution\n"; return; } for (int i = 1; i <= N; ++i) cout << "0 " << i << "\n"; } int main() { Read(); Print(); 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
s=input().split() n=int(s[0]) k=int(s[1]) ans=[] a=0 for i in range(n): for j in range(i+1,n): a+=1 if(a<=k): print("no solution") else: for i in range(-10**9,-10**9+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
import sys n, k = [int(el) for el in sys.stdin.readline().split()] if (n - 1) * n / 2 <= k: 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.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.TreeSet; public class ProblemA { class Point implements Comparable<Point>{ int x; int y; public Point(int a, int b) { x = a; y = b; } @Override public int compareTo(Point f) { if(x < f.x) return -1; else if(x > f.x) return 1; else if(y < f.y) return -1; return 1; } } public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); long k = s.nextLong(); long limit = 1000000000; long py[] = new long[n]; for (int i = 0; i < n; i++) { py[i] = limit; limit--; } long tot = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { tot++; } } if(tot > k){ for (int i = 0; i < n; i++) { System.out.println("0 "+py[i]); } } else System.out.println("no solution"); } }
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.InputStreamReader; import java.io.IOException; import java.util.InputMismatchException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; 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; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); int time = 0; for (int i = 1; i < n; ++i) time += i; if (time > k) for (int i = 0; i < n; ++i) out.println("0 " + i); else out.println("no solution"); } } class InputReader { BufferedReader in; StringTokenizer st; public InputReader(InputStream stream) { in = new BufferedReader(new InputStreamReader(stream)); eat(""); } public int nextInt() { return Integer.parseInt(next()); } public String next() { while (!st.hasMoreTokens()) eat(nextLine()); return st.nextToken(); } public String nextLine() { try { return in.readLine(); } catch (IOException e) { throw new InputMismatchException(); } } public void eat(String str) { if (str == null) throw new InputMismatchException(); st = new StringTokenizer(str); } }
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 maxK = ((n - 1) * n) / 2; if (maxK <= k) { cout << "no solution" << endl; } 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, i, j, tot = 0; scanf("%d%d", &n, &k); if (n * (n - 1) / 2 > k) { for (i = 1; i <= n && tot < n; i++) { for (j = i + 1; j <= n && tot < n; j++, tot++) { printf("%d %d\n", i, j); } } } 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.io.*; import java.util.*; public class TheClosestPair { public TheClosestPair(Scanner in) { int n, k; int steps; int i; n = in.nextInt(); k = in.nextInt(); steps = (n-1)*(n)/2; if (steps <= k) System.out.printf("no solution%n"); else { int x = 0; for (i=0; i < n; i++) { x += (n-i); System.out.printf("%d %d%n", 0, x); } } } public static void main(String[] args) { new TheClosestPair(new Scanner(System.in)); } }
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; scanf("%d", &n); scanf("%d", &k); int tComplexity = n * (n - 1) / 2; if (tComplexity > k) { for (int i = 0; i < n; i++) { printf("%d %d\n", 0, i); } } else printf("%s\n", "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
n, k = map(int,raw_input().split()) tot = n*(n-1)/2 if tot <= k: print "no solution" else: for i in range(n): print 13,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() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; t = 1; while (t--) { long long n, k, i; cin >> n >> k; if (k >= (n * (n - 1)) / 2) cout << "no solution"; else { long long a[n], b[n]; for (i = 0; i < n; i++) a[i] = i + 1; long long x = 0; for (i = 0; i < n; i++) { b[i] = n * i; } for (i = 0; i < n; i++) cout << a[i] << " " << b[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.util.Scanner; public class C { 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"); in.close(); return; } for (int i = 0; i < n; i++) { System.out.println(0+" "+i); } in.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
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d%d", &n, &k); if (n * (n - 1) / 2 > k) { for (int i = 0; i < n; i++) printf("0 %d\n", i); } else printf("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
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; if (((n - 1) * n) / 2 <= k) { cout << "no solution" << endl; 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> int main() { int n, k; while (scanf("%d%d", &n, &k) != EOF) { if (k >= n * (n - 1) / 2) { printf("no solution\n"); } 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 java.util.*; public class cf311a { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int max = (n*n-n)/2; if(max <= 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
#!/usr/bin/python n, k = map(int, raw_input().split()) if n*(n-1)/2 <= k: print "no solution" else: for y in xrange(n): print 0, y
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() { long long n, k; 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; } } }
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 = 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
import java.io.*; import java.util.*; import java.util.Map.Entry; public class C { void run() throws IOException { int n = ni(), k = ni(); if ((n * (n - 1)) / 2 <= k) { pw.println("no solution"); } else { for (int i = 1; i <= n; i++) { pw.println(0 + " " + i); } } // for (int i = 2; i <= 100; i++) { // tr(i + " " + time(i) + " " + (i * (i - 1) / 2)); // } } int time(int n) { int t = 0; double[] x = new double[n]; double[] y = new double[n]; for (int i = 0; i < n; i++) { x[i] = 0; y[i] = i; } double d = 123456789; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { t++; if (x[j] - x[i] >= d) { break; } d = Math.min(d, Math.sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]))); } } return t; } int[] na(int a_len) throws IOException { int[] _a = new int[a_len]; for (int i = 0; i < a_len; i++) _a[i] = ni(); return _a; } int[][] nm(int a_len, int a_hei) throws IOException { int[][] _a = new int[a_len][a_hei]; for (int i = 0; i < a_len; i++) for (int j = 0; j < a_hei; j++) _a[i][j] = ni(); return _a; } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int ni() throws IOException { return Integer.parseInt(next()); } String nl() throws IOException { return br.readLine(); } void tr(String debug) { if (!OJ) pw.println(" " + debug); } static PrintWriter pw; static BufferedReader br; static StringTokenizer st; static boolean OJ; public static void main(String[] args) throws IOException { long timeout = System.currentTimeMillis(); OJ = System.getProperty("ONLINE_JUDGE") != null; pw = new PrintWriter(System.out); br = new BufferedReader(OJ ? new InputStreamReader(System.in) : new FileReader(new File("C.txt"))); while (br.ready()) new C().run(); if (!OJ) { pw.println(); pw.println(System.currentTimeMillis() - timeout); } br.close(); pw.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.awt.Point; import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; import static java.lang.Math.*; public class Solve 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 Solve(), "", 256 * (1L << 20)).start(); } long timeBegin, timeEnd; void time(){ timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } void debug(Object... objects){ if (!ONLINE_JUDGE){ for (Object o: objects){ System.err.println(o.toString()); } } } int sm(int x){ if (x==1) return 0;else return 1; } int gcd(int a,int b){ if (b==0) return a; else{ return gcd(b,a%b); } } void psevdokod() throws IOException{ int n=readInt(); int[] x=new int[n]; int[] y=new int[n]; for (int i=0;i<n;i++){ x[i]=readInt(); y[i]=readInt(); } //O(n*(n-1)/2) double d=Double.MAX_VALUE; int tot=0; for (int i=0;i<n;i++){ for (int j=i+1;j<n;j++){ tot++; if (x[j]-x[i]>=d){ break; } d=Math.min(d, Math.sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]))); } } out.println(tot); } void solve() throws IOException{ int n=readInt(); int k=readInt(); int k1=n*(n-1); int k2=k*2; if (k1<=k2){ out.println("no solution"); return; } for (int i=0;i<n;i++){ int x=n-i; out.println(n+" "+x); } } public void run(){ try{ timeBegin = System.currentTimeMillis(); init(); solve(); //psevdokod(); out.close(); time(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-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, k; scanf("%d %d", &n, &k); if (n * 1LL * (n - 1) / 2 <= k) printf("no solution\n"); else { 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
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; cin >> n >> k; if (k >= n * (n - 1) / 2) { cout << "no solution" << endl; return 0; } for (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
n,k=map(int, input().split()) if(n*(n-1)//2 <=k): 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.PrintWriter; import java.util.Scanner; public class C185D2C { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(), k = in.nextInt(); if (k >= n*(n-1) / 2) { out.println("no solution"); } else { for (int i = 0; i < n; i++) { out.printf("%d %d\n", 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
import java.io.*; import java.util.*; public class C { public static void main(String[] args){ FastScanner sc = new FastScanner(); int n = sc.nextInt(); int k = sc.nextInt(); if(((n * (n - 1)) / 2) <= k) { System.out.println("no solution"); } else { for(int i = 0; i < n; i++) { System.out.println("0 " + i); } } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(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; inline long long mod(long long n, long long m = (long long)(1e9 + 7)) { return (n % m + m) % m; } inline long long gcd(long long a, long long b) { return (b == 0LL) ? a : gcd(b, a % b); } inline long long modPow(long long a, long long b, long long m = (long long)(1e9 + 7)) { long long ret = 1LL; while (b > 0LL) { if (b & 1) ret = mod(ret * a, m); a = mod(a * a, m); b >>= 1; } return ret; } inline bool leapYear(int year) { return (year % 400 == 0) || (year % 100 != 0 && year % 4 == 0); } int main() { int n, k; while (scanf("%d %d", &n, &k) == 2) { if (n * (n - 1) / 2 <= k) printf("no solution\n"); else { for (int y = (0); y < ((n)); y++) printf("0 %d\n", 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
from Queue import * # Queue, LifoQueue, PriorityQueue from bisect import * #bisect, insort from datetime import * from collections import * #deque, Counter,OrderedDict,defaultdict import calendar import heapq import math import copy import itertools def solver(): n,k = map(int, raw_input().split()) if k >= (n * (n -1)) / 2: print "no solution" return for i in range(n): print 0,i if __name__ == "__main__": solver()
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
x = raw_input().split() n = int(x[0]) k = int(x[1]) tot = n*(n-1)/2 if tot <= 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(System.out); sc = new StringTokenizer(br.readLine()); int n = nxtInt(); int k = nxtInt(); if (k >= (n * (n - 1)) / 2) out.println("no solution"); else for (int i = 0; i < n; i++) out.println(0 + " " + i); br.close(); out.close(); } static BufferedReader br = new BufferedReader(new InputStreamReader( System.in)); static StringTokenizer sc; static String nxtTok() throws IOException { while (!sc.hasMoreTokens()) { String s = br.readLine(); if (s == null) return null; sc = new StringTokenizer(s.trim()); } return sc.nextToken(); } static int nxtInt() throws IOException { return Integer.parseInt(nxtTok()); } static long nxtLng() throws IOException { return Long.parseLong(nxtTok()); } static int[] nxtIntArr(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nxtInt(); return a; } static char[] nxtCharArr() throws IOException { return nxtTok().toCharArray(); } }
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 C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), k = in.nextInt(); int sum = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) sum++; StringBuilder sb = new StringBuilder(); if (sum > k) { int x = 0, y = 0; int d = 10000; for (int i = 0; i < n; i++) { sb.append(x + " " + y).append('\n'); y += d; d--; } } else { sb.append("no solution").append('\n'); } System.out.print(sb); } }
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
__author__ = 'liuchang' import sys n , k = map(int , sys.stdin.readline().split(' ')) if n * (n -1 ) / 2 <= k: print "no solution" else: for i in range(n): print "%d %d" % ( 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
n, k = [int(i) for i in raw_input().strip().split()] if k >= (n)*(n-1)/2: print "no solution" else: print "0 0" x = 0 y = 0 k = n - 1 for i in range(2, n+1): x += 1 y += k k -= 1 print x, y
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 = [int(x) for x in raw_input().split()] if K>=N*(N-1)/2: print 'no solution' else: for i in xrange(N): print '0 %d'%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
n,k = map(int, raw_input().split(' ')) if k>=(n-1)*n/2: print "no solution" else: a=0 b=0 for i in range(n): print a,b b+=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 sys input=sys.stdin.readline from collections import defaultdict as dc from collections import Counter from bisect import bisect_right, bisect_left import math from operator import itemgetter from heapq import heapify, heappop, heappush from queue import PriorityQueue as pq 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
#include <bits/stdc++.h> using namespace std; long long int modpow(long long int a, long long int n, long long int temp) { long long int res = 1; while (n > 0) { res = (res * res) % temp; if (n & 1) res = (res * a) % temp; n /= 2; } return res; } long long int gcd(long long int a, long long int b) { if (a == 0) return (b); else return (gcd(b % a, a)); } int main() { int n, k; cin >> n >> k; if ((n * (n - 1)) / 2 > k) { int x = 0, y = 0, tot = 0; while (1) { tot++; cout << x << " " << y << endl; y++; if (tot == n) break; } } else { cout << "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
n,k = map(int,input().split()) if n*(n-1) <= k*2: print('no solution') else: x = 11 for i in range(n-1): print(1,x) x+=3 print(1,x-5)
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.util.*; import java.io.*; public class a { static long mod = 1000000007; public static void main(String[] args) throws IOException { //Scanner input = new Scanner(new File("input.txt")); //PrintWriter out = new PrintWriter(new File("output.txt")); input.init(System.in); PrintWriter out = new PrintWriter((System.out)); int n = input.nextInt(), k = input.nextInt(); if(k >= n*(n-1)/2) out.println("no solution"); else { int at = 0, diff = n; for(int i = 0; i<n; i++) { out.println(0+" "+at); at+=diff; diff--; } } out.close(); } static long pow(long base, long p) { if(p==0) return 1; if((p&1) == 0) { long sqrt = pow(base, p/2); return (sqrt*sqrt)%mod; } return (base*pow(base, p-1))%mod; } static long modinv(long x) { return pow(x, mod-2); } /* Sum Interval Tree - uses O(n) space Updates and queries over a range of values in log(n) time */ static class IT { int[] left,right, a, b; long[] val; IT(int n) { left = new int[4*n]; right = new int[4*n]; val = new long[4*n]; a = new int[4*n]; b = new int[4*n]; init(0,0, n); } int init(int at, int l, int r) { a[at] = l; b[at] = r; if(l==r) left[at] = right [at] = -1; else { int mid = (l+r)/2; left[at] = init(2*at+1,l,mid); right[at] = init(2*at+2,mid+1,r); } return at++; } //return the sum over [x,y] long get(int x, int y) { return go(x,y, 0); } long go(int x,int y, int at) { if(at==-1) return 0; if(x <= a[at] && y>= b[at]) return val[at]; if(y<a[at] || x>b[at]) return 0; return go(x, y, left[at]) + go(x, y, right[at]); } //add v to elements x through y void add(int x, int y, long v) { go3(x, y, v, 0); } void go3(int x, int y, long v, int at) { if(at==-1) return; if(y < a[at] || x > b[at]) return; val[at] += (Math.min(b[at], y) - Math.max(a[at], x) + 1)*v; go3(x, y, v, left[at]); go3(x, y, v, right[at]); } } static ArrayList<Integer>[] g; static boolean[] marked; static int[] id, low, stk; static int pre, count; static void scc() { id = new int[g.length]; low = new int[g.length]; stk = new int[g.length+1]; pre = count = 0; marked = new boolean[g.length]; for(int i =0; i<g.length; i++) if(!marked[i]) dfs(i); } static void dfs(int i) { marked[stk[++stk[0]]=i] = true; int min = low[i] = pre++; for(int j: g[i]) { if(!marked[j]) dfs(j); if(low[j] < min) min = low[j]; } if(min < low[i]) low[i] = min; else { while(stk[stk[0]] != i) { int j =stk[stk[0]--]; id[j] = count; low[j] = g.length; } id[stk[stk[0]--]] = count++; low[i] = g.length; } } static class input { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } static long nextLong() throws IOException { return Long.parseLong( next() ); } static String nextLine() throws IOException { return reader.readLine(); } } }
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 c { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int cur=0; for (int i=0;i<n;i++) for (int j=i+1;j<n;j++) cur++; if (cur<=k) System.out.println("no solution"); else { int x=4;int y=0; for (int i=0;i<n;i++){ System.out.println(x+" "+(y+n-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> int main() { int n, k, i; scanf("%d %d", &n, &k); if (k >= n * (n - 1) / 2) { puts("no solution"); } else { for (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
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n * (n - 1) / 2 > k) { for (int i = 0; i < n; i++) { printf("%d %d\n", 0, i); } } else { cout << "no solution"; } }
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.math.*; public class Main { static Input in; static Output out; static final boolean OJ = System.getProperty("ONLINE_JUDGE") != null; public static void main(String[] args) throws IOException { in = new Input(OJ ? System.in : new FileInputStream("in.txt")); out = new Output(OJ ? System.out : new FileOutputStream("out.txt")); solve(); out.close(); System.exit(0); } private static void solve() throws IOException { int n = in.nextInt(), k = in.nextInt(); long tot = n * (n - 1) / 2; if (tot > k) { for (int i = 0; i < n; i++) { out.printf("%d %d\n", 0, i); } } else out.println("no solution"); } } class Input { final int SIZE = 8192; //4096; 8192; 65536; InputStream in; byte[] buf = new byte[SIZE]; int last, current, total; public Input(InputStream stream) throws IOException { in = stream; last = read(); } int read() throws IOException { if (total == -1) return -1; if (current >= total) { current = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[current++]; } void advance() throws IOException { while (true) { if (last == -1) return; if (!isValidChar(last)) last = read(); else break; } } boolean isValidChar(int c) { return c > 32 && c < 127; } public boolean endOfFile() throws IOException { advance(); return last == -1; } public String nextString() throws IOException { advance(); if (last == -1) throw new EOFException(); StringBuilder s = new StringBuilder(); while (true) { s.appendCodePoint(last); last = read(); if (!isValidChar(last)) break; } return s.toString(); } public String nextLine() throws IOException { if (last == -1) throw new EOFException(); StringBuilder s = new StringBuilder(); while (true) { s.appendCodePoint(last); last = read(); if (last == '\n' || last == -1) break; } return s.toString(); } public String nextLine(boolean ignoreIfEmpty) throws IOException { if (!ignoreIfEmpty) return nextLine(); String s = nextLine(); while (s.trim().length() == 0) s = nextLine(); return s; } public int nextInt() throws IOException { advance(); if (last == -1) throw new EOFException(); int n = 0, s = 1; if (last == '-') { s = -1; last = read(); if (last == -1) throw new EOFException(); } while (true) { n = n * 10 + last - '0'; last = read(); if (!isValidChar(last)) break; } return n * s; } public long nextLong() throws IOException { advance(); if (last == -1) throw new EOFException(); int s = 1; if (last == '-') { s = -1; last = read(); if (last == -1) throw new EOFException(); } long n = 0; while (true) { n = n * 10 + last - '0'; last = read(); if (!isValidChar(last)) break; } return n * s; } public BigInteger nextBigInt() throws IOException { return new BigInteger(nextString()); } public char nextChar() throws IOException { advance(); return (char) last; } public double nextDouble() throws IOException { advance(); if (last == -1) throw new EOFException(); int s = 1; if (last == '-') { s = -1; last = read(); if (last == -1) throw new EOFException(); } double n = 0; while (true) { n = n * 10 + last - '0'; last = read(); if (!isValidChar(last) || last == '.') break; } if (last == '.') { last = read(); if (last == -1) throw new EOFException(); double m = 1; while (true) { m = m / 10; n = n + (last - '0') * m; last = read(); if (!isValidChar(last)) break; } } return n * s; } public BigDecimal nextBigDecimal() throws IOException { return new BigDecimal(nextString()); } public int[] nextIntArray(int len) throws IOException { int[] A = new int[len]; for (int i = 0; i < len; i++) A[i] = nextInt(); return A; } public long[] nextLongArray(int len) throws IOException { long[] A = new long[len]; for (int i = 0; i < len; i++) A[i] = nextLong(); return A; } public int[][] nextIntTable(int rows, int cols) throws IOException { int[][] T = new int[rows][]; for (int i = 0; i < rows; i++) T[i] = nextIntArray(cols); return T; } } class Output { final int SIZE = 4096; // 4096; 8192 Writer out; char[] cb = new char[SIZE]; int nChars = SIZE, nextChar = 0; char lineSeparator = '\n'; public Output(OutputStream stream) { out = new OutputStreamWriter(stream); } void flushBuffer() throws IOException { if (nextChar == 0) return; out.write(cb, 0, nextChar); nextChar = 0; } void write(int c) throws IOException { if (nextChar >= nChars) flushBuffer(); cb[nextChar++] = (char) c; } void write(String s, int off, int len) throws IOException { int b = off, t = off + len; while (b < t) { int a = nChars - nextChar, a1 = t - b; int d = a < a1 ? a : a1; s.getChars(b, b + d, cb, nextChar); b += d; nextChar += d; if (nextChar >= nChars) flushBuffer(); } } void write(String s) throws IOException { write(s, 0, s.length()); } public void print(Object obj) throws IOException { write(String.valueOf(obj)); } public void println(Object obj) throws IOException { write(String.valueOf(obj)); write(lineSeparator); } public void printf(String format, Object... obj) throws IOException { write(String.format(format, obj)); } public void printElements(Object... obj) throws IOException { for (int i = 0; i < obj.length; i++) { if (i > 0) print(" "); print(obj[i]); } print(lineSeparator); } public void close() throws IOException { flushBuffer(); out.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.util.*; import java.io.*; import java.math.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { long mod1 = (long) 1e9 + 7; int mod2 = 998244353; public void solve() throws Exception { long n = sc.nextLong(); long k=sc.nextLong(); long max=n*(n-1)/2l; if(k<max) { for(int i=0;i<n;i++) { out.println(0+" "+i); } } else { out.println("no solution"); } } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static long ncr(int n, int r, long p) { if (r > n) return 0l; if (r > n - r) r = n - r; long C[] = new long[r + 1]; C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = Math.min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r] % p; } void sieveOfEratosthenes(boolean prime[], int size) { for (int i = 0; i < size; i++) prime[i] = true; for (int p = 2; p * p < size; p++) { if (prime[p] == true) { for (int i = p * p; i < size; i += p) prime[i] = false; } } } static int LowerBound(int a[], int x) { // smallest index having value >= x int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int UpperBound(int a[], int x) {// biggest index having value <= x int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } public long power(long x, long y, long p) { long res = 1; // out.println(x+" "+y); x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new FastScanner(in); solve(); } catch (Throwable uncaught) { Solution.uncaught = uncaught; } finally { out.close(); } } public static void main(String[] args) throws Throwable { Thread thread = new Thread(null, new Solution(), "", (1 << 26)); thread.start(); thread.join(); if (Solution.uncaught != null) { throw Solution.uncaught; } } } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public int[] readArray(int n) throws Exception { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(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
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 C { 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