Untitled
unknown
plain_text
2 years ago
7.6 kB
2
Indexable
Never
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result { /* * Complete the 'maxDias' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER N * 2. INTEGER p * 3. INTEGER q * 4. INTEGER r */ public static int maxDias(int N, int p, int q, int r) { int paux=0; int qaux=0; int raux=0; ArrayList<Integer> arrp = new ArrayList<Integer>(); ArrayList<Integer> arrq = new ArrayList<Integer>(); ArrayList<Integer> arrr = new ArrayList<Integer>(); ArrayList<Integer> arrauxp = new ArrayList<Integer>(); ArrayList<Integer> arrauxq = new ArrayList<Integer>(); ArrayList<Integer> arrauxr = new ArrayList<Integer>(); for(int i=1; i<=N; i++){ if(p*i<=N){ paux=(p*i); arrauxp.add(paux); arrp.add(paux);} if(q*i<=N){ qaux=(q*i); arrauxq.add(qaux); arrq.add(qaux);} if(r*i<=N){ raux=(r*i); arrauxr.add(raux); arrr.add(raux);} } if(p<=0){ arrauxp.clear(); arrp.clear(); } if (q<=0){ arrauxq.clear(); arrq.clear(); } if (r<=0){ arrauxr.clear(); arrr.clear(); } if (p==q && p==r){ return 0; } if (p==q) { arrauxp.clear(); arrauxq.clear(); arrauxr.removeAll(arrp); arrauxr.removeAll(arrq); } else if (p==r){ arrauxp.clear(); arrauxr.clear(); arrauxq.removeAll(arrp); arrauxq.removeAll(arrr); } else if (q==r){ arrauxq.clear(); arrauxr.clear(); arrauxp.removeAll(arrq); arrauxp.removeAll(arrr); } if(p<q && p<r) { for (int i=0;i< arrq.size();i++) { if (arrauxp.contains(arrq.get(i))) { arrauxp.removeAll(arrq); arrauxq.removeAll(arrp); } } for (int i=0;i< arrr.size();i++){ if (arrauxp.contains(arrr.get(i))) { arrauxp.removeAll(arrr); arrauxr.removeAll(arrp); } } } if(q<p && q<r) { for (int i=0;i< arrp.size();i++) { if (arrauxq.contains(arrp.get(i))) { arrauxq.removeAll(arrp); arrauxp.removeAll(arrq); } } for (int i=0;i< arrr.size();i++) { if (arrauxq.contains(arrr.get(i))){ arrauxq.removeAll(arrr); arrauxr.removeAll(arrq); } } } if(r<p && r<q) { for (int i=0;i< arrp.size();i++) { if (arrauxr.contains(arrp.get(i))) { arrauxr.removeAll(arrp); arrauxp.removeAll(arrr); } } for (int i = 0; i < arrq.size(); i++) { if (arrauxr.contains(arrq.get(i))) { arrauxr.removeAll(arrq); arrauxq.removeAll(arrr); } } } /* if(p<q && p<r){ if(arrauxp.containsAll(arrq)){ arrauxp.removeAll(arrq); arrauxq.clear(); System.out.println(arrauxp); System.out.println(arrauxq); System.out.println(arrauxq.size()); } if(arrauxp.containsAll(arrr)){ arrauxp.removeAll(arrr); arrauxr.clear(); System.out.println(arrauxp); System.out.println(arrauxr); System.out.println(arrauxr.size()); }else { arrauxp.removeAll(arrauxq); arrauxq.removeAll(arrp); System.out.println(arrauxp); System.out.println(arrauxq); System.out.println(arrauxq.size()); } } if(q<p && q<r) { if (arrauxq.containsAll(arrp)) { arrauxq.removeAll(arrp); arrauxp.clear(); System.out.println(arrauxq); System.out.println(arrauxp); System.out.println(arrauxp.size()); } if (arrauxq.containsAll(arrr)) { arrauxq.removeAll(arrr); arrauxp.clear(); System.out.println(arrauxq); System.out.println(arrauxr); System.out.println(arrauxr.size()); } else { arrauxq.removeAll(arrauxp); arrauxp.removeAll(arrp); System.out.println(arrauxq); System.out.println(arrauxp); System.out.println(arrauxp.size()); } } if(r<p && r<q) { if (arrauxr.containsAll(arrp)) { arrauxr.removeAll(arrp); arrauxp.clear(); System.out.println(arrauxr); System.out.println(arrauxp); System.out.println(arrauxp.size()); } else { arrauxr.removeAll(arrauxp); arrauxp.removeAll(arrp); System.out.println(arrauxr); System.out.println(arrauxp); System.out.println(arrauxp.size()); } } */ return (arrauxp.size()+arrauxq.size()+arrauxr.size()); } } public class TareaEda { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out)); int T = Integer.parseInt(bufferedReader.readLine().trim()); IntStream.range(0, T).forEach(TItr -> { try { String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); int dias = Integer.parseInt(firstMultipleInput[0]); int A = Integer.parseInt(firstMultipleInput[1]); int B = Integer.parseInt(firstMultipleInput[2]); int C = Integer.parseInt(firstMultipleInput[3]); int resultado = Result.maxDias(dias, A, B, C); bufferedWriter.write(String.valueOf(resultado)); bufferedWriter.newLine(); } catch (IOException ex) { throw new RuntimeException(ex); } }); bufferedReader.close(); bufferedWriter.close(); } }