On JVM (Java & Kotlin) the default System.out is configured with auto-flush on each line which makes it very slow on problems with many lines in the output. To work around it, while still being able to use standard output functions (like Kotlin's println), we can reconfigure output without autoflush like this:
However, running this code results in the following exception:
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "readFileDescriptor")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkRead(SecurityManager.java:864)
at java.io.FileInputStream.<init>(FileInputStream.java:171)
Once the above is fixed fixed, there will be the following exception on an attempt to do System.setOut:
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setIO")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.System.checkIO(System.java:253)
On JVM (Java & Kotlin) the default
System.out
is configured with auto-flush on each line which makes it very slow on problems with many lines in the output. To work around it, while still being able to use standard output functions (like Kotlin'sprintln
), we can reconfigure output without autoflush like this:However, running this code results in the following exception:
Once the above is fixed fixed, there will be the following exception on an attempt to do
System.setOut
:Here is an example of submission using this approach for fast output: https://codeforces.com/contest/1322/submission/72937574
Expected behavior: it should work.