El jueves, 18 de abril de 2019, 16:47:23 (UTC+2), Geoff escribió: > Hi all, > > During Round 1A I wasn't able to get the interactive judge to interact, so > I'm hoping some kind person can tell me why before the next round. I don't > recall having an issue with the Number Guessing practice problem, but didn't > attempt the interactive problem from the qualifier round because I had a very > busy time that week. > > I imagine this is one of those cases where I've done something obviously > silly. I am using Java and reading through standard input using a Scanner. I > can get code to complete if it doesn't try to read input after printing a > list of 18 numbers (but obviously this gets a wrong answer); this suggests to > me that I am reading the initial parameters T, N, and M successfully. > > Below is some minimal code to try to get some interaction, which receives > TLE. Alternatively, does anyone have some Java code for the interaction that > I could look at? Much thanks in advance! > > --------------------------------------------------- > import java.util.Scanner; > > public class Solution{ > > int caseNumber = 0; > > static Scanner sc = new Scanner(System.in); > > public static void main(String[] args){ > > Solution sol = new Solution(); > > int T = sc.nextInt(); > int N = sc.nextInt(); > int M = sc.nextInt(); > > for (int i = 1; i <= T; i++){ > sol.caseNumber = i; > > for (int j = 0; j <= 6; j++){ > System.out.println("5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5"); > for(int k = 0; k < 18; k++){ > sc.nextInt(); // If I comment out this line, the code > completes > } > > } > > System.out.println(5); > } > > sc.close(); > } > > public Solution() { > > } > > } > ---------------------------------------------------- > Cheers, > Geoff
I think the problem is that you need to flush the buffer after printing, i.e. include a "System.out.flush()" right after each "println()" (or at least before you read anything). It may not be the problem in your case, or not the only one, but at least this is a good practice advised in the FAQs. In case you have other issues, here's a java code that passes the tests: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Locale; import java.util.Scanner; public class Solution { public static void main(String[] args) { Locale.setDefault(Locale.ENGLISH); Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); solve(in, System.out); in.close(); } protected static void solve(Scanner in, PrintStream out) { int t = in.nextInt(); int n = in.nextInt(); int m = in.nextInt(); for (int i = 1; i <= t; ++i) { String ret = solveLine(in, n, m, i); if (!ret.equals("1")) { break; } } } protected static String solveLine(Scanner in, int n, int m, int t) { int[] coprimes = { 3, 5, 7, 11, 13, 17, 4 }; int[] mod = new int[coprimes.length]; int ans = 0; for (int i = 0; i < coprimes.length; i++) { int prime = coprimes[i]; String qry = generateQuery(prime); int[] resp = getResp(in, qry); int sum = 0; for (int j = 0; j < resp.length; j++) { sum += resp[j]; } mod[i] = sum % coprimes[i]; } ans = mod[0]; int prod = 1; for (int j = 0; j < mod.length; j++) { for (int i = 0; i < coprimes[j]; i++) { if (ans % coprimes[j] == mod[j]) break; ans += prod; } prod *= coprimes[j]; } return getAnswer(in, ans); } private static String generateQuery(int len) { String qry = ""; for (int i = 0; i < 18; i++) { if (i != 0) qry += " "; qry += len; } return qry; } static int[] getResp(Scanner in, String qry) { System.out.print(qry); System.out.println(); System.out.flush(); int[] resp = new int[18]; for (int i = 0; i < 18; i++) { resp[i] = in.nextInt(); } return resp; } static String getAnswer(Scanner in, int qry) { System.out.print(qry); System.out.println(); System.out.flush(); return in.next(); } } -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/80ec2489-15f8-4dcf-bff5-570fb9f06dd2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.