exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 9e32bc275f05cdb44a48d77e4ee38cd3 | train_001.jsonl | 1276875000 | You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.TreeSet;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Erasyl Abenov
*
*
*/
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
try (PrintWriter out = new PrintWriter(outputStream)) {
TaskB solver = new TaskB();
solver.solve(1, in, out);
}
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException{
long a = in.nextLong();
long b = in.nextLong();
long c = in.nextLong();
if(a == b && b == c && c != 0){
out.println(0.0);
}
else if(a == 0){
if(b == 0){
if(c == 0) out.println(-1);
else{
out.println(0.0);
}
}
else{
out.println(1);
out.printf("%.10f", (-1.0*c)/b);
}
}
else if(b == 0){
if(c <= 0){
out.println(1);
out.printf("%.10f", Math.sqrt((-1.0*c)/a));
}
else out.println(0);
}
else if(c == 0){
out.println(2);
double a1 = -0.00;
double a2 = (-1.0*b)/a;
out.printf("%.10f", Math.min(a1, a2));
out.println();
out.printf("%.10f", Math.max(a1, a2));
}
else{
long D = b*b*1L - 1L*4*a*c;
if(D < 0) out.println(-1);
else if(D == 0){
out.println(1);
out.printf("%.10f", (-b*1.0)/(1L*2*a));
}
else{
out.println(2);
double a1 = (-b + Math.sqrt(D))/(1L*2*a);
double a2 = (-b - Math.sqrt(D))/(1L*2*a);
out.printf("%.10f", Math.min(a1, a2));
out.println();
out.printf("%.10f", Math.max(a1, a2));
}
}
}
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public BigInteger nextBigInteger(){
return new BigInteger(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["1 -5 6"] | 1 second | ["2\n2.0000000000\n3.0000000000"] | null | Java 7 | standard input | [
"math"
] | 84372885f2263004b74ae753a2f358ac | The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0. | 2,000 | In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point. | standard output | |
PASSED | 35fe61841f16305cfa17684c3c151434 | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Diego Huerfano ( diego.link )
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, InputReader in, OutputWriter out) {
final int n=in.readInt();
final long k=in.readInt();
long a[]=in.readLongs( n );
if( k==1 ) {
out.printLine( n );
return;
}
Arrays.sort( a );
boolean ok[]=new boolean[n];
Arrays.fill( ok, true );
int div, ans=n;
for( int i=0, j=0; i<n; i++ ) {
while( j<i && a[j]*k<a[i] ) j++;
if( ok[j] && a[j]*k==a[i] ) {
ans--;
ok[i]=false;
}
}
out.printLine( ans );
}
}
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 long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long[] readLongs( int n ){
long ans[]=new long[n];
for( int i=0; i<n; i++ ) ans[i]=readLong();
return ans;
}
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 interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print( objects );
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 90b01da53ed74524a462ae7ca719e6b4 | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | //package codeforces;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
public class CodeForces {
private static MyScanner sc;
private static MyPrinter out;
private static long[] del;
private static boolean bin(int x, int a, int b) {
int now = (a + b) / 2;
if (a == b) {
if (del[a] == x) {
return (true);
} else {
return (false);
}
} else {
if (del[now] == x) {
return (true);
} else {
if (del[now] > x) {
return (bin(x, a, Math.max(a, now - 1)));
} else {
return (bin(x, Math.min(now + 1, b), b));
}
}
}
}
public static void solve() throws IOException {
//Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] m = new int[n];
del = new long[n];
for (int i = 0; i < n; i++) {
m[i] = sc.nextInt();
}
Arrays.sort(m);
int all = 1, td = 0;
del[0] = m[0] * (long) k;
for (int i = 1; i < n; i++) {
if (!bin(m[i], 0, td)) {
all++;
td++;
del[td] = k * (long) m[i];
}
}
System.out.println(all);
}
public static void main(String[] args) throws IOException {
sc = new MyScanner(System.in);
out = new MyPrinter(new File("output.txt"));
solve();
out.close();
}
}
class MyScanner {
private StreamTokenizer st;
public MyScanner(InputStream is) {
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
}
public MyScanner(File f) throws FileNotFoundException {
st = new StreamTokenizer(new BufferedReader(new FileReader(f)));
}
public int nextInt() throws IOException {
st.nextToken();
return ((int) st.nval);
}
public double nextDouble() throws IOException {
st.nextToken();
return (st.nval);
}
public String nextString() throws IOException {
st.nextToken();
if (st.ttype == StreamTokenizer.TT_WORD) {
return (st.sval);
} else {
return ("not found");
}
}
}
class MyPrinter {
private BufferedWriter out;
public MyPrinter(OutputStream os) {
out = new BufferedWriter(new PrintWriter(os));
}
public MyPrinter(File f) throws IOException {
out = new BufferedWriter(new FileWriter(f));
}
public void println(int i) throws IOException {
out.write(Integer.toString(i));
out.newLine();
}
public void println(double d) throws IOException {
out.write(Double.toString(d));
out.newLine();
}
public void println(long l) throws IOException {
out.write(Long.toString(l));
out.newLine();
}
public void println(String s) throws IOException {
out.write(s);
out.newLine();
}
public void println(char c) throws IOException {
out.write(Character.toString(c));
out.newLine();
}
public void print(int i) throws IOException {
out.write(Integer.toString(i));
}
public void print(double d) throws IOException {
out.write(Double.toString(d));
}
public void print(long l) throws IOException {
out.write(Long.toString(l));
}
public void print(String s) throws IOException {
out.write(s);
}
public void print(char c) throws IOException {
out.write(Character.toString(c));
}
public void close() throws IOException {
out.flush();
out.close();
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 2bda6b4b77903b2d279f6a3ab996084e | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
static final double eps = 1e-8;
static int mod = 1000 * 1000 * 1000 + 9;
static int n, k;
static Set<Integer> set = new TreeSet<Integer>();
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
pw = new PrintWriter(System.out);
try {
n = nextInt();
k = nextInt();
if(k == 1)
exit(n);
int[] a = new int[n];
for(int i = 0; i < n; i++)
set.add( a[i] = nextInt() );
int c = 0;
Arrays.sort(a);
for(int i = 0; i < n; i++)
{
if(set.contains(a[i]))
{
c++;
if (set.contains(a[i] * k) && ( (long) a[i] * k < mod) )
set.remove(a[i] * k);
}
}
pw.println(c);
}
finally {
pw.close();
}
}
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st ;
static PrintWriter pw;
static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
static long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
static double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
static String next() throws IOException {
in.nextToken();
return in.sval;
}
static void outArray(int[] O) {
for(int i = 0; i < O.length - 1; i++)
pw.print(O[i] + " ");
pw.println(O[O.length - 1]);
}
static void exit(Object arg)
{
pw.println(arg);
pw.flush();
System.exit(0);
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 8e1926fa4b444e9e42f14c91393b885f | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes |
import java.io.*;
import java.util.*;
//import java.math.BigInteger;
public class Main {
public static void main(String args[]) {
try {
//BufferedReader br = new BufferedReader(new FileReader(new File("input.txt")));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
if(k==1){
System.out.println(n);return;
}
String s1[] = br.readLine().split(" ");
HashSet<Double> set = new HashSet();
HashSet<Double> set1 = new HashSet();
for(int i = 0;i<n;i++){
set.add(Double.parseDouble(s1[i]));
}
int setCount = 0;
for(Iterator I = set.iterator();I.hasNext();){
double a = (Double)I.next();
if(set1.contains(a)){
continue;
}
set1.add(a);
int count = 1;
double temp = a;
//System.out.println(a);
while(set.contains(temp/k)){
set1.add(temp/k);
count++;
temp = temp/k;
}
temp = a;
while(set.contains(temp*k)){
set1.add(temp*k);
count++;
temp = temp*k;
}
//System.out.println(set1+" "+count);
if(count%2==0){
setCount += (count/2);
}
else
setCount += (count/2)+1;
}
System.out.println(setCount);
} catch (IOException | NumberFormatException e) {
}
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | c9dc1f416be6d44c6403fd72789d3f2e | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | //package Round_169;
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class c {
void solve() throws Exception {
int n = in.nextInt();
int k = in.nextInt();
long []a = in.readLongArray(n);
for (int i = 0; i<n; i++){
int j = (int)(random() * n);
long sw = a[j];
a[j] = a[i];
a[i] = sw;
}
Arrays.sort(a);
HashSet<Long> hash = new HashSet<Long>();
int lenght = 0;
for (int i = 0; i<n; i++){
if (!hash.contains(a[i])){
long t = a[i] * k;
lenght++;
hash.add(t);
}
}
out.println(lenght);
}
FastScanner in;
PrintWriter out;
String input = "";
String output = "";
void run() {
try {
if (input.length() > 0) {
in = new FastScanner(new BufferedReader(new FileReader(input)));
} else
in = new FastScanner(new BufferedReader(new InputStreamReader(
System.in)));
if (output.length() > 0)
out = new PrintWriter(new FileWriter(output));
else
out = new PrintWriter(System.out);
solve();
out.flush();
out.close();
} catch (Exception ex) {
ex.printStackTrace();
out.flush();
out.close();
} finally {
out.close();
}
}
public static void main(String[] args) {
new c().run();
}
class FastScanner {
BufferedReader bf;
StringTokenizer st;
public FastScanner(BufferedReader bf) {
this.bf = bf;
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(bf.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public String nextLine() throws IOException {
return bf.readLine();
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public int[] readIntArray(int n) throws IOException {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = this.nextInt();
return array;
}
public long[] readLongArray(int n) throws IOException {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = this.nextLong();
return array;
}
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 30783b5d911e9db5ac8650f89902078a | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Main {
//http://www.codeforces.com/contest/275/problem/C
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int num = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine(), " ");
if (k == 1) System.out.println(num);
else {
TreeSet<Long> set = new TreeSet<Long>();
TreeSet<Long> bad = new TreeSet<Long>();
long sel;
int[] arr = new int[num];
for (int i = 0; i < num; i++) {
arr[i] = Integer.parseInt((st.nextToken()));
}
shuffle(arr);
Arrays.sort(arr);
for (int i = 0; i < num; i++) {
sel = arr[i];
if (sel % k != 0) {
set.add(sel);
bad.add(sel * k);
}
if (!bad.contains(sel) && !set.contains(sel / k)) {
bad.add(sel * k);
set.add(sel);
}
}
System.out.println(set.size());
}
}
public static void shuffle(int[] arr) {
Random rand = new Random();
for (int i = arr.length - 1; i >= 0; --i) {
int pos = rand.nextInt(i + 1);
int aux = arr[i];
arr[i] = arr[pos];
arr[pos] = aux;
}
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | f7c95a46bf55d4e97fae5b9ff0f56f1f | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.util.*;
import static java.lang.System.*;
public class C275 {
Scanner sc = new Scanner(in);
public void run() {
int n=sc.nextInt();long k=sc.nextInt();
long[] a=new long[n];
boolean[] used=new boolean[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
int res=0;
Arrays.sort(a);
for(int i=0;i<n;i++){
if(!used[i]){
used[i]=true;
res++;
long val=a[i];
int ind=Arrays.binarySearch(a,val*k);
if(ind>=0){
used[ind]=true;
}
}
}
ln(res);
}
public static void main(String[] _) {
new C275().run();
}
public static void pr(Object o) {
out.print(o);
}
public static void ln(Object o) {
out.println(o);
}
public static void ln() {
out.println();
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 3179cf2c6d134bff14f6da7192e034cb | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class C {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int k = s.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = s.nextInt();
}
Arrays.sort(a);
Set<Long> set = new HashSet<Long>();
int cnt = 0;
for (int i = 0; i < n; i++) {
if (!set.contains((long) a[i])) {
cnt++;
set.add(a[i] * (long) k);
}
}
System.out.println(cnt);
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 39e906b9da38e8b96f27fa9fc4054e5e | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.Arrays;
public class C {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
long k = input.nextInt();
long[] nums = new long[n];
for (int i = 0; i < n; i++) {
nums[i] = input.nextInt();
}
Arrays.sort(nums);
Set<Long> wrong = new TreeSet<Long>();
long ans = 0;
for (int i = 0; i < n; i++) {
if (!wrong.contains(nums[i])) {
try {
wrong.add(nums[i] * k);
} catch (Exception e) {
}
ans++;
}
}
System.out.println(ans);
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 03caa9f0b5a7fbc251d131f159289e90 | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
public class B_168 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =sc.nextInt();
long a[]=new long [n+1];
long k =sc.nextInt();
HashSet<Long> set=new HashSet<Long>();
for (int i = 1; i <=n; i++) {
a[i]=sc.nextLong();
}
Arrays.sort(a,1,n+1);
int x = 0;
for (int i = 1; i <=n ; i++) {
if(!set.contains(a[i])){
set.add(k*a[i]);
x++;
}
}
System.out.println(x);
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | e19ae0baf6ddd5b1c99efbb568353392 | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.math.*;
public class Task
{
public static void main(String[] args) throws IOException
{
new Task().run();
}
StreamTokenizer in;
Scanner ins;
PrintWriter out;
int nextInt() throws IOException
{
in.nextToken();
return (int)in.nval;
}
long nextLong() throws IOException
{
in.nextToken();
return (long)in.nval;
}
char nextChar() throws IOException{
in.nextToken();
return (char)in.ttype;
}
String nextString() throws IOException{
in.nextToken();
return in.sval;
}
long gcdLight(long a, long b){
a = Math.abs(a);
b = Math.abs(b);
while(a != 0 && b != 0){
if(a > b)
a %= b;
else
b %= a;
}
return a + b;
}
ForGCD gcd(int a,int b)
{
ForGCD tmp = new ForGCD();
if(a == 0)
{
tmp.x = 0;
tmp.y = 1;
tmp.d = b;
}
else
{
ForGCD tmp1 = gcd(b%a, a);
tmp.d = tmp1.d;
tmp.y = tmp1.x;
tmp.x = tmp1.y - tmp1.x*(b/a);
}
return tmp;
}
long k;
int n;
long A[];
boolean used[];
void run() throws IOException
{
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
ins = new Scanner(System.in);
out = new PrintWriter(System.out);
try
{
if(System.getProperty("xDx")!=null)
{
in = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
ins = new Scanner(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
}
}
catch(Exception e)
{
}
n = nextInt();
k = nextLong();
A = new long[n];
used = new boolean[n];
Arrays.fill(used, false);
for(int i = 0; i < n; i++){
A[i] = nextLong();
}
Arrays.sort(A);
int sum = 0;
for(int i = 0 ; i < n; i++){
if(!used[i]){
sum++;
long tx = A[i]*k;
int next = Arrays.binarySearch(A, tx);
if(next >= 0){
used[next] = true;
}
}
}
out.print(sum);
out.close();
}
class ForGCD
{
int x,y,d;
}
class Boxes implements Comparable
{
public long k,a;
public Boxes(long k, long a){
this.k = k;
this.a = a;
}
public int compareTo(Object obj)
{
Boxes b = (Boxes) obj;
if(k < b.k)
return -1;
else
if(k == b.k)
return 0;
else
return 1;
}
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | d68ae9aad8c2a2119858b871b9afa249 | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author George Marcus
*/
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();
Integer[] A = new Integer[N];
for(int i = 0; i < N; i++)
A[i] = in.nextInt();
Arrays.sort(A);
HashSet<Integer> s = new HashSet<Integer>(N);
int ans = 0;
for(int i = 0; i < N; i++)
if(!s.contains(A[i])) {
ans++;
if((long)A[i] * K <= 1000000000)
s.add(A[i] * K);
}
out.println(ans);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
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 nextInt() {
return Integer.parseInt(nextString());
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 6d4f296b1a6917b427afea0a6fbd2eea | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.util.List;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author George Marcus
*/
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();
Integer[] A = new Integer[N];
for(int i = 0; i < N; i++)
A[i] = in.nextInt();
if(N != 100000 || K != 999999999)
Arrays.sort(A);
HashSet<Integer> s = new HashSet<Integer>(N);
int ans = 0;
for(int i = 0; i < N; i++)
if(A[i] % K != 0 || !s.contains(A[i] / K)) {
s.add(A[i]);
ans++;
}
out.println(ans);*/
Set<Long> vals = new HashSet<Long>();
List<Long> as = new ArrayList<Long>();
int n = in.nextInt();
long k = in.nextLong();
for (int i = 0; i < n; i++) {
as.add(in.nextLong());
}
Collections.sort(as);
int cnt = 0;
for (int i = 0; i < as.size(); i++) {
Long next = as.get(i);
if(vals.contains(next)){
continue;
}
cnt ++;
vals.add(next* k);
}
out.println(cnt);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
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 nextInt() {
return Integer.parseInt(nextString());
}
public long nextLong() {
return Long.parseLong(nextString());
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 94b53c43e11f4b7f7f250551130690be | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.util.List;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Collections;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author George Marcus
*/
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();
Integer[] A = new Integer[N];
for(int i = 0; i < N; i++)
A[i] = in.nextInt();
if(N != 100000 || K != 999999999)
Arrays.sort(A);
HashSet<Integer> s = new HashSet<Integer>(N);
int ans = 0;
for(int i = 0; i < N; i++)
if(A[i] % K != 0 || !s.contains(A[i] / K)) {
s.add(A[i]);
ans++;
}
out.println(ans);*/
HashSet<Integer> vals = new HashSet<Integer>();
ArrayList<Integer> as = new ArrayList<Integer>();
int n = in.nextInt();
int k = in.nextInt();
for (int i = 0; i < n; i++) {
as.add(in.nextInt());
}
Collections.sort(as);
int cnt = 0;
for (int i = 0; i < as.size(); i++) {
int next = as.get(i);
if(vals.contains(next)){
continue;
}
cnt ++;
if((long)next * k <= 1000000000)
vals.add(next* k);
}
out.println(cnt);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
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 nextInt() {
return Integer.parseInt(nextString());
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 2a88c429a4b08f6cd3828134f570e45f | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author George Marcus
*/
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[] A = new int[N];
for(int i = 0; i < N; i++)
A[i] = in.nextInt();
Arrays.sort(A);
HashSet<Integer> s = new HashSet<Integer>();
int ans = 0;
for(int i = 0; i < N; i++)
if(A[i] % K != 0 || !s.contains(A[i] / K)) {
s.add(A[i]);
ans++;
}
out.println(ans);*/
int n = in.nextInt();
long k = in.nextInt();
if (k == 1) {
out.println(n);
return;
}
long[] a = new long[n];
for (int i = 0; i < n; ++i) {
a[i] = in.nextInt();
}
Arrays.sort(a);
boolean[] bad = new boolean[n];
int ans = 0;
for (int i = 0; i < n; ++i) {
if (bad[i]) {
continue;
}
++ans;
long t = a[i] * k;
int j = Arrays.binarySearch(a, t);
if (j >= 0) {
bad[j] = true;
}
}
out.println(ans);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
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 nextInt() {
return Integer.parseInt(nextString());
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 0ab04b5038d286af67eae0bc19caa74a | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/**
* @author Ivan Pryvalov (ivan.pryvalov@gmail.com)
*/
public class Codeforces_R168_Div2_C implements Runnable{
boolean debug = false;
private void solve() throws IOException {
int n;
int k;
int[] a;
if (!debug){
n = scanner.nextInt(); //10^5
k = scanner.nextInt(); //10^9
a = scanner.loadIntArray(n);
}else{
n = 100000;
k = 999999999;
a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = i+5;
}
}
Arrays.sort(a);
Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
for(int x : a){
if (x % k == 0){
int parent = x / k;
if (map.containsKey(parent)){
int cnt = map.remove(parent);
map.put(x, cnt+1);
}else{
map.put(x, 1);
}
}else{
map.put(x, 1);
}
}
int res = 0;
for(int cnt : map.values()){
res += (cnt + 1)/2;
}
out.println(res);
}
/////////////////////////////////////////////////
final int BUF_SIZE = 1024 * 1024 * 8;//important to read long-string tokens properly
final int INPUT_BUFFER_SIZE = 1024 * 1024 * 8 ;
final int BUF_SIZE_INPUT = 1024;
final int BUF_SIZE_OUT = 1024;
boolean inputFromFile = false;
String filenamePrefix = "A-small-attempt0";
String inSuffix = ".in";
String outSuffix = ".out";
PrintStream out;
ByteScanner scanner;
ByteWriter writer;
public void run() {
try{
InputStream bis = null;
OutputStream bos = null;
//PrintStream out = null;
if (inputFromFile){
File baseFile = new File(getClass().getResource("/").getFile());
bis = new BufferedInputStream(
new FileInputStream(new File(
baseFile, filenamePrefix+inSuffix)),
INPUT_BUFFER_SIZE);
bos = new BufferedOutputStream(
new FileOutputStream(
new File(baseFile, filenamePrefix+outSuffix)));
out = new PrintStream(bos);
}else{
bis = new BufferedInputStream(System.in, INPUT_BUFFER_SIZE);
bos = new BufferedOutputStream(System.out);
out = new PrintStream(bos);
}
scanner = new ByteScanner(bis, BUF_SIZE_INPUT, BUF_SIZE);
writer = new ByteWriter(bos, BUF_SIZE_OUT);
solve();
out.flush();
}catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public interface Constants{
final static byte ZERO = '0';//48 or 0x30
final static byte NINE = '9';
final static byte SPACEBAR = ' '; //32 or 0x20
final static byte MINUS = '-'; //45 or 0x2d
final static char FLOAT_POINT = '.';
}
public static class EofException extends IOException{
}
public static class ByteWriter implements Constants {
int bufSize = 1024;
byte[] byteBuf = new byte[bufSize];
OutputStream os;
public ByteWriter(OutputStream os, int bufSize){
this.os = os;
this.bufSize = bufSize;
}
public void writeInt(int num) throws IOException{
int byteWriteOffset = byteBuf.length;
if (num==0){
byteBuf[--byteWriteOffset] = ZERO;
}else{
int numAbs = Math.abs(num);
while (numAbs>0){
byteBuf[--byteWriteOffset] = (byte)((numAbs % 10) + ZERO);
numAbs /= 10;
}
if (num<0)
byteBuf[--byteWriteOffset] = MINUS;
}
os.write(byteBuf, byteWriteOffset, byteBuf.length - byteWriteOffset);
}
/**
* Please ensure ar.length <= byteBuf.length!
*
* @param ar
* @throws IOException
*/
public void writeByteAr(byte[] ar) throws IOException{
for (int i = 0; i < ar.length; i++) {
byteBuf[i] = ar[i];
}
os.write(byteBuf,0,ar.length);
}
public void writeSpaceBar() throws IOException{
byteBuf[0] = SPACEBAR;
os.write(byteBuf,0,1);
}
}
public static class ByteScanner implements Constants{
InputStream is;
public ByteScanner(InputStream is, int bufSizeInput, int bufSize){
this.is = is;
this.bufSizeInput = bufSizeInput;
this.bufSize = bufSize;
byteBufInput = new byte[this.bufSizeInput];
byteBuf = new byte[this.bufSize];
}
public ByteScanner(byte[] data){
byteBufInput = data;
bufSizeInput = data.length;
bufSize = data.length;
byteBuf = new byte[bufSize];
byteRead = data.length;
bytePos = 0;
}
private int bufSizeInput;
private int bufSize;
byte[] byteBufInput;
byte by=-1;
int byteRead=-1;
int bytePos=-1;
byte[] byteBuf;
int totalBytes;
boolean eofMet = false;
private byte nextByte() throws IOException{
if (bytePos<0 || bytePos>=byteRead){
byteRead = is==null? -1: is.read(byteBufInput);
bytePos=0;
if (byteRead<0){
byteBufInput[bytePos]=-1;//!!!
if (eofMet)
throw new EofException();
eofMet = true;
}
}
return byteBufInput[bytePos++];
}
/**
* Returns next meaningful character as a byte.<br>
*
* @return
* @throws IOException
*/
public byte nextChar() throws IOException{
while ((by=nextByte())<=0x20);
return by;
}
/**
* Returns next meaningful character OR space as a byte.<br>
*
* @return
* @throws IOException
*/
public byte nextCharOrSpacebar() throws IOException{
while ((by=nextByte())<0x20);
return by;
}
/**
* Reads line.
*
* @return
* @throws IOException
*/
public String nextLine() throws IOException {
readToken((byte)0x20);
return new String(byteBuf,0,totalBytes);
}
public byte[] nextLineAsArray() throws IOException {
readToken((byte)0x20);
byte[] out = new byte[totalBytes];
System.arraycopy(byteBuf, 0, out, 0, totalBytes);
return out;
}
/**
* Reads token. Spacebar is separator char.
*
* @return
* @throws IOException
*/
public String nextToken() throws IOException {
readToken((byte)0x21);
return new String(byteBuf,0,totalBytes);
}
/**
* Spacebar is included as separator char
*
* @throws IOException
*/
private void readToken() throws IOException {
readToken((byte)0x21);
}
private void readToken(byte acceptFrom) throws IOException {
totalBytes = 0;
while ((by=nextByte())<acceptFrom);
byteBuf[totalBytes++] = by;
while ((by=nextByte())>=acceptFrom){
byteBuf[totalBytes++] = by;
}
}
public int nextInt() throws IOException{
readToken();
int num=0, i=0;
boolean sign=false;
if (byteBuf[i]==MINUS){
sign = true;
i++;
}
for (; i<totalBytes; i++){
num*=10;
num+=byteBuf[i]-ZERO;
}
return sign?-num:num;
}
public long nextLong() throws IOException{
readToken();
long num=0;
int i=0;
boolean sign=false;
if (byteBuf[i]==MINUS){
sign = true;
i++;
}
for (; i<totalBytes; i++){
num*=10;
num+=byteBuf[i]-ZERO;
}
return sign?-num:num;
}
/*
//TODO test Unix/Windows formats
public void toNextLine() throws IOException{
while ((ch=nextChar())!='\n');
}
*/
public double nextDouble() throws IOException{
readToken();
char[] token = new char[totalBytes];
for (int i = 0; i < totalBytes; i++) {
token[i] = (char)byteBuf[i];
}
return Double.parseDouble(new String(token));
}
public int[] loadIntArray(int size) throws IOException{
int[] a = new int[size];
for (int i = 0; i < a.length; i++) {
a[i] = nextInt();
}
return a;
}
public long[] loadLongArray(int size) throws IOException{
long[] a = new long[size];
for (int i = 0; i < a.length; i++) {
a[i] = nextLong();
}
return a;
}
}
public static abstract class Timing{
private static int counter = 0;
protected String name = "Timing"+(++counter);
private boolean debug;
public Timing(boolean debug) {
super();
this.debug = debug;
}
public abstract void run();
public void start(){
long time1 = System.currentTimeMillis();
run();
long time2 = System.currentTimeMillis();
if (debug)
System.out.println(name+" time = "+(time2-time1)/1000.0+" ms.");
}
}
public static class Alg{
public static interface BooleanChecker{
public boolean check(long arg);
}
public static class BinarySearch{
/**
* This check returns boolean value, result of function.
* It should be monotonic.
*
* @return
*/
public BooleanChecker bc;
/**
* Returns following element: <pre> 0 0 [1] 1 1</pre>
*/
public long search(long left, long right){
while (left<=right){
long mid = (left+right)/2;
if (bc.check(mid)){
right = mid-1;
}else{
left = mid+1;
}
}
return left;
}
/**
* Optional.<br>
* Returns following element: <pre> 1 1 [1] 0 0</pre>
*/
public long searchInverted(long left, long right){
while (left<=right){
long mid = (left+right)/2;
if (!bc.check(mid)){
right = mid-1;
}else{
left = mid+1;
}
}
return left - 1;
}
}
}
public static class Modulo{
long mod = (long)1e9+7;
public Modulo(long mod) {
super();
this.mod = mod;
}
public long inv(int a) {
long res = pow(a, mod-2);
return res;
}
public long pow(long a, long x) {
if (x==0)
return 1;
long part = 1;
if ((x&1)!=0)
part = a;
return (part * pow((a*a)%mod, x>>1)) % mod;
}
}
public static void main(String[] args) {
new Codeforces_R168_Div2_C().run();
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 754de29ceb794ab0724918e87f11fe3b | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes |
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;
public class C {
int[] a;
void run() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();int k = sc.nextInt();
a = new int[n];
boolean[] used = new boolean[n];
for(int i=0;i<n;i++) a[i] = Integer.parseInt(sc.next());
sort(a);
int cnt = 0;
for(int i=n-1;i>=0;i--) if(!used[i]){
if( a[i]%k == 0) {
int p = binSearch(a[i]/k);
if( p >= 0 ) {
used[p] = true;
}
}
cnt++;
}
System.out.println(cnt);
}
int binSearch(int v) {
int l = 0, r = a.length, c = 0;
while(l<r) {
c = (l+r) / 2;
if( a[c] == v ) return c;
if( a[c] < v ) l = c+1;
if( a[c] > v ) r = c;
}
return -1;
}
void debug(Object... os) {
System.err.println(Arrays.deepToString(os));
}
public static void main(String[] args) {
new C().run();
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | ed38e7ab03f9f07417b0a6f11b25911f | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes |
import java.util.*;
/**
*
* @author ADMIND
*/
public class Codeforce {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
int k=cin.nextInt();
int a[]=new int [n];
boolean f[]=new boolean[n];
int j=-1;
for(int i=0;i<n;i++) a[i]=cin.nextInt();
Arrays.sort(a);
int res=0;
for(int i=0;i<n;i++)
{
while (j+1<n && (long)(a[j+1])*k<=a[i]) j++;
if (j==-1 || f[j]==false || (long)a[j]*k!=a[i])
{
res++;
f[i]=true;
}
}
System.out.print(res);
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 406e59fca4c2cfc9c96696a228f79209 | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
void run() throws IOException {
int n = ni();
long k = ni();
TreeSet<Long> a = new TreeSet<Long>();
TreeSet<Long> b = new TreeSet<Long>();
int s = 0;
for (int i = 0; i < n; i++) {
a.add((long) ni());
}
b.addAll(a);
for (int i = 0; i < n; i++) {
long d = a.pollFirst();
if (b.contains(d)) {
b.remove(d * k);
s++;
}
}
pw.println(s);
}
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 | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 15524ee59d72a0346132abe2f0efbdd5 | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.System.*;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(in);
int n = sc.nextInt();
long k = sc.nextLong();
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLong();
}
Arrays.sort(arr);
HashSet<Long> set = new HashSet<Long>();
for (int i = 0; i < arr.length; i++) {
if (!set.contains(arr[i])) {
set.add(arr[i]*k);
}
}
out.println(set.size());
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 613632d638dcb8c753336c3e680296da | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class C {
public static void main(String[] args) {
FastScanner in = new FastScanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
Set<Long> us = new TreeSet<Long>();
long[] ar = new long[n];
for (int i = 0; i < n; i++) {
ar[i] = in.nextInt();
}
if (k == 1) {
System.out.println(n);
} else {
Arrays.sort(ar);
int ans = 0;
for (int i = 0; i < n; i++) {
if (!us.contains(ar[i])) {
ans++;
us.add(ar[i] * k);
}
}
System.out.println(ans);
}
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
}
| Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 6d29697fdcb0a2060cd994aab077500d | train_001.jsonl | 1361374200 | A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset. | 256 megabytes | import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main
{
/********************************************** a list of common variables **********************************************/
private MyScanner scan = new MyScanner();
private PrintWriter out = new PrintWriter(System.out);
private final double PI = Math.acos(-1.0);
private final int SIZEN = (int)(1e5);
private final long MOD = (int)(1e9 + 7);
private final long MODH = 10000000007L, BASE = 10007;
private final int[] DX = {0, 1, 0, -1}, DY = {-1, 0, 1, 0};
private ArrayList<Integer>[] edge;
public void foo()
{
int n = scan.nextInt();
int k = scan.nextInt();
TreeSet<Long> ts = new TreeSet<Long>();
for(int i = 0;i < n;++i)
{
ts.add(scan.nextLong());
}
int ans = 0;
while(!ts.isEmpty())
{
long x = ts.first();
int cnt = 0;
while(ts.contains(x))
{
ts.remove(x);
x *= k;
++cnt;
}
ans += (cnt + 1) / 2;
}
out.println(ans);
}
public static void main(String[] args)
{
Main m = new Main();
m.foo();
m.out.close();
}
/********************************************** a list of common algorithms **********************************************/
/**
* 1---Get greatest common divisor
* @param a : first number
* @param b : second number
* @return greatest common divisor
*/
public long gcd(long a, long b)
{
return 0 == b ? a : gcd(b, a % b);
}
/**
* 2---Get the distance from a point to a line
* @param x1 the x coordinate of one endpoint of the line
* @param y1 the y coordinate of one endpoint of the line
* @param x2 the x coordinate of the other endpoint of the line
* @param y2 the y coordinate of the other endpoint of the line
* @param x the x coordinate of the point
* @param y the x coordinate of the point
* @return the distance from a point to a line
*/
public double getDist(long x1, long y1, long x2, long y2, long x, long y)
{
long a = y2 - y1;
long b = x1 - x2;
long c = y1 * (x2 - x1) - x1 * (y2 - y1);
return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
}
/**
* 3---Get the distance from one point to a segment (not a line)
* @param x1 the x coordinate of one endpoint of the segment
* @param y1 the y coordinate of one endpoint of the segment
* @param x2 the x coordinate of the other endpoint of the segment
* @param y2 the y coordinate of the other endpoint of the segment
* @param x the x coordinate of the point
* @param y the y coordinate of the point
* @return the distance from one point to a segment (not a line)
*/
public double ptToSeg(long x1, long y1, long x2, long y2, long x, long y)
{
double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
if(cross <= 0)
{
return (x - x1) * (x - x1) + (y - y1) * (y - y1);
}
double d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
if(cross >= d)
{
return (x - x2) * (x - x2) + (y - y2) * (y - y2);
}
double r = cross / d;
double px = x1 + (x2 - x1) * r;
double py = y1 + (y2 - y1) * r;
return (x - px) * (x - px) + (y - py) * (y - py);
}
/**
* 4---KMP match, i.e. kmpMatch("abcd", "bcd") = 1, kmpMatch("abcd", "bfcd") = -1.
* @param t: String to match.
* @param p: String to be matched.
* @return if can match, first index; otherwise -1.
*/
public int kmpMatch(char[] t, char[] p)
{
int n = t.length;
int m = p.length;
int[] next = new int[m + 1];
next[0] = -1;
int j = -1;
for(int i = 1;i < m;++i)
{
while(j >= 0 && p[i] != p[j + 1])
{
j = next[j];
}
if(p[i] == p[j + 1])
{
++j;
}
next[i] = j;
}
j = -1;
for(int i = 0;i < n;++i)
{
while(j >= 0 && t[i] != p[j + 1])
{
j = next[j];
}
if(t[i] == p[j + 1])
{
++j;
}
if(j == m - 1)
{
return i - m + 1;
}
}
return -1;
}
/**
* 5---Get the hash code of a String
* @param s: input string
* @return hash code
*/
public long hash(String s)
{
long key = 0, t = 1;
for(int i = 0;i < s.length();++i)
{
key = (key + s.charAt(i) * t) % MODH;
t = t * BASE % MODH;
}
return key;
}
/**
* 6---Get x ^ n % MOD quickly.
* @param x: base
* @param n: times
* @return x ^ n % MOD
*/
public long quickMod(long x, long n)
{
long ans = 1;
while(n > 0)
{
if(1 == n % 2)
{
ans = ans * x % MOD;
}
x = x * x % MOD;
n >>= 1;
}
return ans;
}
class MyScanner
{
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
BufferedInputStream bis = new BufferedInputStream(System.in);
public int read()
{
if (-1 == numChars)
{
throw new InputMismatchException();
}
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = bis.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
{
return -1;
}
}
return buf[curChar++];
}
public int nextInt()
{
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 long nextLong()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
{
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
{
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9')
{
throw new InputMismatchException();
}
res *= 10;
res += c & 15;
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
{
return res * Math.pow(10, nextInt());
}
if (c < '0' || c > '9')
{
throw new InputMismatchException();
}
m /= 10;
res += (c & 15) * m;
c = read();
}
}
return res * sgn;
}
public String next()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c)
{
return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
}
}
} | Java | ["6 2\n2 3 6 5 4 10"] | 2 seconds | ["3"] | NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | Java 7 | standard input | [
"binary search",
"sortings",
"greedy"
] | 4ea1de740aa131cae632c612e1d582ed | The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces. | 1,500 | On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}. | standard output | |
PASSED | 5d0895844574066489e445a023db6f70 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | //https://codeforces.com/contest/1291/problem/B
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t;
t= sc.nextInt();
while (t-->0){
int n = sc.nextInt();
int[] a= new int[n];
for (int i =0 ;i<n;i++) a[i]= sc.nextInt();
int pe=-1,se=n;
for (int i = 0; i < n; ++i) {
if (a[i] < i) break;
pe = i;
}
for (int i = n-1; i >= 0; --i) {
if (a[i] < (n-1)-i) break;
se = i;
}
if (se <= pe)
System.out.println("Yes");
else System.out.println("No");
}
}
public static boolean checkForArray(int[] a){
int len = a.length,i=0;
while (i<(len-1)){
if (a[i]==a[i+1]) return false;
i++;
}
return true;
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 7e6eab364deb01475406f8ba4b29c89d | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | //https://codeforces.com/contest/1291/problem/B
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t;
t= sc.nextInt();
while (t-->0){
int n = sc.nextInt();
int[] a= new int[n];
for (int i =0 ;i<n;i++) a[i]= sc.nextInt();
int pe=-1,se=n;
for (int i = 0; i < n; ++i) {
if (a[i] < i) break;
pe = i;
}
for (int i = n-1; i >= 0; --i) {
if (a[i] < (n-1)-i) break;
se = i;
}
if (se <= pe)
System.out.println("Yes");
else System.out.println("No");
}
}
public static boolean checkForArray(int[] a){
int len = a.length,i=0;
while (i<(len-1)){
if (a[i]==a[i+1]) return false;
i++;
}
return true;
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 64a4a310ea872940da9d0e6f46ec8f2a | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ArraySharp {
public static void main(String[] args) throws IOException {
int t;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
t = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
int[] a = new int[n];
String[] s = br.readLine().split(" ");
for (int i=0; i<n; i++) a[i] = Integer.parseInt(s[i]);
String ans = solve(a, n);
sb.append(ans + "\n");
}
System.out.print(sb);
}
private static String solve(int[] a, int n) {
if (n == 1) return "Yes";
int i = 0;
for (; i<n; i++) {
if (i > a[i]) {
break;
}
}
if (i != n) {
int t = i;
//System.out.println("i = " + i + "; " + a[i-1]);
if (a[i-1] == i - 1 && i - 1 == n - 1 - i) return "No";
for (; t < n; t++) {
if (a[t] < n-1 - t) return "No";
}
}
return "Yes";
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 04a7194c4ba42fc750ef1d4eaa02ea3a | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class Solve {
FastScanner in;
PrintWriter out;
void solve() {
int T = in.nextInt();
t:
while (0 < T--) {
int n = in.nextInt();
int[] a = in.nextIntArray(n);
if (n == 1 ) {
out.println("Yes");
} else {
int i = 0;
for (i = 0; i < n; i++) {
if (a[i] < i) {
// i--;
break;
}
}
int j = i-1;
for (j = i-1; j < n; j++) {
if (a[j] < n-(j+1)) {
// j++;
out.println("No");
continue t;
}
}
out.println("Yes");
// out.println(i + " " + j);
// out.println((i == n || j == -1 || j <= i) ? "Yes" : "No");
// 3 4 5
// *
// * *
// 0 0
// Yes
// i j
// 2 1
}
// out.println();
}
}
void run() {
try {
in = new FastScanner(new File("Solve.in"));
out = new PrintWriter(new File("Solve.out"));
solve();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
return a;
}
BigInteger nextBigInteger() {
return new BigInteger(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextDouble();
}
return a;
}
}
public static void main(String[] args) {
new Solve().runIO();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | d4b3ab304d2631a3c8cf907403f31a45 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class Solve {
FastScanner in;
PrintWriter out;
void solve() {
int T = in.nextInt();
t:
while (0 < T--) {
int n = in.nextInt();
int[] a = in.nextIntArray(n);
int i = 0;
for (i = 0; i < n; i++) {
if (a[i] < i) {
break;
}
}
i--;
int j = i;
for (j = i; j < n; j++) {
if (a[j] < n-(j+1)) {
out.println("No");
continue t;
}
}
// out.println((j+1) + " " + n);
out.println("Yes");
// 0 1 2 3 4 5
// 3 2 1 0
}
}
void run() {
try {
in = new FastScanner(new File("Solve.in"));
out = new PrintWriter(new File("Solve.out"));
solve();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
return a;
}
BigInteger nextBigInteger() {
return new BigInteger(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextDouble();
}
return a;
}
}
public static void main(String[] args) {
new Solve().runIO();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 648cfe380eedde0de461903467d31194 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class Solve {
FastScanner in;
PrintWriter out;
void solve() {
int T = in.nextInt();
t:
while (0 < T--) {
int n = in.nextInt();
int[] a = in.nextIntArray(n);
// out.println(Arrays.toString(a));
int i = 0;
while (i < n && i <= a[i]) {
i++;
}
i--;
int j = n-1;
while (0 <= j && (n-1-j) <= a[j]) {
j--;
}
j++;
// out.println(i + " " + j);
out.println((j <= i) ? "Yes" : "No");
}
}
void run() {
try {
in = new FastScanner(new File("Solve.in"));
out = new PrintWriter(new File("Solve.out"));
solve();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
return a;
}
BigInteger nextBigInteger() {
return new BigInteger(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextDouble();
}
return a;
}
}
public static void main(String[] args) {
new Solve().runIO();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | e57c58c9c117e426bc57009497671e57 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
public class gym {
static class FenwickTree {
int[] ft;
FenwickTree(int n) {
ft = new int[n + 1];
}
void update(int idx, int val) {
while (idx < ft.length) {
ft[idx] += val;
idx += idx & -idx;
}
}
int query(int idx) {
int s = 0;
while (idx > 0) {
s += ft[idx];
idx ^= idx & -idx;
}
return s;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int min = -1;
int a[] = new int[n];
boolean f = true;
boolean q = false;
int j=0;
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(st.nextToken());
}
int x=0;
for (int i = 0; i < a.length; i++) {
if (a[i] > min ) {
min++;
x=i;
} else {
j=i;
break;
}
}
if(j==0)
j++;
min = a[j-1];
f = true;
for (int i = j; i < a.length; i++) {
if(a[i]>=min) {
min--;
}
else
min=a[i];
if (min == -1 ) {
f = false;
break;
}
}
pw.println(!f&&(x!=n-1) ? "No" : "Yes");
}
pw.flush();
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | adb1bafaffce035578f1cea3af09eaf0 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args) {
new Thread(null, new Runnable() {
public void run() {
solve();
}
}, "1", 1 << 26).start();
}
static void solve () {
FastReader fr =new FastReader(); PrintWriter op =new PrintWriter(System.out);
int t =fr.nextInt() ,n ,i ,a[] ; boolean f[][] ;
while (t-- > 0) {
n =fr.nextInt() ; a =new int[n] ; f =new boolean[2][n] ;
for (i =0 ; i<n ; ++i) a[i] =fr.nextInt() ; f[0][0] =f[1][n-1] =true ;
for (i =1 ; i<n ; ++i) {
if (a[i]>=i && f[0][i-1]) f[0][i] =true ; else f[0][i] =false ;
}
for (i =n-2 ; i>-1 ; --i) {
if (a[i]>=(n-1-i) && f[1][i+1]) f[1][i] =true ; else f[1][i] =false ;
}
for (i =0 ; i<n ; ++i) if (f[0][i] && f[1][i]) break;
if (i==n) op.println("No") ; else op.println("Yes") ;
}
op.flush(); op.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br =new BufferedReader(new InputStreamReader(System.in));
}
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;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next()) ;
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 677db7a9254142dc3359f304a34a09b8 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.*;
public class B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int u = 0; u < t; u++) {
int n = in.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt() + 1;
}
int leftMax = -1;
int rightMax = n;
for (int i = 0; i < n && a[i] > i; i++) {
leftMax = i;
}
for (int i = n - 1; i >= 0 && a[i] > n - 1 - i; i--) {
rightMax = i;
}
if (rightMax <= leftMax)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 44820de8dc98bcaa954424d3c90c1571 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class spoj {
InputStream is;
PrintWriter out;
void solve()
{
int t=ni();
while(t-->0)
{
int n=ni();
int a[]=na(n);
int dumm[]=new int[n];
int si=-1,sd=-1;
for(int i=0;i<n-1;i++)
{
if(a[i]<=a[i+1])
{
si=i;
break;
}
}
for(int i=0;i<n-1;i++)
{
if(a[i]>=a[i+1])
{
sd=i;
break;
}
}
if(si==-1 || sd==-1){
out.println("Yes");continue;}
int nf=0;
for(int i=0;i<n/2;i++)
{
if(a[i]>=i && a[n-1-i]>=i)
{
dumm[i]=i;
dumm[n-i-1]=i;
}
else
{
nf=-1;
}
}
if(n%2==0)
{
if(dumm[n/2]+1<=a[n/2] || dumm[(n/2)-1]+1<=a[(n/2)-1])
{
}
else
{
nf=-1;
}
}
if(n%2!=0)
{
if(dumm[(n/2)-1]+1<=a[n/2])
{}
else
nf=-1;
}
if(nf==0)
out.println("Yes");
else
out.println("No");
}
}
//---------- I/O Template ----------
public static void main(String[] args) { new spoj().run(); }
void run() {
is = System.in;
out = new PrintWriter(System.out);
solve();
out.flush();
}
byte input[] = new byte[1024];
int len = 0, ptr = 0;
int readByte() {
if(ptr >= len) { ptr = 0;
try { len = is.read(input); }
catch(IOException e) { throw new InputMismatchException(); }
if(len <= 0) { return -1; }
} return input[ptr++];
}
boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
int skip() {
int b = readByte();
while(b != -1 && isSpaceChar(b)) { b = readByte(); }
return b;
}
char nc() { return (char)skip(); }
String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
return sb.toString();
}
String nLine() {
int b = skip();
StringBuilder sb = new StringBuilder();
while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
return sb.toString();
}
int ni() {
int n = 0, b = readByte();
boolean minus = false;
while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
if(b == '-') { minus = true; b = readByte(); }
if(b == -1) { return -1; } //no input
while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
return minus ? -n : n;
}
long nl() {
long n = 0L; int b = readByte();
boolean minus = false;
while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
if(b == '-') { minus = true; b = readByte(); }
while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
return minus ? -n : n;
}
double nd() { return Double.parseDouble(ns()); }
float nf() { return Float.parseFloat(ns()); }
int[] na(int n) {
int a[] = new int[n];
for(int i = 0; i < n; i++) { a[i] = ni(); }
return a;
}
char[] ns(int n) {
char c[] = new char[n];
int i, b = skip();
for(i = 0; i < n; i++) {
if(isSpaceChar(b)) { break; }
c[i] = (char)b; b = readByte();
} return i == n ? c : Arrays.copyOf(c,i);
}
void pa(int a[])
{
for(int i=0;i<a.length;i++)
out.print(a[i]+" ");
out.println();
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | bd9eaa73d13df31ee86e9af5000118f0 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.*;
import java.io.*;
public class P1291B {
private static void solve() {
int tests = nextInt();
while (tests-- != 0) {
int n = nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
int first = 0;
for (int i = 0; i < n; i++) {
if (a[i] >= i) {
first = i;
} else {
break;
}
}
int last = 0;
for (int i = n - 1; i >= 0; i--) {
if (a[i] >= n - 1 - i) {
last = i;
} else {
break;
}
}
out.println(last <= first ? "Yes" : "No");
}
}
private static void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
private static StringTokenizer st;
private static BufferedReader br;
private static PrintWriter out;
private static String next() {
while (st == null || !st.hasMoreElements()) {
String s;
try {
s = br.readLine();
} catch (IOException e) {
return null;
}
st = new StringTokenizer(s);
}
return st.nextToken();
}
private static int nextInt() {
return Integer.parseInt(next());
}
private static long nextLong() {
return Long.parseLong(next());
}
public static void main(String[] args) {
run();
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | e545ddd91c918c26790de3e163a0b24b | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(new BufferedInputStream(System.in));
int v=sc.nextInt();
while(v-->0){
int a=sc.nextInt();
int b[]=new int[a];
int c[]=new int[a];
for(int i=0;i<a;i++){
b[i]=sc.nextInt();
if(i<a/2)
c[i]=i;
else
c[i]=a-i-1;
}
if(a%2==1){
int flag=0;
for(int i=0;i<a;i++){
if(c[i]>b[i])
flag++;
}
if(flag==0)
System.out.println("Yes");
else
System.out.println("No");
}else{
int flag1=0;
int flag2=0;
c[a/2-1]++;
for(int i=0;i<a;i++){
if(c[i]>b[i])
flag1++;
}
c[a/2-1]--;
c[a/2]++;
for(int i=0;i<a;i++){
if(c[i]>b[i])
flag2++;
}
if(flag2==0||flag1==0)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | be334550de1dfbc09ade0d05fcfd0ba3 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(new BufferedInputStream(System.in));
int v=sc.nextInt();
while(v-->0){
int a=sc.nextInt();
int b[]=new int[a];
if(a%2==0) {
for (int i = 0; i < a / 2-1; i++) {
b[i] = sc.nextInt();
if (b[i] >= i)
b[i] = i;
}
b[a/2-1]=sc.nextInt();
b[a/2]=sc.nextInt();
for (int i = a / 2 + 1; i < a; i++) {
b[i] = sc.nextInt();
if (b[i] >= a - 1 - i)
b[i] = a - 1 - i;
}
}else {
for (int i = 0; i < a / 2; i++) {
b[i] = sc.nextInt();
if (b[i] >= i)
b[i] = i;
}
for (int i = a / 2; i < a; i++) {
b[i] = sc.nextInt();
if (b[i] >= a - 1 - i)
b[i] = a - 1 - i;
}
}
int flag1=0;
int count=0;
if(a==1)
System.out.println("Yes");
else if(a==2){
if(b[0]==0&&b[1]==0)
System.out.println("No");
else
System.out.println("Yes");
}
else {
if(a%2==0&&b[a/2]==b[a/2-1]) {
if (b[a / 2 - 1] > b[a / 2 - 2])
b[a / 2 - 1] = b[a / 2 - 2] + 1;
else {
if (b[a / 2] > b[a / 2 + 1])
b[a / 2] = b[a / 2 + 1] + 1;
}
}
/*for(int i=0;i<a;i++)
System.out.print(b[i]+" ");
System.out.println();*/
for (int i = 1; i < a; i++) {
if (flag1 == 0) {
if (b[i] <= b[i - 1]) {
flag1 = 1;
i--;
}
else
count++;
} else {
if(b[i]<b[i-1])
count++;
}
}
//System.out.println(count);
if(count==a-1)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 677ec03af588570e4d8446fe1b84b805 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import javax.print.attribute.standard.PrintQuality;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
public class Main {
static int mod = (int) 1e9 + 7;
public static void main(String[] args) {
FastReader sc = new FastReader();
int t=sc.nextInt();
StringBuilder sb=new StringBuilder();
while (t-->0) {
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)arr[i]=sc.nextInt();
if(n==2){
if(arr[0]==0 && arr[1]==0)sb.append("NO\n");
else sb.append("YES\n");
continue;
}
arr[0]=0;
arr[n-1]=0;
boolean z=false;
for(int i=1;i<n-1;i++){
if(arr[i]==0){
z=true;
break;
}
}
if(z){
sb.append("NO\n");
continue;
}
int i=1,j=n-2,count=1;
while(i<=j){
if(arr[i]>=count);
else{
z=true;
break;
}
i++;
if(arr[j]>=count);
else{
z=true;
break;
}
j--;
count++;
}
if(n%2==0){
i--;j++;count--;
if(arr[i]==arr[j]){
if(arr[i]==count && arr[j]==count)z=true;
}
}
if(z)sb.append("NO\n");
else sb.append("YES\n");
}
System.out.println(sb);
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 9dcf53c79c26522d061ebdac35096d36 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
public class ArraySharpening {
private static StreamTokenizer st;
private static int nextInt() throws IOException{
st.nextToken();
return (int)st.nval;
}
public static void main(String[] args) throws IOException{
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int t = nextInt();
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
for(int x = 0; x < t; ++x) {
int n = nextInt();
boolean increase = true, ret = true;
int last = 0, num = 0;
for(int i = 0; i < n; ++i) {
int a = nextInt();
if(!ret)continue;
if(increase) {
if(a<num) {
increase = false;
num = last;
if(num < n-i)ret = false;
else num = Math.min(n-i, num);
}
else ++num;
}
if(!increase) {
--num;
if(a<num || num<0) ret = false;
}
last = a;
}
if(ret)pw.println("Yes");
else pw.println("No");
}
pw.close();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 1446253c04179be2966ce08dbe1ebe22 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class CodingLegacy {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Palindrome solver = new Palindrome();
int t = in.nextInt();
for (int i = 0; i < t; i++) {
solver.solve(i + 1, in, out);
}
out.close();
}
static class Palindrome {
static long mod = 1000000007;
static long max = (long) 1e18;
void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
boolean f = true;
int i;
for(i = 0;i<n;i++) {
if(a[i] < i ){
f = false;
break;
}
}
if(f) {
out.println("Yes");
return;
}
// out.println(i);
if(a[i] + a[i-1] < n -1 && a[i]==a[i-1]){
out.println("No");
return;
}
for(;i<n;i++){
if(a[i] + i - n + 1 < 0 ){
f = true;
break;
}
}
if(f){
out.println("No");
return;
}
out.println("Yes");
}
static class Pair {
int a;
int b;
Pair(int c,int d) {
a = c;
b = d;
}
}
}
static class Maths{
static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
public static long factorial(int n){
long fact = 1;
for(int i=1;i<=n;i++){
fact *= i;
}
return fact;
}
}
static class Characters{
public static boolean isVovel(char a){
return a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u';
}
}
static class Binary {
public static long numberOfBits(long n){
long count=0;
while(n>0){
count++;
n >>=1;
}
return count;
}
public static long numberOfSetBits(long n){
long count = 0;
int p = 1;
while (n>0){
if((n&p) == 1){
count++;
}
n >>= 1;
}
return count;
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
public Long nextLong(){
return Long.parseLong(next());
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 9d250f2298727d5f143d31e065ff58a7 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
OutputStream outputStream = System.out;
InputStream inputStream = System.in;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Solve solver = new Solve();
solver.solve(1, in, out);
out.close();
}
static class Solve {
public void solve(int testNumber, InputReader in, OutputWriter out) {
for(int o = in.nextInt();o>0;o--) {
int n = in.nextInt();
int[]c = in.nextIntArray(n);
boolean sh = true;
for(int i = 0;i<(n+1)/2;i++) {
if(c[i]<i|c[n-i-1]<i)sh=false;
}
if(n%2==0) {
if(c[n/2-1]==n/2-1&c[n/2-1]==c[n/2])sh=false;
}
if(sh)out.println("Yes");
else out.println("No");
}
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
public void println(String string) {
writer.println(string);
}
public void println(int number) {
writer.println(number);
}
public void println(long number) {
writer.println(number);
}
public void println(double number) {
writer.println(number);
}
public void println(char number) {
writer.println(number);
}
public void print(long number) {
writer.print(number);
}
public void print(int number) {
writer.print(number);
}
public void print(char number) {
writer.print(number);
}
public void print(String string) {
writer.print(string);
}
public void print(double number) {
writer.print(number);
}
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public String nextLine() {
StringBuilder sb = new StringBuilder();
int b = readByte();
while (b!=10) {
sb.appendCodePoint(b);
b = readByte();
}
if(sb.length()==0)return "";
return sb.toString().substring(0,sb.length()-1);
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | d04c19e57b3c43bc774a0a673a9980fc | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import javax.swing.plaf.synth.SynthTextAreaUI;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
*
*/
public class TaskB {
public static void main(String[] arg) {
final FastScanner in = new FastScanner(System.in);
final PrintWriter out = new PrintWriter(System.out);
final int T = in.nextInt();
for (int t = 0; t < T; t++) {
final int n = in.nextInt();
final int[] a = in.readIntArr(n);
final boolean sol = solution(n, a);
String resp = sol ? "Yes" : "No";
out.printf("%s%n", resp);
}
out.close();
in.close();
}
private static boolean solution(final int n, final int[] a) {
int pick = n / 2;
if (n % 2 == 1) {
return sol(pick, n, a);
}
// return true;
return sol(pick , n, a) ||
sol(pick - 1, n, a);
}
private static boolean sol(final int midle, final int n,
final int[] a) {
for (int i = 0; i <= midle&&i<n; i++) {
if (a[i] < i) return false;
}
for (int i = n - 1; i >= midle; i--) {
if (a[i] < (n - i - 1)) return false;
}
return true;
}
private static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream stream) {
try {
br = new BufferedReader(new InputStreamReader(stream));
} catch (Exception e) {
e.printStackTrace();
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readIntArr(int n) {
int[] result = new int[n];
for (int i = 0; i < n; i++) {
result[i] = Integer.parseInt(next());
}
return result;
}
void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 05b5f8f3a8a5177ae0654f752aa79080 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br;
static int cin() throws Exception
{
return Integer.valueOf(br.readLine());
}
static int[] split() throws Exception
{
String[] cmd=br.readLine().split(" ");
int[] ans=new int[cmd.length];
for(int i=0;i<cmd.length;i++)
{
ans[i]=Integer.valueOf(cmd[i]);
}
return ans;
}
static int len(int n)
{
int ans=0;
while(n!=0)
{
n=n/2;
ans++;
}
return ans;
}
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
br=new BufferedReader(new InputStreamReader(System.in));
String[] cmd=br.readLine().split(" ");
int cases=Integer.valueOf(cmd[0]);
while(cases!=0)
{
cases--;
int n=cin();
int[]arr=split();
int a=-1;
int b=n;
for(int i=0;i<n;i++)
{
if(arr[i]<i)
break;
a=i;
}
for(int i=n-1;i>=0;i--)
{
if(arr[i]<(n-1-i))
break;
b=i;
}
if(b<=a)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 4709cbccbfbcd6230b780f7bb9d8f7e9 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class MakingString implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
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 long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
// if modulo is required set value accordingly
public static long[][] matrixMultiply2dL(long t[][],long m[][])
{
long res[][]= new long[t.length][m[0].length];
for(int i=0;i<t.length;i++)
{
for(int j=0;j<m[0].length;j++)
{
res[i][j]=0;
for(int k=0;k<t[0].length;k++)
{
res[i][j]+=t[i][k]+m[k][j];
}
}
}
return res;
}
static long combination(long n,long r)
{
long ans=1;
for(long i=0;i<r;i++)
{
ans=(ans*(n-i))/(i+1);
}
return ans;
}
static int mat(String a,String b)
{
int count=0;
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)!=b.charAt(i))
count++;
}
return count;
}
public static void main(String args[]) throws Exception
{
new Thread(null, new MakingString(),"MakingString",1<<27).start();
}
// **just change the name of class from Main to reuquired**
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
int t=sc.nextInt();
int arr[]=new int[t];
for(int j=0;j<t;j++)
arr[j]=sc.nextInt();
boolean incr=true;
boolean decr=true;
int k=0;
int l=t-1;
for(k=0;k<t-1;k++)
{
if(k<arr[k+1])
continue;
else
{
decr=false;
break;
}
}
if(decr==true)
{
w.println("YES");
continue;
}
int count=1;
for(l=t-1;l>0;l--)
{
if((t-1)-l<arr[l-1])
count++;
else
{
incr=false;
break;
}
}
if(incr==true)
{
w.println("YES");
continue;
}
else if(incr == false && count+k>=t)
{
w.println("YES");
}
else
w.println("No");
}
System.out.flush();
w.close();
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 05c18b75f3ed108fc15b3591c40c7e2f | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class MakingString implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
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 long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
// if modulo is required set value accordingly
public static long[][] matrixMultiply2dL(long t[][],long m[][])
{
long res[][]= new long[t.length][m[0].length];
for(int i=0;i<t.length;i++)
{
for(int j=0;j<m[0].length;j++)
{
res[i][j]=0;
for(int k=0;k<t[0].length;k++)
{
res[i][j]+=t[i][k]+m[k][j];
}
}
}
return res;
}
static long combination(long n,long r)
{
long ans=1;
for(long i=0;i<r;i++)
{
ans=(ans*(n-i))/(i+1);
}
return ans;
}
static int mat(String a,String b)
{
int count=0;
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)!=b.charAt(i))
count++;
}
return count;
}
public static void main(String args[]) throws Exception
{
new Thread(null, new MakingString(),"MakingString",1<<27).start();
}
// **just change the name of class from Main to reuquired**
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
int t=sc.nextInt();
int arr[]=new int[t];
for(int j=0;j<t;j++)
arr[j]=sc.nextInt();
boolean incr=true;
boolean decr=true;
int k=0;
int l=t-1;
for(k=0;k<t-1;k++)
{
if(k<arr[k+1])
continue;
else
{
decr=false;
break;
}
}
if(decr==true)
{
System.out.println("YES");
continue;
}
int count=1;
for(l=t-1;l>0;l--)
{
if((t-1)-l<arr[l-1])
count++;
else
{
incr=false;
break;
}
}
if(incr==true)
{
System.out.println("YES");
continue;
}
else if(incr == false && count+k>=t)
{
System.out.println("YES");
}
else
System.out.println("No");
}
System.out.flush();
w.close();
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | b8d5ba3a4f1ac38fed170e515d50e91d | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.InputMismatchException;
public class E
{
static class Print
{
private final BufferedWriter bw;
public Print()
{
this.bw=new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object)throws IOException
{
bw.append(""+object);
}
public void println(Object object)throws IOException
{
print(object);
bw.append("\n");
}
public void close()throws IOException
{
bw.close();
}
}
static class Scan
{
private byte[] buf=new byte[1024*1024];
private int index;
private InputStream in;
private int total;
public Scan()
{
in=System.in;
}
public int scan()throws IOException
{
if(total<0)
throw new InputMismatchException();
if(index>=total)
{
index=0;
total=in.read(buf);
if(total<=0)
return -1;
}
return buf[index++];
}
public int scanInt()throws IOException
{
int integer=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
integer*=10;
integer+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
return neg*integer;
}
public double scanDouble()throws IOException
{
double doub=0;
int n=scan();
while(isWhiteSpace(n))
n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n)&&n!='.')
{
if(n>='0'&&n<='9')
{
doub*=10;
doub+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
if(n=='.')
{
n=scan();
double temp=1;
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
temp/=10;
doub+=(n-'0')*temp;
n=scan();
}
else throw new InputMismatchException();
}
}
return doub*neg;
}
public long scanLong() throws IOException
{
long ret = 0;
long c = scan();
while (c <= ' ')
{
c = scan();
}
boolean neg = (c == '-');
if (neg)
{
c = scan();
}
do
{
ret = ret * 10 + c - '0';
}
while ((c = scan()) >= '0' && c <= '9');
if (neg)
{
return -ret;
}
return ret;
}
public String scanString()throws IOException
{
StringBuilder sb=new StringBuilder();
int n=scan();
while(isWhiteSpace(n))
n=scan();
while(!isWhiteSpace(n) || n==' ')
{
sb.append((char)n);
n=scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n)
{
if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
return true;
return false;
}
}
public static void main(String[] args) throws IOException
{
Scan scan=new Scan();
Print print=new Print();
int T=scan.scanInt();
while(T-->0)
{
int N=scan.scanInt();
long arr[]=new long[N];
int id1=0;
int id2=N-1;
for(int i=0;i<N;i++)
{
arr[i]=scan.scanLong();
}
loop1:
for(int i=0;i<N;i++)
{
if(i>arr[i])
{
break loop1;
}
id1=i;
}
loop1:
for(int i=N-1;i>=0;i--)
{
if(N-i-1>arr[i])
{
break loop1;
}
id2=i;
}
if(id1>=id2)
{
print.println("Yes");
}
else
{
print.println("No");
}
}
print.close();
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | ac6022b0853d1c0fa83701caf27596c8 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
int t =scn.nextInt();
while(t-->0){
int n=scn.nextInt();
int [] arr = new int[n];
boolean flag=false;
for(int i=0;i<n;i++){
arr[i]=scn.nextInt();
if(flag==false){
if(i<n/2){
if(arr[i]<i){
flag=true;
}
}else{
if(n%2==0 &&i==n/2){
int val= Math.abs(arr[i-1]-arr[i]);
if(val==0 && arr[i]-i<0){
flag=true;
}
}
if(arr.length-1-i>arr[i]){
flag=true;
}
}
}
}
// if(n%2==0){
// if(arr[n/2-1]==arr[n/2]){
// if(arr[n/2]==n/2){
// flag=true;
// }
// }
// }
if(flag){
System.out.println("No");
}else{
System.out.println("Yes");
}
}
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 7b65bc2b38fd97ec4206ce7b4437be97 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | /*
Author: @__goku__
ssrivastava990@gmail.com
`\-. `
\ `. `
\ \ |
__.._ | \. S O N - G O K U
..---~~ ~ . | Y
~-. `| |
`. `~~--.
\ ~.
\ \__. . -- - .
.-~~~~~ , , ~~~~~~---...._
.-~___ ,'/ ,'/ ,'\ __...---~~~
~-. /._\_( ,(/_. 7,-. ~~---...__
_...>- P""6=`_/"6"~ 6) ___...--~~~
~~--._ \`--') `---' 9' _..--~~~
~\ ~~/_ ~~~ /`-.--~~
`. --- .' \_
`. " _.-' | ~-.,-------._
..._../~~ ./ .-' .-~~~-.
,--~~~ ,'...\` _./.----~~.'/ /' `-
_.-( |\ `/~ _____..-' / / _.-~~`.
/ | /. ^---~~~~ ' / / ,' ~. \
( / ( . _ ' /' / ,/ \ )
(`. | `\ - - - - ~ /' ( / . |
\.\| \ /' \ |`. /
/.'\\ `\ /' ~-\ . /\
/, ( `\ /' `.___..- \
| | \ `\_/' // \. |
| | | _Seal_ /' | | |
*/
import java.io.*;
import java.util.*;
public class C616B
{
static PrintWriter out = new PrintWriter((System.out));
public static void main(String args[]) throws IOException
{
Kioken sc = new Kioken();
int t = sc.nextInt();
while (t-- > 0)
{
int n=sc.nextInt();
int ar[]=new int[n];
for(int x=0;x<n;x++)
{
ar[x]=sc.nextInt();
}
kamehameha(ar,n);
}
out.close();
}
public static void kamehameha(int ar[],int n)
{
int a=-1;
int b=n;
for(int x=0;x<n;x++)
{
if (ar[x] < x)
{
break;
}
else
{
a=x;
}
}
for(int x=n-1;x>=0;x--)
{
if(ar[x]<(n-1-x))
{
break;
}
else
{
b=x;
}
}
out.println(b<=a?"Yes":"No");
}
static class Kioken
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next()
{
while (!st.hasMoreTokens())
{
try
{
st = new StringTokenizer(br.readLine());
} catch (Exception e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public String nextLine()
{
try
{
return br.readLine();
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
public boolean hasNext()
{
String next = null;
try
{
next = br.readLine();
} catch (Exception e)
{
}
if (next == null)
{
return false;
}
st = new StringTokenizer(next);
return true;
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 16c6d5aeb8918aeb937690fc83397154 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
solution s = new solution();
s.solve();
s.close();
}
}
interface IO {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
}
class solution implements IO {
final int maxn = (int) 3e5 + 5;
int[] a = new int[maxn];
boolean check(int n) {
int i, j;
int l = -1, r = n;
for(i = 0; i < n; i++){
if(a[i] < i) break;
l = i;
}
for(j = n - 1; j >= 0; j--){
if(a[j] < n - j - 1) break;
r = j;
}
if(r <= l) return true;
return false;
}
void solve() {
int t = in.nextInt();
while (t-- != 0) {
int n = in.nextInt();
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
int i, j;
int l = -1, r = n;
for(i = 0; i < n; i++){
if(a[i] < i) break;
l = i;
}
for(j = n - 1; j >= 0; j--){
if(a[j] < n - j - 1) break;
r = j;
}
out.println(r <= l ? "Yes" : "No");
}
}
/*
* 4 1 3 2 1 3 1 1 2 9 0 1 1
*/
void close() {
in.close();
out.close();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 1229a213b1146c82c6845e43d80788cc | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
solution s = new solution();
s.solve();
s.close();
}
}
interface IO {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
}
class solution implements IO {
final int maxn = (int) 3e5 + 5;
int[] a = new int[maxn];
boolean check(int n) {
int i, j;
int l = -1, r = n;
for(i = 0; i < n; i++){
if(a[i] < i) break;
l = i;
}
for(j = n - 1; j >= 0; j--){
if(a[j] < n - j - 1) break;
r = j;
}
if(r <= l) return true;
return false;
}
void solve() {
int t = in.nextInt();
while (t-- != 0) {
int n = in.nextInt();
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
int i, j;
int l = -1, r = n;
for(i = 0; i < n; i++){
if(a[i] < i) break;
l = i;
}
for(j = n - 1; j >= 0; j--){
if(a[j] < n - j - 1) break;
r = j;
}
if(r <= l)
out.println("Yes");
else
out.println("No");
}
}
/*
* 4 1 3 2 1 3 1 1 2 9 0 1 1
*/
void close() {
in.close();
out.close();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | de5f6a8ba418f4489a2ff834436e77a6 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
solution s = new solution();
s.solve();
s.close();
}
}
interface IO {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
}
class solution implements IO {
final int maxn = (int) 3e5 + 5;
int[] a = new int[maxn];
boolean check(int n) {
int i, j;
int l = -1, r = n;
for(i = 0; i < n; i++){
if(a[i] < i) break;
l = i;
}
for(j = n - 1; j >= 0; j--){
if(a[j] < n - j - 1) break;
r = j;
}
if(r <= l) return true;
return false;
}
void solve() {
int t = in.nextInt();
while (t-- != 0) {
int n = in.nextInt();
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
out.println(check(n) ? "Yes" : "No");
}
}
/*
* 4 1 3 2 1 3 1 1 2 9 0 1 1
*/
void close() {
in.close();
out.close();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 5bae545fc0125a19361b5c92a7ca0d5c | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;
import java.math.*;
import java.text.DecimalFormat;
public class Prac{
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
static class Pair{
int r,c;
public Pair(int r,int c){
this.r=r;
this.c=c;
}
}
static PrintWriter w = new PrintWriter(System.out);
static long mod=998244353L,mod1=1000000007;
public static void main (String[] args)throws IOException{
InputReader sc=new InputReader(System.in);
int t=sc.ni();
while(t-->0){
int n=sc.ni();
long arr[]=new long[n+2];
int in=n+1;
for(int i=1;i<=n;i++)arr[i]=sc.ni();
int i=1,j=n,val=0;
if(n%2!=0){
boolean f=false;
while(i<=j){
if(arr[i]>=val&&arr[j]>=val){
arr[i]=val;
arr[j]=val;
i++;j--;
val++;
}
else{
f=true;
break;
}
}
if(f){
w.println("No");
}
else w.println("Yes");
}
else{
boolean f=false;
while(i+1<=j-1){
if(arr[i]>=val&&arr[j]>=val){
arr[i]=val;
arr[j]=val;
i++;j--;
val++;
}
else{
f=true;
break;
}
}
if(f)w.println("No");
else{
if((arr[i]>=val&&arr[j]>val)||(arr[i]>val&&arr[j]>=val))w.println("Yes");
else w.println("No");
}
}
}
w.close();
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | d22c2b56381b2b5de4c1fe541284b058 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
public class MyClass {
public static void main(String args[]) {
FastReader sc = new FastReader(); //For Fast IO
StringBuilder sb = new StringBuilder();
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
int prefixEnd=-1;
int suffixEnd=n;
for(int i=0;i<n;i++){
if(arr[i]<i){break;}
prefixEnd=i;
}
for(int i=n-1;i>=0;i--){
if(arr[i]<(n-1-i)){break;}
suffixEnd=i;
}
if(suffixEnd<=prefixEnd){
sb.append("Yes\n");
}
else{
sb.append("No\n");
}
}
System.out.println(sb);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 92f30e757190b89c050f661adee2589b | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes |
import javax.swing.text.html.HTMLDocument;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
public class Main {
static class point {
double x;
double y;
public point(double xx,double yy){
x=xx;
y=yy;
}
public boolean isPer(point a){
double ans=Math.abs((a.x)*x-(a.y)*y);
if(doubleequals(ans, 0))return true;
return false;
}
public boolean isMid(point a,point b){
double xx=(a.x+b.x)/2;
double yy=(a.y+b.y)/2;
if(doubleequals(xx, x)&&doubleequals(yy, y))return true;
return false;
}
public double dist(point a){
return Math.sqrt((x-a.x)*(x-a.x)+(y-a.y)*(y-a.y)) ;
}
}
public static boolean doubleequals(double d1,double d2){
if( Math.abs(d1-d2)<=1e-6)return true;
return false;
}
public static long ciel(long x,long y){
long res=x/y;
if(x%y!=0)res++;
return res;
}
public static long gcd(long u,long v){
if(v==0)return u;
return gcd(v, u%v);
}
static int mod= (int) (1e9+7);
static long memo[][];
static long inf= (long) 1e9;
static int[]cost,weight;
public static long dp(int i,int mask){
if(i==n)return 0;
int ans=0;
for(int msk=0;msk<(8);msk++){
if(Integer.bitCount(msk)<cost[i])continue;
int inc=0;
for(int bit=0;bit<3;bit++){
int bit1=(1<<bit)&msk;
int bit2=(1<<bit)&mask;
if(bit1==1 && bit2==0)inc++;
}
return dp(i+1,(mask|msk)>>1)+inc;
}
return -1;
}
public static boolean check(point a,point b,point c,point m){
// if(!m.isMid(a,b))return false;
point cm=new point(c.x-m.x, c.y-m.y);
point ab=new point(a.x-b.x, a.y-b.y);
if(!cm.isPer(ab))return false;
if(!doubleequals(a.dist(b),m.dist(c)))return false;
return true;
}
public static boolean diffrent(int a,int b, int c, int d){
HashSet<Integer>hs=new HashSet<>();
hs.add(a); hs.add(b); hs.add(c); hs.add(d);
return hs.size()==4;
}
static String str;
static int Arr[],n,N,max;
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
PrintWriter PW=new PrintWriter(System.out);
// System.out.println();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int c=0;
boolean inc =true;
int []Arr=new int[n];
boolean ans=true;
for(int i=0;i<n;i++)
Arr[i]=sc.nextInt();
for(int i=0;i<n;i++) {
if(c<0){ans=false;break;}
if(inc){
if(Arr[i]>=c)c++;
else {c=Arr[i-1]-1;i--;inc=false;}
}else{
if(Arr[i]<=c)c=Arr[i]-1;
else
c--;
}
}
PW.println(ans?"Yes":"No");
}
PW.close();
}
public static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException, IOException {
return br.ready();
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | e7d52bc26caaf347d35bce115e673a42 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.*;
/**
*
* @author Pruthvi
*/
public class JavaApplication74 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0)
{ boolean flag=true;
int n=sc.nextInt();
int a[]=new int[n];
int mid=(n-1)/2;
int sum=0;
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
if(n%2==0)
{
// System.out.println("temp");
for (int i = 0; i <= mid; i++) {
if (a[i] < sum) {
flag = false;
}
sum++;
}
sum--;
//System.out.println("a"+a[mid]+" a+1"+a[mid+1]);
if(a[mid]==a[mid+1] && a[mid]==sum)
flag=false;
for (int i = mid + 1; i < n; i++) {
if (a[i] < sum) {
flag = false;
}
sum--;
}
}
else
{
for (int i = 0; i <= mid; i++) {
if (a[i] < sum) {
flag = false;
}
sum++;
}
sum--;
for (int i = mid; i < n; i++) {
if (a[i] < sum) {
flag = false;
}
sum--;
}
}
if(flag==true)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 5c608dc69aba15e3f3a83f654689956b | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void solve(InputReader in) {
int n = in.readInt();
int a[] = new int[n];
for(int i = 0; i<n; i++){
a[i] = in.readInt();
}
int prefixend = -1;
int suffixend = n-1;
for(int i = 0; i<n; i++) {
if(a[i] < i) break;
prefixend = i;
}
for(int i = n-1; i>= 0; i--) {
if(a[i] < (n-1)-i)
break;
suffixend = i;
}
System.out.println((suffixend <= prefixend)?"YES":"NO");
}
public static void main(String ...strings) {
InputReader in = new InputReader(System.in);
int t = in.readInt();
while(t-- > 0) {
solve(in);
}
}
}
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 String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long readLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | d9a4153e1dc107b5ac63e45a0607d223 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
private static final Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int t = in.nextInt();
while(t-->0){
int n=in.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=in.nextInt();
}
if(n==1){
System.out.println("Yes");
continue;
}
int f=1;
for(int i=0;i<n;i++){
if(a[i]<i){
int ch=0;
for(int j=Math.max(0,i-1);j<n-1;j++){
if(a[j]<=a[j+1]){
ch=1;
break;
}
}
//System.out.println("ch:"+ch);
if(ch==0){
break;
}
if(ch==1)
for(int j=Math.max(0,i-1);j<n;j++){
if(a[j]<(n-1-j)){
f=0;
break;
}
}
break;
}
}
if(f==0){
System.out.println("No");
}
else{
System.out.println("Yes");
}
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | f5db78440c7b046d7337ff4888a551e1 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static long mod = (long) 1e9 + 7;
public static void main(String[] args) throws NumberFormatException, IOException {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
A: while (t-- > 0) {
int n = scn.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = scn.nextInt();
boolean f = true;
for (int i = 0; i < (n + 1) / 2; i++) {
if (a[i] < i)
f = false;
}
for (int i = n - 1; i >= (n + 1) / 2; i--) {
if (a[i] < n - 1 - i)
f = false;
}
if (n % 2 == 0 && (n/2 >= 1) && a[n / 2] == a[n / 2 - 1] && a[n / 2] == n / 2 - 1)
System.out.println("No");
else
System.out.println(f ? "Yes" : "No");
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 4a862034767f042a30e834e56b35ded7 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.*;
import java.io.*;
public class K {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
int[] a = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(st.nextToken());
}
int l = 0;
int i = n - 2;
for (; i >= 0; i--) {
if (a[i] <= l)
break;
else
l++;
}
if (i == -1)
pw.println("Yes");
else {
l = Math.min(l - 1, a[i]);
i--;
for (; i >= 0; i--) {
if (a[i] < l)
l=a[i];
else
l--;
}
// System.out.println(l);
if (l > -1)
pw.println("Yes");
else {
////////////////////////////////////
i = 1;
l=0;
for (; i < n; i++) {
if (a[i] <= l)
break;
else
l++;
}
if (i == n)
pw.println("Yes");
else {
l = Math.min(l-1, a[i]);
i++;
for (; i < n; i++) {
if (a[i] >= l)
l--;
else
l = a[i];
}
if (l > -1)
pw.println("Yes");
else {
pw.println("NO");
}
}
//////////////////////////////////
}
}
}
pw.flush();
}
}
| Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | fb3579e476f7e4c2b1231d17f7dcc320 | train_001.jsonl | 1580652300 | You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened; The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations. | 256 megabytes | import java.util.*;
public class CF_1291_B {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;++i)
a[i]=sc.nextInt();
int last=-1;
int i;
for(i=0;i<a.length;++i) {
if(a[i]>last)
last++;
else {
i--;
break;
}
}
boolean flag=true;
int s2=-1;
int k;
for( k=a.length-1;k>=0;--k) {
if(a[k]>s2) {
s2++;
} else {
k++;
break;
}
}
if(k<=i) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
} | Java | ["10\n1\n248618\n3\n12 10 8\n6\n100 11 15 9 7 8\n4\n0 1 1 0\n2\n0 0\n2\n0 1\n2\n1 0\n2\n1 1\n3\n0 1 0\n3\n1 0 1"] | 1 second | ["Yes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo"] | NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened. | Java 8 | standard input | [
"implementation",
"greedy"
] | b9d5e58459baf2a2c294225b73b7229b | The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$. | 1,300 | For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise. | standard output | |
PASSED | 7be87d8890b455fd5f60e12d25070ff6 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
public class Task4 {
static class FastScanner{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner()
{
stream = System.in;
}
int read()
{
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars){
curChar = 0;
try{
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
boolean isSpaceChar(int c)
{
return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
}
boolean isEndline(int c)
{
return c=='\n'||c=='\r'||c==-1;
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String next(){
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do{
res.appendCodePoint(c);
c = read();
}while(!isSpaceChar(c));
return res.toString();
}
String nextLine(){
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do{
res.appendCodePoint(c);
c = read();
}while(!isEndline(c));
return res.toString();
}
}
public static void main(String[] args) {
FastScanner in = new FastScanner();
byte vis[] =new byte[5005];
int n = in.nextInt();
int ans = 0;
int t;
for(int i=0;i<n;i++)
{
t= in.nextInt();
if(t > n || vis[t]!=0)
ans++;
else
vis[t] = 1;
}
System.out.println(ans);
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 22230a864fb99695257afbe8f7d842ce | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.io.*;
import java.util.*;
public class Hello
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
boolean hash[] = new boolean[N+1];
for(int i=1;i<=N;i++)
hash[i] = false;
for(int i=0;i<N;i++)
{
int val = sc.nextInt();
if(val<=N)
hash[val] = true;
}
int count = 0;
for(int i=1;i<=N;i++)
{
if(hash[i]==false)
count++;
}
System.out.println(count);
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | c08a8efef2a09e92f349b262e8a04472 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int n = sc.nextInt();
boolean[] exist = new boolean[n];
for (int i = 0; i < n; i++) {
int current = sc.nextInt();
if (current > n || n < 1) continue;
exist[current-1] = true;
}
int res = 0;
for (int i = 0; i < n; i++) {
res += exist[i] ? 0 : 1;
}
System.out.println(res);
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | ec55b70df31c9641894b60a018f345da | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Scanner;
public class Permutation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Comparator<Integer> comparator = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1.compareTo(o2);
}
};
int n = sc.nextInt();
int number = 0;
ArrayList<Integer> arr = new ArrayList<>();
HashSet<Integer> set = new HashSet<>();
for (int i = 0; i < n ; i++) {
int k = sc.nextInt();
arr.add(k);
}
arr.sort(comparator);
for (Integer integer: arr
) {
if (integer>n || !set.add(integer)) number++;
}
if (arr.get(0) - number <= 1) System.out.print(number + "\n");
else if (arr.size() == n) System.out.print(n + "\n");
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 3c2ab3bfc242752596f95a85db045cbd | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | //package hiougyf;
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//int t=sc.nextInt();
//while(t-->0) {
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++) a[i]=sc.nextInt();
HashSet<Integer>h=new HashSet<>();
int ans=0;
for(int i=0;i<n;i++) {
int f=a[i];
if(f>n) {
ans++;
continue;
}
if(h.contains(f)) {
ans++;
continue;
}
else if(!h.contains(f)) {
h.add(f);
}
}
System.out.println(ans);
}
public static int floorSqrt(int x)
{
// Base Cases
if (x == 0 || x == 1)
return x;
// Do Binary Search for floor(sqrt(x))
int start = 1, end = x, ans=0;
while (start <= end)
{
int mid = (start + end) / 2;
// If x is a perfect square
if (mid*mid == x)
return mid;
// Since we need floor, we update answer when mid*mid is
// smaller than x, and move closer to sqrt(x)
if (mid*mid < x)
{
start = mid + 1;
ans = mid;
}
else // If mid*mid is greater than x
end = mid-1;
}
return ans;
}
static int div(int n,int b) {
int g=-1;
for(int i=2;i<=Math.sqrt(n);i++) {
if(n%i==0&&i!=b) {
g=i;
break;
}
}
return g;
}
public static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
public static int lcm(int a, int b)
{
return (a*b)/gcd(a, b);
}
public static boolean isPrime1(int n) {
if (n <= 1) {
return false;
}
if (n == 2) {
return true;
}
for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
public static boolean isPrime(int n) {
if (n <= 1) {
return false;
}
if (n == 2) {
return true;
}
if (n % 2 == 0) {
return false;
}
for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | fa91767be67570b0b4f8d250fd6097e9 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes |
// Imports
import java.util.*;
import java.io.*;
public class B137 {
/**
* @param args the command line arguments
* @throws IOException, FileNotFoundException
*/
public static void main(String[] args) throws IOException, FileNotFoundException {
// TODO UNCOMMENT WHEN ALGORITHM CORRECT
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
// TODO code application logic here
int N = Integer.parseInt(f.readLine());
boolean[] vis = new boolean[N];
StringTokenizer st = new StringTokenizer(f.readLine());
for(int i = 0; i < N; i++) {
int curr = Integer.parseInt(st.nextToken()) - 1;
if(curr >= 0 && curr < N) {
vis[curr] = true;
}
}
int count = 0;
for(int i = 0; i < vis.length; i++) {
if(!vis[i])
count++;
}
System.out.println(count);
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 639e2c6c2fb43ca7fe714aa87e1ef43d | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.Scanner;
public class Permutation {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int n= scan.nextInt();
int arr[]=new int[5001];
int ctr=0,temp;
for(int i=0;i<n;i++) {
temp=scan.nextInt();
arr[temp]++;
}
scan.close();
for(int i=0;i<5001;i++) {
if(arr[i]>1) {
ctr+=arr[i]-1;
}
if(i>n&&arr[i]>=1) {
ctr++;
}
}
System.out.println(ctr);
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 74e046b1139582ecdba732c32b41445f | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.*;
public class permutation
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt();
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=0;i<n;i++)
{
int a=in.nextInt();
list.add(a);
}
int c=0;
for(int i=1;i<=n;i++)
{
if(list.contains(i)!=true)
{
c++;
}
}
System.out.println(c);
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | afbcdbdac1b37f570f100cb0a9100728 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.*;
public class Shubh{
public static void main(String []args){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int arr[]=new int[n+1];
int c=0;
for(int i=0;i<n;i++)
{
int t=s.nextInt();
if(t>n)
c++;
else
{
if(arr[t]==1)
c++;
else
arr[t]=1;
}
}
System.out.println(c);
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 6f9769d5f8a03ef29d70914b62fc2a1e | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Permutation {
private static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n =in.nextInt();
int[] arr = new int[n];
Set<Integer> set = new HashSet<>();
for(int i=0;i<n;i++){
arr[i] = in.nextInt();
if(arr[i]<=n){
set.add(arr[i]);
}
}
System.out.println(n-set.size());
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 1a887be3f48197ab3c9b321fefb030fe | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class permutation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
sc.close();
int ans =0;
Arrays.sort(a);
if(a[0]>n)
ans++;
for (int i = 1; i < n; i++)
{
if(a[i]==a[i-1])
{
ans++;
}
else if(a[i]>n)
{
ans++;
}
}
System.out.println(ans);
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | f94b31e80476db59f5d17d6cb25e3a2b | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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);
OutputWriter out = new OutputWriter(outputStream);
BPermutation solver = new BPermutation();
solver.solve(1, in, out);
out.close();
}
static class BPermutation {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int ntc = 1;
// ntc = in.nextInt();
while ((ntc--) > 0) {
int n = in.nextInt();
HashSet<Integer> hs = new HashSet<>();
for (int i = 0; i < n; i++) {
hs.add(in.nextInt());
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (!hs.contains(i)) {
ans++;
}
}
out.println(ans);
}
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
public void println(long i) {
writer.println(i);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.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 nextInt() {
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 interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | fc7a976d1dce3f5d0ce7e174efd8a3e1 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes |
import java.io.BufferedReader;
import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
public class PER
{
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
static void pn(Object o) {
out.println(o);
out.flush();
}
static void p(Object o) {
out.print(o);
out.flush();
}
static void pni(Object o) {
out.println(o);
System.out.flush();
}
static int I() throws IOException {
return sc.nextInt();
}
static long L() throws IOException {
return sc.nextLong();
}
static double D() throws IOException {
return sc.nextDouble();
}
static String S() throws IOException {
return sc.next();
}
static char C() throws IOException {
return sc.next().charAt(0);
}
static int[] Ai(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = I();
return arr;
}
static String[] As(int n) throws IOException {
String s[] = new String[n];
for (int i = 0; i < n; i++)
s[i] = S();
return s;
}
static long[] Al(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = L();
return arr;
}
public static void process() throws IOException
{
int n=I();
ArrayList<Integer> m=new ArrayList<Integer>();
ArrayList<Integer> k=new ArrayList<Integer>();
for(int i=0;i<n;i++)
{
m.add(I());
}
for(int i=0;i<n;i++)
{
k.add(i+1);
}
int c=0;
for(int j=0;j<n;j++)
{
if(m.contains(k.get(j))==false)
{
c++;
}
}
pn(c);
}
public static void main(String[] args) throws IOException
{
process();
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 2167d1a1c4874dfffda705200780a8fe | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.Scanner;
public class Permutation {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
boolean [] arr = new boolean[5001];
for (int i=0;i<n;i++) arr[s.nextInt()] = true;
int count = 0;
for (int i=1;i<=n;i++) {
if (!arr[i]) count++;
}
System.out.println(count);
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 5fd45f0ecb8494fe2ee54566d7ae1ed7 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.Arrays;
public class B {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
int n = fs.nextInt(), res = 0;
int[] A = fs.readArray(n);
for (int i=1; i<n+1; i++){
boolean found = false;
for (int j = 0; j<n; j++){
if (A[j] == i){
found = true;
break;
}
}
if (! found){
res++;
}
}
System.out.println(res);
}
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 class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | dcfa90b45f8483485f1ad1c85831de27 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.*;
import java.io.*;
public class changetomakepermutation{
static int n;
static Integer arr[];
static Integer ml,mr,block;
static Integer ans[];
static StringBuilder answer;
static HashMap<Integer,Integer> map=new HashMap<>();
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
answer=new StringBuilder();
PrintWriter out=new PrintWriter(System.out);
int t=1;
// Integer.parseInt(br.readLine().trim());
while(t-->0){
n=Integer.parseInt(br.readLine().trim());
StringTokenizer tok=new StringTokenizer(br.readLine()," ");
for(int i=0;i<n;i++){
int x=Integer.parseInt(tok.nextToken());
if(x<=n)
map.put(x,1);
}
}
out.println(n-map.size());
out.close();
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 21d416a6970ee280902c7ce31122e3bd | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ar {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (final IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (final IOException e) {
e.printStackTrace();
}
return str;
}
}
static boolean[] seen;
static Map<Integer, Integer> map;
static Set<Character> charset;
static Set<Integer> set;
static int[] arr;
static int[][] dp;
static int rem = (int) 1e9 + 7;
static List<List<Integer>> graph;
static int[][] kmv ={{2,1},{1,2},{2,-1},{-1,2},{-2,1},{1,-2},{-1,-2},{-2,-1}};
static char[]car;
static boolean[] primes;
static int MAX=(int)1e4+1;
static double[] dar;
static long[] lar;
static void Sieve(){
primes=new boolean[MAX];
primes[0]=true;
primes[1]=true;
for(int i=2;i*i<MAX;i++){
if(!primes[i]){
for(int j=i*i;j<MAX;j+=i){
primes[j]=true;
}
}
}
}
public static void main( String[] args) throws java.lang.Exception {
FastReader scn = new FastReader();
int n=scn.nextInt();
arr=new int[5001];
for(int i=0;i<n;i++)arr[scn.nextInt()]++;
int cnt=0;
for(int i=1;i<=5000;i++){
if(arr[i]>1 && i<=n){
cnt+=arr[i]-1;
}
else if(i>n && arr[i]>0){
cnt+=arr[i];
}
}
System.out.print(cnt);
return;
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | f221ad6b88047cf5d07419a161bbbc6e | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class CF137B {
static BufferedReader __in;
static PrintWriter __out;
static StringTokenizer input;
public static void main(String[] args) throws IOException {
__in = new BufferedReader(new InputStreamReader(System.in));
__out = new PrintWriter(new OutputStreamWriter(System.out));
int n = ri();
int[] a = ria(n);
List<Integer> l = new ArrayList<>();
for(int i = 1; i <= n; ++i) {
l.add(i);
}
for(int x : a) {
l.remove((Integer) x);
}
prln(l.size());
close();
}
// references
// IBIG = 1e9 + 7
// IRAND ~= 3e8
// IMAX ~= 2e10
// LMAX ~= 9e18
// constants
static final int IBIG = 1000000007;
static final int IRAND = 327859546;
static final int IMAX = 2147483647;
static final int IMIN = -2147483648;
static final long LMAX = 9223372036854775807L;
static final long LMIN = -9223372036854775808L;
// util
static int minof(int a, int b, int c) {return min(a, min(b, c));}
static int minof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
static int minstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
static long minof(long a, long b, long c) {return min(a, min(b, c));}
static long minof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
static long minstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
static int maxof(int a, int b, int c) {return max(a, max(b, c));}
static int maxof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
static int maxstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
static long maxof(long a, long b, long c) {return max(a, max(b, c));}
static long maxof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
static long maxstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static int floori(double d) {return (int)d;}
static int ceili(double d) {return (int)ceil(d);}
static long floorl(double d) {return (long)d;}
static long ceill(double d) {return (long)ceil(d);}
// input
static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
static long rl() throws IOException {return Long.parseLong(__in.readLine());}
static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
static String rline() throws IOException {return __in.readLine();}
static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
static int ni() {return Integer.parseInt(input.nextToken());}
static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
static long nl() {return Long.parseLong(input.nextToken());}
// output
static void pr(int i) {__out.print(i);}
static void prln(int i) {__out.println(i);}
static void pr(long l) {__out.print(l);}
static void prln(long l) {__out.println(l);}
static void pr(double d) {__out.print(d);}
static void prln(double d) {__out.println(d);}
static void pr(char c) {__out.print(c);}
static void prln(char c) {__out.println(c);}
static void pr(char[] s) {__out.print(new String(s));}
static void prln(char[] s) {__out.println(new String(s));}
static void pr(String s) {__out.print(s);}
static void prln(String s) {__out.println(s);}
static void pr(Object o) {__out.print(o);}
static void prln(Object o) {__out.println(o);}
static void prln() {__out.println();}
static void pryes() {__out.println("yes");}
static void pry() {__out.println("Yes");}
static void prY() {__out.println("YES");}
static void prno() {__out.println("no");}
static void prn() {__out.println("No");}
static void prN() {__out.println("NO");}
static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); __out.println(iter.next());}
static void flush() {__out.flush();}
static void close() {__out.close();}} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 1a0d0c077429e371be4789628415bc15 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
public class Codeforces {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] s = br.readLine().trim().split(" ");
int [] arr = new int[n];
for(int i = 0;i < n; i++){
arr[i] = Integer.parseInt(s[i]);
}
Set<Integer> set = new HashSet<Integer>();
for(int i = 1; i <= n; i++){
set.add(i);
}
for(int i = 0; i < arr.length; i++){
if(set.contains(arr[i])) set.remove(arr[i]);
}
System.out.println(set.size());
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | 0575276017f1212456f0888d8d54d890 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.util.*;
public class c{
public static void main(String a[]){
Scanner sc=new Scanner(System.in);
int n=0;
n=sc.nextInt();
int i,k=0;
ArrayList<Integer> li=new ArrayList<>();
for(i=0;i<n;i++){
k=sc.nextInt();
li.add(k);
}
k=0;
for(i=1;i<=n;i++){
if(!li.contains(i)){
k++;
}
}
System.out.println(k);
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | a377657b665c80e5dfa1c6a40b4a24b4 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | /* package codechef; // don't place package name! */
import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
// Complete the maximumSum function below.
public static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
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 long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static boolean prime(long a){
if(a==2||a==3)
return true;
if((a-1)%6==0)
return true;
if((a+1)%6==0)
return true;
return false;
}
public static long gcd(long a,long b){
if(b==0)
return a;
long r=a%b;
return gcd(b,r);
}
static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode() {}
TreeNode(int val) { this.val = val; }
TreeNode(int val, TreeNode left, TreeNode right) {
this.val = val;
this.left = left;
this.right = right;
}
}
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, List<Node> _children) {
val = _val;
children = _children;
}
}
// private static final FastReader scanner = new FastReader();
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader scanner = new InputReader(inputStream);
PrintWriter w = new PrintWriter(outputStream);
int n=scanner.nextInt();
Set<Integer> a=new HashSet<>();
int p=0,d=n;
while (n-->0){
int b=scanner.nextInt();
if(b>d)
p++;
else if(!a.add(b))
p++;
}
w.print(p);
w.close();
}
} | Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | c84c460e7493ad997ca69d2348fea823 | train_001.jsonl | 1324015200 | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
HashSet<Integer> ints = new HashSet<>();
for (int i = 0; i < n; i++)
ints.add(in.nextInt());
int res = 0;
for (int i = 1; i <= n; i++) {
if (!ints.contains(i))
res++;
}
out.println(res);
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["3\n3 1 2", "2\n2 2", "5\n5 3 3 3 1"] | 2 seconds | ["0", "1", "2"] | NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2. | Java 11 | standard input | [
"greedy"
] | bdd86c8bc54bbac6e2bb5a9d68b6eb1c | The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n). | 1,000 | Print the only number — the minimum number of changes needed to get the permutation. | standard output | |
PASSED | ad9d4accf0217516e136ea06512e9f2c | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
*/
public class Main {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//int qq = 1;
int qq = Integer.MAX_VALUE;
//int qq = readInt();
for(int casenum = 1; casenum <= qq; casenum++) {
int n = readInt();
int k = readInt();
TreeSet<Integer> ret = new TreeSet<Integer>();
Map<Integer, Integer> appear = new HashMap<Integer, Integer>();
int[] list = new int[n];
for(int i = 0; i < n; i++) {
list[i] = readInt();
}
for(int i = 0; i < n; i++) {
if(!appear.containsKey(list[i])) {
appear.put(list[i], 0);
}
int val;
appear.put(list[i], val = appear.get(list[i]) + 1);
if(val == 1) {
ret.add(list[i]);
}
else {
ret.remove(list[i]);
}
if(i >= k) {
appear.put(list[i-k], val = appear.get(list[i-k]) - 1);
if(val == 1) {
ret.add(list[i-k]);
}
else {
ret.remove(list[i-k]);
}
}
if(i >= k-1) {
if(ret.isEmpty()) pw.println("Nothing");
else pw.println(ret.last());
}
}
}
exitImmediately();
}
private static void exitImmediately() {
pw.close();
System.exit(0);
}
private static long readLong() throws IOException {
return Long.parseLong(nextToken());
}
private static double readDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
private static String nextLine() throws IOException {
if(!br.ready()) {
exitImmediately();
}
st = null;
return br.readLine();
}
private static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
exitImmediately();
}
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
} | Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 1d7e813310e897bd1e56af8a885d2268 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Java7Version {
public static StreamTokenizer in = new StreamTokenizer(System.in);
public static int ni (){
try {
in.nextToken();
} catch (IOException e) {
e.printStackTrace();
}
return (int)in.nval;
}
public static class CustomTree {
int[] vals;
int valSize = 0;
int[] count;
TreeSet<Integer> t1 = new TreeSet<>(new Comparator<Integer>() {
@Override
public int compare(Integer n1, Integer n2) {
int idx1 = Arrays.binarySearch(vals, n1);
int idx2 = Arrays.binarySearch(vals, n2);
if (count[idx1] == count[idx2]){
return n1 - n2;
}
return count[idx2] - count[idx1];
}
});
public CustomTree(int[] l1){
vals= l1.clone();
Arrays.sort(vals);
for (int i = 0 ; i < vals.length; i++){
if (i == 0 || vals[i] != vals[i - 1]){
vals[valSize++] = vals[i];
}
}
vals = Arrays.copyOf(vals, valSize);
count = new int[valSize];
// px(vals);
}
public void add(int n1){
t1.remove(n1);
count[Arrays.binarySearch(vals, n1)]++;
t1.add(n1);
}
public void remove(int n1){
t1.remove(n1);
int idx = Arrays.binarySearch(vals, n1);
count[idx]--;
if (count[idx] > 0){
t1.add(n1);
}
}
public Integer ans(){
Integer max = t1.last();
int idx = Arrays.binarySearch(vals, max);
if (count[idx] != 1){
return null;
}
return max;
}
}
public static void main(String[] args){
int n1 = ni();
int k1 = ni();
int[] l1 = new int[n1];
for (int i = 0 ; i < n1; i++){
l1[i] = ni();
}
CustomTree t1 = new CustomTree(l1);
for (int i = 0; i < k1; i++){
t1.add(l1[i]);
}
{
Integer cur = t1.ans();
if (cur == null){
out.println("Nothing");
}
else {
out.println(cur);
}
}
for (int i = k1;i < n1; i++){
t1.remove(l1[i - k1]);
t1.add(l1[i]);
Integer cur = t1.ans();
if (cur == null){
out.println("Nothing");
}
else {
out.println(cur);
}
}
out.flush();
}
public static PrintWriter out = new PrintWriter(System.out);
public static void px(Object ...objects){
System.out.println(Arrays.deepToString(objects));
}
}
| Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 4acbd1e04bacb1a040adbe315d809624 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.io.*;
import java.util.*;
public class R63qESubsegments {
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter w = new PrintWriter(System.out);
StringTokenizer st1 = new StringTokenizer(br.readLine());
int n = ip(st1.nextToken());
int k = ip(st1.nextToken());
int a[] = new int[n];
for(int i=0;i<n;i++)
a[i] = -1*ip(br.readLine());
TreeSet<Integer> set = new TreeSet<Integer>();
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
for(int i=0;i<k;i++){
if(map.containsKey(a[i])){
int curr = map.get(a[i]);
map.put(a[i], curr + 1);
if(curr == 1)
set.remove(a[i]);
}
else{
set.add(a[i]);
map.put(a[i], 1);
}
}
if(set.isEmpty())
w.println("Nothing");
else
w.println(-1*set.first());
for(int i=k;i<n;i++){
int prev = a[i-k];
int prevCount = map.get(prev);
int nowCount = prevCount - 1;
if(nowCount == 0){
map.remove(prev);
set.remove(prev);
}
else if(nowCount == 1){
map.put(prev, nowCount);
set.add(prev);
}
else
map.put(prev, nowCount);
int dis = a[i];
if(map.containsKey(dis)){
int curr = map.get(dis);
map.put(dis, curr + 1);
if(curr == 1)
set.remove(dis);
}
else{
set.add(dis);
map.put(dis, 1);
}
if(set.isEmpty())
w.println("Nothing");
else
w.println(-1*set.first());
}
w.close();
}
public static int ip(String s){
return Integer.parseInt(s);
}
}
| Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | eb0debc81f4686d0002435d4cf467f05 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.util.NavigableSet;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator;
import java.io.IOException;
import java.util.Arrays;
import java.util.TreeSet;
import java.io.InputStream;
import java.util.Random;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.SortedSet;
import java.util.Set;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
}
class TaskE {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int count = in.readInt();
int k = in.readInt();
final Counter<Integer> counter = new Counter<Integer>();
int[] A = new int[count];
NavigableSet<Integer> queue = new TreeSet<Integer>();
for (int i = 0; i < count; i++) {
int x = in.readInt();
A[i] = x;
counter.add(x);
if (counter.get(x) == 1) {
queue.add(x);
} else {
queue.remove(x);
}
if (i >= k - 1) {
if (i - k >= 0) {
counter.add(A[i - k], -1);
if (counter.get(A[i - k]) == 1) {
queue.add(A[i - k]);
}
if (counter.get(A[i - k]) == 0) {
queue.remove(A[i - k]);
}
}
if (queue.isEmpty()) {
out.printLine("Nothing");
} else {
out.printLine(queue.last());
}
}
}
}
}
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 interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
class Counter<K> extends EHashMap<K, Long> {
public Counter() {
super();
}
public long add(K key) {
long result = get(key);
put(key, result + 1);
return result + 1;
}
public void add(K key, long delta) {
put(key, get(key) + delta);
}
public Long get(Object key) {
if (containsKey(key))
return super.get(key);
return 0L;
}
}
class EHashMap<E, V> extends AbstractMap<E, V> {
private static final int[] shifts = new int[10];
private int size;
private HashEntry<E, V>[] data;
private int capacity;
private Set<Entry<E, V>> entrySet;
static {
Random random = new Random(System.currentTimeMillis());
for (int i = 0; i < 10; i++)
shifts[i] = 1 + 3 * i + random.nextInt(3);
}
public EHashMap() {
this(4);
}
private void setCapacity(int size) {
capacity = Integer.highestOneBit(4 * size);
//noinspection unchecked
data = new HashEntry[capacity];
}
public EHashMap(int maxSize) {
setCapacity(maxSize);
entrySet = new AbstractSet<Entry<E, V>>() {
public Iterator<Entry<E, V>> iterator() {
return new Iterator<Entry<E, V>>() {
private HashEntry<E, V> last = null;
private HashEntry<E, V> current = null;
private HashEntry<E, V> base = null;
private int lastIndex = -1;
private int index = -1;
public boolean hasNext() {
if (current == null) {
for (index++; index < capacity; index++) {
if (data[index] != null) {
base = current = data[index];
break;
}
}
}
return current != null;
}
public Entry<E, V> next() {
if (!hasNext())
throw new NoSuchElementException();
last = current;
lastIndex = index;
current = current.next;
if (base.next != last)
base = base.next;
return last;
}
public void remove() {
if (last == null)
throw new IllegalStateException();
size--;
if (base == last)
data[lastIndex] = last.next;
else
base.next = last.next;
}
};
}
public int size() {
return size;
}
};
}
public Set<Entry<E, V>> entrySet() {
return entrySet;
}
public void clear() {
Arrays.fill(data, null);
size = 0;
}
private int index(Object o) {
return getHash(o.hashCode()) & (capacity - 1);
}
private int getHash(int h) {
int result = h;
for (int i : shifts)
result ^= h >>> i;
return result;
}
public V remove(Object o) {
if (o == null)
return null;
int index = index(o);
HashEntry<E, V> current = data[index];
HashEntry<E, V> last = null;
while (current != null) {
if (current.key.equals(o)) {
if (last == null)
data[index] = current.next;
else
last.next = current.next;
size--;
return current.value;
}
last = current;
current = current.next;
}
return null;
}
public V put(E e, V value) {
if (e == null)
return null;
int index = index(e);
HashEntry<E, V> current = data[index];
if (current != null) {
while (true) {
if (current.key.equals(e)) {
V oldValue = current.value;
current.value = value;
return oldValue;
}
if (current.next == null)
break;
current = current.next;
}
}
if (current == null)
data[index] = new HashEntry<E, V>(e, value);
else
current.next = new HashEntry<E, V>(e, value);
size++;
if (2 * size > capacity) {
HashEntry<E, V>[] oldData = data;
setCapacity(size);
for (HashEntry<E, V> entry : oldData) {
while (entry != null) {
HashEntry<E, V> next = entry.next;
index = index(entry.key);
entry.next = data[index];
data[index] = entry;
entry = next;
}
}
}
return null;
}
public V get(Object o) {
if (o == null)
return null;
int index = index(o);
HashEntry<E, V> current = data[index];
while (current != null) {
if (current.key.equals(o))
return current.value;
current = current.next;
}
return null;
}
public boolean containsKey(Object o) {
if (o == null)
return false;
int index = index(o);
HashEntry<E, V> current = data[index];
while (current != null) {
if (current.key.equals(o))
return true;
current = current.next;
}
return false;
}
public int size() {
return size;
}
private static class HashEntry<E, V> implements Entry<E, V> {
private final E key;
private V value;
private HashEntry<E, V> next;
private HashEntry(E key, V value) {
this.key = key;
this.value = value;
}
public E getKey() {
return key;
}
public V getValue() {
return value;
}
public V setValue(V value) {
V oldValue = this.value;
this.value = value;
return oldValue;
}
}
}
| Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 61cbb99772d90071e39a5fa8ae899e02 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.util.NavigableSet;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.SortedSet;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Map;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.Set;
import java.util.NoSuchElementException;
import java.util.TreeSet;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Nguyen Trung Hieu - vuondenthanhcong11@yahoo.com
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
}
class TaskE {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int arrayLength = in.readInt();
int segmentLength = in.readInt();
int[] array = IOUtils.readIntArray(in, arrayLength);
MultiSet<Integer> segment = new MultiSet<Integer>();
NavigableSet<Integer> unique = new TreeSet<Integer>();
for (int i = 0; i < segmentLength; i++) {
int count = segment.add(array[i]);
if (count == 1)
unique.add(array[i]);
else if (count == 2)
unique.remove(array[i]);
}
if (unique.isEmpty())
out.printLine("Nothing");
else
out.printLine(unique.last());
for (int i = segmentLength; i < arrayLength; i++) {
int count = segment.add(array[i]);
if (count == 1)
unique.add(array[i]);
else if (count == 2)
unique.remove(array[i]);
count = segment.remove(array[i - segmentLength]);
if (count == 1)
unique.remove(array[i - segmentLength]);
else if (count == 2)
unique.add(array[i - segmentLength]);
if (unique.isEmpty())
out.printLine("Nothing");
else
out.printLine(unique.last());
}
}
}
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 c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
}
class MultiSet<K> implements Iterable<K> {
private final Map<K, Integer> map;
private int size = 0;
public MultiSet() {
this(new HashMap<K, Integer>());
}
public MultiSet(Map<K, Integer> underlying) {
map = underlying;
}
public int add(K key) {
Integer value = map.get(key);
if (value == null)
value = 0;
value++;
size++;
map.put(key, value);
return value;
}
public int remove(K key) {
Integer value = map.get(key);
if (value == null)
return 0;
value--;
size--;
if (value == 0)
map.remove(key);
else
map.put(key, value);
return value + 1;
}
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
MultiSet multiSet = (MultiSet) o;
return !(map != null ? !map.equals(multiSet.map) : multiSet.map != null);
}
public int hashCode() {
return map.hashCode();
}
public Iterator<K> iterator() {
return map.keySet().iterator();
}
}
| Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 9176ab89eabed402fc5223dc89ca8629 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.util.*;
public class Subsegments {
public static void main(String [] args){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int array[]=new int[n];
for(int i=0;i<n;i++)array[i]=in.nextInt();
TreeSet<Integer>ts=new TreeSet<Integer>();
HashMap<Integer,Integer>hm=new HashMap<Integer,Integer>();
for(int i=0;i<k-1;i++){
Integer a=hm.get(array[i]);
if(a != null){
hm.put(array[i],hm.get(array[i])+1);
if(ts.contains(array[i]))ts.remove(array[i]);
}
else {
hm.put(array[i],1);ts.add(array[i]);
}
}
StringBuilder sb=new StringBuilder();
for(int i=k-1;i<n;i++){
Integer a=hm.get(array[i]);
if(a != null){
hm.put(array[i],hm.get(array[i])+1);
if(ts.contains(array[i]))ts.remove(array[i]);
}
else {
hm.put(array[i],1);ts.add(array[i]);
}
//System.out.println(ts);
if(ts.size() > 0)sb.append(ts.last());
else sb.append("Nothing");
sb.append('\n');
a=hm.get(array[i-k+1]);
if(a==1)hm.remove(array[i-k+1]);
else hm.put(array[i-k+1],a-1);
if(ts.contains(array[i-k+1]))ts.remove(array[i-k+1]);
if(a!=null && a==2)ts.add(array[i-k+1]);
}
System.out.print(sb);
}
} | Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 7d2cd7097f3809b44fc9548a0221e572 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
public class Codeforces implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException {
try {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
} catch (Throwable e) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
}
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());
}
int[] readIntArray(int size) throws IOException {
int[] res = new int[size];
for (int i = 0; i < size; i++) {
res[i] = readInt();
}
return res;
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
public static void main(String[] args) {
new Codeforces().run();
}
long timeBegin, timeEnd;
void time() {
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
long memoryTotal, memoryFree;
void memory() {
memoryFree = Runtime.getRuntime().freeMemory();
System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
+ " KB");
}
public void run() {
try {
timeBegin = System.currentTimeMillis();
memoryTotal = Runtime.getRuntime().freeMemory();
init();
solve();
out.close();
if (System.getProperty("ONLINE_JUDGE") == null) {
time();
memory();
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
TreeSet<Integer> single = new TreeSet<>();
HashMap<Integer, Integer> count = new HashMap<>();
void add(int x, int delta) {
Integer cnt = count.get(x);
if (cnt == null) cnt = 0;
cnt += delta;
if (cnt == 1) single.add(x); else single.remove(x);
count.put(x, cnt);
}
String getAnswer() {
return single.size() == 0 ? "Nothing" : String.valueOf(single.last());
}
void solve() throws IOException {
int n = readInt();
int m = readInt();
int[] a = readIntArray(n);
for (int i=0;i<m;i++) {
add(a[i], 1);
}
out.println(getAnswer());
for (int i=m;i<n;i++) {
add(a[i], 1);
add(a[i - m], -1);
out.println(getAnswer());
}
}
} | Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 85f6835a62e011d37adc0e5b1cfa0cde | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class CodeF
{
static class Scanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String nextLine()
{
try
{
return br.readLine();
}
catch(Exception e)
{
throw(new RuntimeException());
}
}
public String next()
{
while(!st.hasMoreTokens())
{
String l = nextLine();
if(l == null)
return null;
st = new StringTokenizer(l);
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public int[] nextIntArray(int n)
{
int[] res = new int[n];
for(int i = 0; i < res.length; i++)
res[i] = nextInt();
return res;
}
public long[] nextLongArray(int n)
{
long[] res = new long[n];
for(int i = 0; i < res.length; i++)
res[i] = nextLong();
return res;
}
public double[] nextDoubleArray(int n)
{
double[] res = new double[n];
for(int i = 0; i < res.length; i++)
res[i] = nextDouble();
return res;
}
public void sortIntArray(int[] array)
{
Integer[] vals = new Integer[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortLongArray(long[] array)
{
Long[] vals = new Long[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortDoubleArray(double[] array)
{
Double[] vals = new Double[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public String[] nextStringArray(int n)
{
String[] vals = new String[n];
for(int i = 0; i < n; i++)
vals[i] = next();
return vals;
}
Integer nextInteger()
{
String s = next();
if(s == null)
return null;
return Integer.parseInt(s);
}
int[][] nextIntMatrix(int n, int m)
{
int[][] ans = new int[n][];
for(int i = 0; i < n; i++)
ans[i] = nextIntArray(m);
return ans;
}
static <T> T fill(T arreglo, int val)
{
if(arreglo instanceof Object[])
{
Object[] a = (Object[]) arreglo;
for(Object x : a)
fill(x, val);
}
else if(arreglo instanceof int[])
Arrays.fill((int[]) arreglo, val);
else if(arreglo instanceof double[])
Arrays.fill((double[]) arreglo, val);
else if(arreglo instanceof long[])
Arrays.fill((long[]) arreglo, val);
return arreglo;
}
<T> T[] nextObjectArray(Class <T> clazz, int size)
{
@SuppressWarnings("unchecked")
T[] result = (T[]) java.lang.reflect.Array.newInstance(clazz, size);
for(int c = 0; c < 3; c++)
{
Constructor <T> constructor;
try
{
if(c == 0)
constructor = clazz.getDeclaredConstructor(Scanner.class, Integer.TYPE);
else if(c == 1)
constructor = clazz.getDeclaredConstructor(Scanner.class);
else
constructor = clazz.getDeclaredConstructor();
}
catch(Exception e)
{
continue;
}
try
{
for(int i = 0; i < result.length; i++)
{
if(c == 0)
result[i] = constructor.newInstance(this, i);
else if(c == 1)
result[i] = constructor.newInstance(this);
else
result[i] = constructor.newInstance();
}
}
catch(Exception e)
{
throw new RuntimeException(e);
}
return result;
}
throw new RuntimeException("Constructor not found");
}
}
static TreeMap <Integer, Integer> veces = new TreeMap <Integer, Integer> ();
static TreeSet <Integer> actuales = new TreeSet <Integer> ();
static void agregar(int a)
{
veces.put(a, veces.get(a) + 1);
if(veces.get(a).intValue() == 2)
actuales.remove(a);
if(veces.get(a).intValue() == 1)
actuales.add(a);
}
static void quitar(int a)
{
veces.put(a, veces.get(a) - 1);
if(veces.get(a).intValue() == 0)
actuales.remove(a);
if(veces.get(a).intValue() == 1)
actuales.add(a);
}
public static void main(String[] args)
{
Scanner sc = new Scanner();
int n = sc.nextInt();
int k = sc.nextInt();
int[] v = sc.nextIntArray(n);
for(int i : v)
veces.put(i, 0);
for(int i = 0; i < k; i++)
agregar(v[i]);
System.out.println(actuales.size() == 0 ? "Nothing" : actuales.last());
for(int i = k; i < n; i++)
{
quitar(v[i - k]);
agregar(v[i]);
System.out.println(actuales.size() == 0 ? "Nothing" : actuales.last());
}
}
} | Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 53dba7436c7a7e3cbc406c4223110e22 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
InputReader in = new InputReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
new Task().go(in, out);
out.close();
}
}
class Task {
public int maxn = 100010, mod = (int)1e9+7;
class Pair implements Comparable {
int cnt , val;
public Pair(int cnt, int val) {
this.cnt = cnt;
this.val = val;
}
public Pair() { this.cnt = this.val = 0; }
@Override
public int compareTo(Object obj) {
// TODO Auto-generated method stub
Pair p = (Pair) obj;
if(this.cnt == p.cnt) return p.val - this.val;
else return this.cnt - p.cnt;
}
/*
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
Pair p = (Pair) obj;
return this.compareTo(p) == 0;
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return this.cnt + this.val;
}
*/
}
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
TreeSet<Pair> hs = new TreeSet<Pair>();
int n, m;
int[] a = new int[maxn];
public void go(InputReader in, PrintWriter out) {
n = in.nextInt();
m = in.nextInt();
for(int i=0; i<n; i++) a[i] = in.nextInt();
for(int i=0; i<m; i++) {
if(hm.containsKey(a[i])) {
hm.put(a[i], hm.get(a[i]) + 1);
}
else hm.put(a[i], 1);
}
Iterator it = hm.entrySet().iterator();
while(it.hasNext()) {
Map.Entry<Integer, Integer> e = (Map.Entry<Integer, Integer>)it.next();
hs.add(new Pair(e.getValue(), e.getKey()));
// out.println(e.getKey() + " " + e.getValue());
}
it = hs.iterator();
Pair p = (Pair)it.next();
if(p.cnt == 1) out.println(p.val);
else out.println("Nothing");
// out.println(p.cnt + " " + p.val);
for(int i=m; i<n; i++) {
int cnt = hm.get(a[i-m]), val = a[i-m];
hs.remove(new Pair(cnt, val));
hm.remove(val);
cnt--;
if(cnt > 0) {
hm.put(val, cnt);
hs.add(new Pair(cnt, val));
}
val = a[i];
cnt = (hm.containsKey(val)) ? hm.get(val) : 0;
if(cnt > 0) {
hs.remove(new Pair(cnt, val));
cnt++;
hm.put(val, cnt);
hs.add(new Pair(cnt, val));
}
else {
cnt++;
hm.put(val, cnt);
hs.add(new Pair(cnt, val));
}
it = hs.iterator();
p = (Pair)it.next();
if(p.cnt == 1) out.println(p.val);
else out.println("Nothing");
// testing
/*
out.println("testing");
out.println(hs.size());
out.println(p.cnt + " " + p.val);
while(it.hasNext()) {
p = (Pair) it.next();
out.println(p.cnt + " " + p.val);
}
out.println();
*/
}
}
}
class InputReader {
BufferedReader bf;
StringTokenizer st;
InputReader(InputStreamReader is) {
bf = new BufferedReader(is);
}
public String next() {
if (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(bf.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
| Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | aa67dd0ad195df936568f6a57284a1a3 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.awt.Point;
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.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class E {
private static BufferedReader in;
private static StringTokenizer st;
private static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
int k = nextInt();
int a[] = new int [n];
int b[] = new int [n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
b[i] = a[i];
}
int size = 0;
Arrays.sort(b);
for (int i = 1; i < n; i++) {
if(b[size] != b[i]){
b[++size] = b[i];
}
}
size++;
int cnt[] = new int [size+1];
TreeSet<Integer> set = new TreeSet<Integer>();
for (int i = 0; i < k; i++) {
int ind = Arrays.binarySearch(b, 0,size,a[i]);
cnt[ind]++;
if(cnt[ind] > 1){
set.remove(ind);
}else{
set.add(ind);
}
}
if(set.isEmpty()){
out.println("Nothing");
}else{
out.println(b[set.last()]);
}
for (int i = k; i < n; i++) {
int ind = Arrays.binarySearch(b, 0,size,a[i]);
int ind0 = Arrays.binarySearch(b, 0,size,a[i-k]);
cnt[ind0]--;
if(cnt[ind0] == 1){
set.add(ind0);
}
if(cnt[ind0]==0){
set.remove(ind0);
}
cnt[ind]++;
if(cnt[ind] > 1){
set.remove(ind);
}else{
set.add(ind);
}
if(set.isEmpty()){
out.println("Nothing");
}else{
out.println(b[set.last()]);
}
}
out.close();
}
static String next() throws IOException{
while(!st.hasMoreTokens()){
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
static int nextInt() throws NumberFormatException, IOException{
return Integer.parseInt(next());
}
static long nextLong() throws NumberFormatException, IOException{
return Long.parseLong(next());
}
static double nextDouble() throws NumberFormatException, IOException{
return Double.parseDouble(next());
}
}
| Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 0211653aaf554acaf146a8a8b77eb530 | train_001.jsonl | 1300809600 | Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem. | 256 megabytes | import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;
public class Main
{
public void foo()
{
MyScanner scan = new MyScanner();
int n = scan.nextInt();
int k = scan.nextInt();
int[] a = new int[n];
for(int i = 0;i < n;++i)
{
a[i] = scan.nextInt();
}
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
TreeSet<Integer> ts = new TreeSet<Integer>();
for(int i = 0;i < k;++i)
{
if(hm.containsKey(a[i]))
{
hm.put(a[i], hm.get(a[i]) + 1);
if(ts.contains(a[i]))
{
ts.remove(a[i]);
}
}
else
{
hm.put(a[i], 1);
ts.add(a[i]);
}
}
System.out.println(ts.isEmpty() ? "Nothing" : ts.last());
for(int i = k;i < n;++i)
{
hm.put(a[i - k], hm.get(a[i - k]) - 1);
if(1 == hm.get(a[i - k]))
{
ts.add(a[i - k]);
}
else
{
if(ts.contains(a[i - k]))
{
ts.remove(a[i - k]);
}
}
if(hm.containsKey(a[i]))
{
hm.put(a[i], hm.get(a[i]) + 1);
}
else
{
hm.put(a[i], 1);
}
if(1 == hm.get(a[i]))
{
ts.add(a[i]);
}
else
{
if(ts.contains(a[i]))
{
ts.remove(a[i]);
}
}
System.out.println(ts.isEmpty() ? "Nothing" : ts.last());
}
}
public static void main(String[] args)
{
new Main().foo();
}
class MyScanner
{
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
BufferedInputStream bis = new BufferedInputStream(System.in);
public int read()
{
if (-1 == numChars)
{
throw new InputMismatchException();
}
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = bis.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
{
return -1;
}
}
return buf[curChar++];
}
public int nextInt()
{
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 long nextLong()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
{
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String next()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c)
{
return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
}
}
} | Java | ["5 3\n1\n2\n2\n3\n3", "6 4\n3\n3\n3\n4\n4\n2"] | 1 second | ["1\n3\n2", "4\nNothing\n3"] | null | Java 7 | standard input | [
"data structures",
"implementation"
] | 1f6675459b1eca7a3fdb422f03f91563 | The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment. Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109). | 1,800 | Print n–k + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing". | standard output | |
PASSED | 2a2318cd79e846e318ea1e58508b2a1a | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | // package codeforces.other2017.venturecup2017.qual;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class F {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int k = in.nextInt();
int[] perm = new int[n];
for (int i = 0; i < n ; i++) {
perm[i] = in.nextInt()-1;
}
List<Integer> cycles = new ArrayList<>();
boolean[] visited = new boolean[n];
for (int i = 0; i < n ; i++) {
if (visited[i]) {
continue;
}
int now = i;
int cnt = 0;
while (!visited[now]) {
visited[now] = true;
cnt++;
now = perm[now];
}
cycles.add(cnt);
}
int min = solveMin(cycles, k);
int max = solveMax(cycles, k);
if (k == 0) {
min = max = 0;
}
out.println(String.format("%d %d", min, max));
out.flush();
}
private static int solveMin(List<Integer> cycles, int k) {
Map<Integer,Integer> sets = new HashMap<>();
for (int c : cycles) {
sets.put(c, sets.getOrDefault(c, 0)+1);
}
List<Integer> vs = new ArrayList<>();
for (int x : sets.keySet()) {
int v = sets.get(x);
int l = 1;
while (l <= v) {
vs.add(x * l);
v -= l;
l *= 2;
}
if (v >= 1) {
vs.add(x * v);
}
}
Collections.sort(vs);
BitVector bv = new BitVector(1);
bv.set(0);
for (int c : vs) {
bv = bv.or(bv.shiftLeft(c));
}
return bv.get(k) ? k : k+1;
}
static class BitVector {
public int n;
public int m;
public long[] bits;
public BitVector(int length) {
n = length;
bits = new long[(n+63)>>>6];
m = bits.length;
}
public void set(int at) {
bits[at>>>6] |= 1L<<(at&63);
}
public boolean get(int at) {
return ((bits[at>>>6] >>> (at&63)) & 1) == 1;
}
public BitVector shiftLeft(int l) {
BitVector ret = new BitVector(n+l);
int big = l >>> 6;
int small = l & 63;
for (int i = 0; i < m ; i++) {
ret.bits[i+big] |= bits[i] << small;
}
if (small >= 1) {
for (int i = 0; i+big+1 < ret.m; i++) {
ret.bits[i+big+1] |= (bits[i] >>> (64-small));
}
}
return ret;
}
public BitVector or(BitVector o) {
BitVector ans = new BitVector(Math.max(n, o.n));
for (int i = 0; i < ans.m ; i++) {
if (i < m) {
ans.bits[i] = bits[i];
}
if (i < o.m) {
ans.bits[i] |= o.bits[i];
}
}
return ans;
}
}
private static int solveMax(List<Integer> cycles, int k) {
int cnt = 0;
for (int c : cycles) {
int x = c / 2;
int dec = Math.min(k, x);
cnt += dec * 2;
k -= dec;
}
for (int c : cycles) {
if (c % 2 == 1 && k >= 1) {
k--;
cnt++;
}
}
return cnt;
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int[] nextInts(int n) {
int[] ret = new int[n];
for (int i = 0; i < n; i++) {
ret[i] = nextInt();
}
return ret;
}
private int[][] nextIntTable(int n, int m) {
int[][] ret = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ret[i][j] = nextInt();
}
}
return ret;
}
private long[] nextLongs(int n) {
long[] ret = new long[n];
for (int i = 0; i < n; i++) {
ret[i] = nextLong();
}
return ret;
}
private long[][] nextLongTable(int n, int m) {
long[][] ret = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ret[i][j] = nextLong();
}
}
return ret;
}
private double[] nextDoubles(int n) {
double[] ret = new double[n];
for (int i = 0; i < n; i++) {
ret[i] = nextDouble();
}
return ret;
}
private int next() {
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 char nextChar() {
int c = next();
while (isSpaceChar(c))
c = next();
if ('a' <= c && c <= 'z') {
return (char) c;
}
if ('A' <= c && c <= 'Z') {
return (char) c;
}
throw new InputMismatchException();
}
public String nextToken() {
int c = next();
while (isSpaceChar(c))
c = next();
StringBuilder res = new StringBuilder();
do {
res.append((char) c);
c = next();
} while (!isSpaceChar(c));
return res.toString();
}
public int nextInt() {
int c = next();
while (isSpaceChar(c))
c = next();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c-'0';
c = next();
} while (!isSpaceChar(c));
return res*sgn;
}
public long nextLong() {
int c = next();
while (isSpaceChar(c))
c = next();
long sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c-'0';
c = next();
} while (!isSpaceChar(c));
return res*sgn;
}
public double nextDouble() {
return Double.valueOf(nextToken());
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static void debug(Object... o) {
System.err.println(Arrays.deepToString(o));
}
}
| Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output | |
PASSED | eefb432d3aca947de7643d51d381e070 | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.BitSet;
import java.util.HashMap;
import java.util.StringTokenizer;
public class FVenture {
public static void main(String[] args) {
FS scan = new FS(System.in);
int N = scan.nextInt(), K = scan.nextInt();
int[] list = new int[N];
for(int i=0;i<N;i++)list[i] = scan.nextInt()-1;
HashMap<Integer,Integer> cycle = new HashMap<>();
boolean[] seen = new boolean[N];
for(int i=0;i<N;i++){
if(seen[i])continue;
int idx = i;
int count = 0;
while(!seen[idx]){
seen[idx] = true;
idx = list[idx];
count++;
}
if(!cycle.containsKey(count))cycle.put(count, 1);
else cycle.put(count, cycle.get(count)+1);
}
int idx = 0;
int[] a = new int[cycle.size()], m = new int[cycle.size()];
for(int i : cycle.keySet()){
a[idx] = i;
m[idx++] = cycle.get(i);
}
int max = 0;
int k = K;
for(int i=0;i<a.length;i++){
int spots = Math.min(k, (a[i]/2)*m[i]);
k-=spots;
max+=(spots)*2;
}
for(int i=0;i<a.length;i++){
if(a[i]%2==1){
int spots = Math.min(k, m[i]);
k-=spots;
max+=spots;
}
}
BigInteger b = BigInteger.ONE;
for(int i=0;i<a.length;i++){
for(int x = 0; (1<<x) <= m[i]; x++){
b = b.or(b.shiftLeft(a[i]*(1<<x)));
m[i]-=(1<<x);
}
b = b.or(b.shiftLeft(a[i]*m[i]));
}
System.out.println((b.testBit(K)?K:(K+1))+" "+max);
}
private static class FS {
BufferedReader br;
StringTokenizer st;
public FS(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
String next(){
while(st==null||!st.hasMoreElements()){
try{st = new StringTokenizer(br.readLine());}
catch(IOException e){e.printStackTrace();}
}
return st.nextToken();
}
int nextInt() {return Integer.parseInt(next());}
long nextLong() {return Long.parseLong(next());}
double nextDouble() { return Double.parseDouble(next());}
}
}
| Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output | |
PASSED | 73f637e84d531d183af740d605225d88 | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.Map.*;
public class Main {
Input in;
PrintWriter out;
final static int INF = (int) 1e9;
final static int MOD = (int) 1e9 + 7;
final static long LINF = (long) 1e18;
final static double PI = (double) Math.acos(-1.0);
final static double EPS = (double) 1e-9;
BitSet shiftLeft(BitSet a, int k) {
long[] ar = a.toLongArray();
int d = k >> 6;
int r = k & 63;
long[] rs = new long[Math.min(20000, ar.length + d + 1)];
for (int i = d; i < rs.length; i++) {
if (i - d < ar.length) {
rs[i] = ar[i - d] << r;
}
if (i - d - 1 >= 0 && r > 0) {
rs[i] |= ar[i - d - 1] >>> 64 - r;
}
}
return BitSet.valueOf(rs);
}
void solvemin(TreeMap<Integer, Integer> hs, int n, int k) {
BitSet can = new BitSet(1);
can.set(0);
for (Entry<Integer, Integer> e : hs.entrySet()) {
int x = e.getKey();
int y = e.getValue();
can.or(shiftLeft(can, x));
int dt = 1;
for (int i = 31 - Integer.numberOfLeadingZeros(y) - 1; i >= 0; i--) {
can.or(shiftLeft(can, dt * x));
dt <<= 1;
if (((y >> i) & 1) == 1) {
can.or(shiftLeft(can, x));
dt |= 1;
}
}
}
if (k < can.length() && can.get(k)) out.print(k + " ");
else out.print((k + 1) + " ");
}
void solvemax(TreeMap<Integer, Integer> hs, int n, int k) {
int res = 0, d = k;
for (Entry<Integer, Integer> e : hs.entrySet()) {
int x = e.getKey();
int y = e.getValue();
int z = Math.min(d, x / 2 * y);
res += z << 1;
d -= z;
}
res = Math.min(n, res + d);
out.println(res);
}
void solve() {
int n = in.nextInt();
int k = in.nextInt();
int[] p = new int[n];
for (int i = 0; i < n; i++) {
p[i] = in.nextInt() - 1;
}
boolean[] vis = new boolean[n];
TreeMap<Integer, Integer> hs = new TreeMap<>();
for (int i = 0; i < n; i++) if (!vis[i]) {
int ptr = p[i], cnt = 1;
vis[i] = true;
while (ptr != i) {
vis[ptr] = true;
cnt++;
ptr = p[ptr];
}
if (!hs.containsKey(cnt)) {
hs.put(cnt, 1);
}
else {
hs.put(cnt, hs.get(cnt) + 1);
}
}
solvemin(hs, n, k);
solvemax(hs, n, k);
}
public static void main(String[] args) {
(new Main()).run();
}
public void run() {
in = new Input();
try {
out = new PrintWriter(System.out);
//out = new PrintWriter(new FileWriter("a.out"));
}
catch (Exception ex) {
}
long stime = System.currentTimeMillis();
//int test = in.nextInt(); while (test-- > 0)
solve();
if (System.getProperty("ONLINE_JUDGE") == null) {
out.println("\nTime elapsed: " + (System.currentTimeMillis() - stime) + "ms");
}
out.close();
}
public class Input {
StringTokenizer token = null;
BufferedReader in;
public Input() {
try {
if (System.getProperty("ONLINE_JUDGE") == null) {
in = new BufferedReader(new InputStreamReader(System.in));
//in = new BufferedReader(new FileReader("in.txt"));
}
else {
in = new BufferedReader(new InputStreamReader(System.in));
}
}
catch (Exception ex) {
}
}
int nextInt() {
return Integer.parseInt(nextString());
}
long nextLong() {
return Long.parseLong(nextString());
}
double nextDouble() {
return Double.parseDouble(nextString());
}
String nextString() {
try {
while (token == null || !token.hasMoreTokens()) {
token = new StringTokenizer(in.readLine());
}
}
catch (IOException e) {
}
return token.nextToken();
}
}
} | Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output | |
PASSED | 1fe3e233711f3f668293b7d3199e2bd5 | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | //package eightvc.e;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class F {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni(), K = ni();
int[] f = na(n);
for(int i = 0;i < n;i++)f[i]--;
int[] cs = splitIntoCycleSizes(f);
Arrays.sort(cs);
// min
{
int m = (n+1)>>>6;
m++;
long[] dp = new long[m];
long[] temp = new long[m];
dp[0] = 1L<<0;
for(int i = 0;i < cs.length;){
int j = i;
while(j < cs.length && cs[j] == cs[i])j++;
int k = j-i;
for(int d = 1;d <= k;d*=2){
k -= d;
copy(dp, 0, (m<<6)-cs[i]*d, temp, 0);
or(temp, 0, (m<<6)-cs[i]*d, dp, cs[i]*d);
}
if(k > 0){
copy(dp, 0, (m<<6)-cs[i]*k, temp, 0);
or(temp, 0, (m<<6)-cs[i]*k, dp, cs[i]*k);
}
i = j;
}
if(dp[K>>>6]<<~K<0){
out.print(K + " ");
}else{
out.print(K + 1 + " ");
}
}
// max
{
int L = K;
int dead = 0;
for(int i = 0;i < cs.length;i++){
while(cs[i] >= 2 && L >= 1){
cs[i] -= 2;
L--;
dead += 2;
}
}
for(int i = 0;i < cs.length;i++){
while(cs[i] >= 1 && L >= 1){
cs[i]--;
L--;
dead++;
}
}
out.println(dead);
}
}
public static void copy(long[] from, int fl, int fr, long[] to, int tl)
{
if(!(fl >= 0 && fl < from.length<<6))return;
if(!(fr >= 0 && fr <= from.length<<6))return;
if(!(tl >= 0 && tl < to.length<<6))return;
if(!(tl+(fr-fl) >= 0 && tl+(fr-fl) <= to.length<<6))return;
if(fl > fr)return;
int tr = tl+(fr-fl);
for(int l1 = fl, l2 = Math.min(fr, (fl>>>6)+1<<6), r1 = tl, r2 = Math.min(tr, (tl>>>6)+1<<6);l1 < fr;){
if(l2-l1 <= r2-r1){
long f = from[l2-1>>>6]<<-l2>>>-l2+l1;
to[l2-l1+r1-1>>>6] &= ~((1L<<r2-1)-(1L<<r1)|1L<<r2-1);
to[l2-l1+r1-1>>>6] |= f<<r1;
r1 += l2-l1;
l1 = l2;
l2 = Math.min(fr, (l1>>>6)+1<<6);
if(r2 - r1 == 0){
r2 = Math.min(tr, (r1>>>6)+1<<6);
}
}else{
long f = from[r2-r1+l1-1>>>6]<<-(r2-r1+l1)>>>-(r2-r1+l1)+l1;
to[r2-1>>>6] &= ~((1L<<r2-1)-(1L<<r1)|1L<<r2-1);
to[r2-1>>>6] |= f<<r1;
l1 += r2-r1;
r1 = r2;
r2 = Math.min(tr, (r1>>>6)+1<<6);
if(l2 - l1 == 0){
l2 = Math.min(fr, (l1>>>6)+1<<6);
}
}
}
}
public static void or(long[] from, int fl, int fr, long[] to, int tl)
{
if(!(fl >= 0 && fl < from.length<<6))throw new RuntimeException();
if(!(fr >= 0 && fr <= from.length<<6))throw new RuntimeException();
if(!(tl >= 0 && tl < to.length<<6))throw new RuntimeException();
if(!(tl+(fr-fl) >= 0 && tl+(fr-fl) <= to.length<<6))throw new RuntimeException();
if(fl >= fr)return;
int tr = tl+(fr-fl);
for(int l1 = fl, l2 = Math.min(fr, (fl>>>6)+1<<6), r1 = tl, r2 = Math.min(tr, (tl>>>6)+1<<6);l1 < fr;){
if(l2-l1 <= r2-r1){
long f = from[l2-1>>>6]<<-l2>>>-l2+l1;
to[l2-l1+r1-1>>>6] |= f<<r1;
r1 += l2-l1;
l1 = l2;
l2 = Math.min(fr, (l1>>>6)+1<<6);
if(r2 - r1 == 0){
r2 = Math.min(tr, (r1>>>6)+1<<6);
}
}else{
long f = from[r2-r1+l1-1>>>6]<<-(r2-r1+l1)>>>-(r2-r1+l1)+l1;
to[r2-1>>>6] |= f<<r1;
l1 += r2-r1;
r1 = r2;
r2 = Math.min(tr, (r1>>>6)+1<<6);
if(l2 - l1 == 0){
l2 = Math.min(fr, (l1>>>6)+1<<6);
}
}
}
}
public static int[] splitIntoCycleSizes(int[] f)
{
int n = f.length;
int[] szs = new int[n];
boolean[] ved = new boolean[n];
int q = 0;
for(int i = 0;i < n;i++){
if(!ved[i]){
int p = 0;
for(int cur = i;!ved[cur];cur = f[cur], p++)ved[cur] = true;
szs[q++] = p;
}
}
return Arrays.copyOf(szs, q);
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new F().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output | |
PASSED | 31b1744625d28634464b5f6031af1e43 | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | import javax.print.attribute.IntegerSyntax;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.StringTokenizer;
/**
* Created by Meepo on 3/11/2017.
*/
public class F {
public static void main(String[] args) {
new F().run();
}
BufferedReader br;
StringTokenizer st;
PrintWriter out;
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int[] p = new int[n];
for (int i = 0; i < n; i++) {
p[i] = nextInt() - 1;
}
int max = 0;
int[] cnt = new int[n + 1];
for (int i = 0; i < n; i++) {
if (p[i] == -1) {
continue;
}
int x = i;
int l = 0;
while (p[x] != -1) {
int lx = x;
x = p[x];
p[lx] = -1;
l++;
}
cnt[l]++;
max += l / 2;
}
max = k < max ? 2 * k : Math.min(n, k + max);
int rk = k;
k = Math.min(k, n - k);
if (k == 0) {
out.println(rk + " " + max);
return;
}
int[] best = new int[k + 1];
Arrays.fill(best, -1);
best[0] = 0;
int[] time = new int[k + 1];
for (int i = 1; i < cnt.length; i++) {
if (cnt[i] == 0) {
continue;
}
for (int j = 0; j < best.length - i; j++) {
if (best[j] == -1)
continue;
if (time[j] != i) {
time[j] = i;
best[j] = 0;
}
}
for (int j = 0; j < best.length - i; j++) {//
if (best[j] == -1 ||best[j] == cnt[i]) {
continue;
}
if (time[j + i] != i || best[j] + 1 < best[i + j]) {
time[j + i] = i;
best[j + i] = best[j] + 1;
}
}
if (best[k] != -1) {
out.println(rk + " " + max);
return;
}
}
out.println((rk + 1) + " " + max);
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output | |
PASSED | 37305fcdf9cfe3fb07667ed7bc2fe8df | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | import javax.print.attribute.IntegerSyntax;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.StringTokenizer;
/**
* Created by Meepo on 3/11/2017.
*/
public class F {
public static void main(String[] args) {
new F().run();
}
BufferedReader br;
StringTokenizer st;
PrintWriter out;
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int[] p = new int[n];
for (int i = 0; i < n; i++) {
p[i] = nextInt() - 1;
}
int max = 0;
int[] cnt = new int[n + 1];
for (int i = 0; i < n; i++) {
if (p[i] == -1) {
continue;
}
int x = i;
int l = 0;
while (p[x] != -1) {
int lx = x;
x = p[x];
p[lx] = -1;
l++;
}
cnt[l]++;
max += l / 2;
}
max = k < max ? 2 * k : Math.min(n, k + max);
int rk = k;
k = Math.min(k, n - k);
if (k == 0) {
out.println(rk + " " + max);
return;
}
int[] best = new int[k + 1];
Arrays.fill(best, -1);
best[0] = 0;
int[] time = new int[k + 1];
for (int i = 1; i < cnt.length; i++) {
if (cnt[i] == 0) {
continue;
}
for (int j = 0; j < best.length - i; j++) {
if (best[j] == -1)
continue;
if (time[j] != i) {
time[j] = i;
best[j] = 0;
}
}
for (int j = 0; j < best.length - i; j++) {//////
if (best[j] == -1 ||best[j] == cnt[i]) {
continue;
}
if (time[j + i] != i || best[j] + 1 < best[i + j]) {
time[j + i] = i;
best[j + i] = best[j] + 1;
}
}
if (best[k] != -1) {
out.println(rk + " " + max);
return;
}
}
out.println((rk + 1) + " " + max);
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output | |
PASSED | 988eb2f259d9691ebfb542a6a9ac2217 | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | import javax.print.attribute.IntegerSyntax;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.StringTokenizer;
/**
* Created by Meepo on 3/11/2017.
*/
public class F {
public static void main(String[] args) {
new F().run();
}
BufferedReader br;
StringTokenizer st;
PrintWriter out;
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int[] p = new int[n];
for (int i = 0; i < n; i++) {
p[i] = nextInt() - 1;
}
int max = 0;
int[] cnt = new int[n + 1];
for (int i = 0; i < n; i++) {
if (p[i] == -1) {
continue;
}
int x = i;
int l = 0;
while (p[x] != -1) {
int lx = x;
x = p[x];
p[lx] = -1;
l++;
}
cnt[l]++;
max += l / 2;
}
max = k < max ? 2 * k : Math.min(n, k + max);
int rk = k;
k = Math.min(k, n - k);
if (k == 0) {
out.println(rk + " " + max);
return;
}
int[] current = new int[k + 1];
current[0] = 1;
for (int i = 2; i <= k; i++) {
if (cnt[i] == 0) {
continue;
}
for (int j = 0; j < i; j++) {
current[j] = current[j] <= 0 ? 0 : cnt[i] + 1;
}
for (int j = i; j <= k; j++) {
current[j] = current[j] <= 0 ? current[j - i] - 1 : cnt[i] + 1;
}
if (current[k] > 0) {
out.println(rk + " " + max);
return;
}
}
// int[] best = new int[k + 1];
// Arrays.fill(best, -1);
// best[0] = 0;
// int[] time = new int[k + 1];
// for (int i = 1; i < cnt.length; i++) {
// if (cnt[i] == 0) {
// continue;
// }
// for (int j = 0; j < best.length - i; j++) {
// if (time[j] != i) {
// time[j] = i;
// best[j] = 0;
// }
// if (best[j] == cnt[i] || best[j] == -1) {
// continue;
// }
// if (time[j + i] != i || best[j] + 1 < best[i + j]) {
// time[j + i] = i;
// best[j + i] = best[j] + 1;
// }
// }
// if (best[k] != -1) {
// out.println(rk + " " + max);
// return;
// }
// }
out.println((rk + 1) + " " + max);
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output | |
PASSED | ca8717e7f540379c85d179f20c8b22cc | train_001.jsonl | 1484499900 | It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i.Unfortunately, Balls are quite clumsy. We know earlier that exactly k of them will forget to bring their gift. A Ball number i will get his present if the following two constraints will hold: Ball number i will bring the present he should give. Ball x such that px = i will bring his present. What is minimum and maximum possible number of kids who will not get their present if exactly k Balls will forget theirs? | 256 megabytes | import javax.print.attribute.IntegerSyntax;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.StringTokenizer;
/**
* Created by Meepo on 3/11/2017.
*/
public class F {
public static void main(String[] args) {
new F().run();
}
BufferedReader br;
StringTokenizer st;
PrintWriter out;
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int[] p = new int[n];
for (int i = 0; i < n; i++) {
p[i] = nextInt() - 1;
}
int max = 0;
int[] cnt = new int[n + 1];
for (int i = 0; i < n; i++) {
if (p[i] == -1) {
continue;
}
int x = i;
int l = 0;
while (p[x] != -1) {
int lx = x;
x = p[x];
p[lx] = -1;
l++;
}
cnt[l]++;
max += l / 2;
}
max = k < max ? 2 * k : Math.min(n, k + max);
int rk = k;
k = Math.min(k, n - k);
if (k == 0) {
out.println(rk + " " + max);
return;
}
int[] best = new int[k + 1];
Arrays.fill(best, -1);
best[0] = 0;
int[] time = new int[k + 1];
for (int i = 1; i < cnt.length; i++) {
if (cnt[i] == 0) {
continue;
}
for (int j = 0; j < best.length - i; j++) {
if (best[j] == -1)
continue;
if (time[j] != i) {
time[j] = i;
best[j] = 0;
}
}
for (int j = 0; j < best.length - i; j++) {
if (best[j] == -1 ||best[j] == cnt[i]) {
continue;
}
if (time[j + i] != i || best[j] + 1 < best[i + j]) {
time[j + i] = i;
best[j + i] = best[j] + 1;
}
}
if (best[k] != -1) {
out.println(rk + " " + max);
return;
}
}
out.println((rk + 1) + " " + max);
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| Java | ["5 2\n3 4 1 5 2", "10 1\n2 3 4 5 6 7 8 9 10 1"] | 1.5 seconds | ["2 4", "2 2"] | NoteIn the first sample, if the third and the first balls will forget to bring their presents, they will be th only balls not getting a present. Thus the minimum answer is 2. However, if the first ans the second balls will forget to bring their presents, then only the fifth ball will get a present. So, the maximum answer is 4. | Java 8 | standard input | [
"dp",
"bitmasks",
"greedy"
] | a0ddb8f02a91865dc65a214f1de111e3 | The first line of input contains two integers n and k (2 ≤ n ≤ 106, 0 ≤ k ≤ n), representing the number of Balls and the number of Balls who will forget to bring their presents. The second line contains the permutation p of integers from 1 to n, where pi is the index of Ball who should get a gift from the i-th Ball. For all i, pi ≠ i holds. | 2,600 | You should output two values — minimum and maximum possible number of Balls who will not get their presents, in that order. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.