Advertisement
Guest User

Untitled

a guest
Sep 5th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Swordfish {
  5.     public static void main(String[] args) throws Exception {
  6.         new Main().run();
  7.     }
  8. }
  9.  
  10. class Main {
  11.    
  12.     BufferedReader reader;
  13.     StringTokenizer st;
  14.     PrintWriter out;
  15.    
  16.     Integer n, cnt;
  17.     Integer[] place, answer;
  18.    
  19.     void run() throws Exception {
  20.         out = new PrintWriter(new FileWriter("race.out"));
  21.         reader = new BufferedReader(new FileReader("race.in"));
  22.        
  23.         n = Integer.decode(reader.readLine());
  24.         place = new Integer[n];
  25.         answer = new Integer[n];
  26.         cnt = 0;
  27.         answer[cnt++] = n - 1;
  28.        
  29.         st = new StringTokenizer(reader.readLine());
  30.        
  31.         for (int i = 0; i < n; i++) {
  32.             place[i] = Integer.decode(st.nextToken()) - 1;
  33.         }
  34.        
  35.         int m = place[n - 1];
  36.        
  37.         for (int k = n - 2; k >= 0; k--) {
  38.            
  39.             if (m == k + 1) {
  40.                 answer[cnt++] = k;
  41.             }
  42.            
  43.             if (place[k] < m)
  44.                 m = place[k];
  45.         }
  46.        
  47.         out.printf("%d%n", cnt);
  48.        
  49.         for (int i = cnt - 1; i >= 0; i--)
  50.             out.printf("%d ", answer[i] + 1);
  51.        
  52.         out.printf("%n");
  53.        
  54.         reader.close();
  55.         out.close();
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement