fork download
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.util.Hashtable;
  4. import java.util.StringTokenizer;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. static Long counter = (long)0;
  10. public static void main (String[] args)
  11. {
  12. System.out.println(Runtime.getRuntime().freeMemory() / 1000000.0 + "MB free");
  13.  
  14. try {
  15.  
  16. int user_choice= Integer.parseInt(ob1.readLine());
  17.  
  18. int flag=0;
  19. while(user_choice!=0)
  20. {
  21. user_choice--;
  22. Long n,k;
  23. obj=new StringTokenizer(ob1.readLine());
  24. n=Long.parseLong(obj.nextToken());
  25. k=Long.parseLong(obj.nextToken());
  26. Hashtable<Long, Long> hash= new Hashtable<Long, Long>();
  27. while(n!=0)
  28. {
  29. Long start,comp;
  30. Long finish;
  31. obj1=new StringTokenizer(ob1.readLine());
  32. start=Long.parseLong(obj1.nextToken());
  33. finish=Long.parseLong(obj1.nextToken());
  34. comp=Long.parseLong(obj1.nextToken());
  35. if(flag==0)
  36. {
  37. for(int i=1;i<=k;i++)
  38. {
  39. hash.put((long)i,(long)0);
  40. }
  41.  
  42. }
  43. Long finish1;
  44. finish1=hash.get(comp);
  45. if(finish1==0)
  46. {
  47. hash.put(comp,finish);
  48. counter++;
  49. }
  50. else if(finish1<=start)
  51. {
  52. counter++;
  53. hash.put(comp,finish);
  54. }
  55. n--;
  56. flag=1;
  57. }
  58. flag=0;
  59. System.out.println(counter);
  60. counter=(long)0;
  61. /* for(int i=1;i<=k;i++)
  62.   System.out.println(hash.get((long)i) +" "+i );*/
  63.  
  64. }
  65.  
  66. } catch(Throwable t) {
  67. System.out.println(t.getClass().getName() + " " + t.getMessage());
  68. System.out.println();
  69. for(StackTraceElement elem : t.getStackTrace()) {
  70. System.out.println(elem);
  71. }
  72. }
  73. }
  74. }
Success #stdin #stdout 4.63s 380608KB
stdin
2
3 300000
1 3 1
4 6 2
7 10 3
3 10000000
1 3 1
4 6 2
7 10 3
stdout
15.87436MB free
3
java.lang.OutOfMemoryError Java heap space

java.util.Hashtable.rehash(Hashtable.java:496)
java.util.Hashtable.put(Hashtable.java:560)
Ideone.main(Main.java:42)