Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Reversi {
  5.  
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8. int n = sc.nextInt();
  9. int [] ways = new int[200001];
  10. ArrayList<Integer> stones = new ArrayList<>();
  11.  
  12. int current = sc.nextInt();
  13. stones.add(current);
  14. for(int i = 1; i < n; i++){
  15. current = sc.nextInt();
  16. if (current != stones.get(stones.size()-1)){
  17. stones.add(current);
  18. }
  19.  
  20.  
  21. }
  22. int [] count = new int[stones.size()];
  23. count[0] = 1;
  24. ways[stones.get(0)] = 1;
  25. for (int i = 1; i < stones.size();i++){
  26. count[i] = (count[i - 1] + ways[stones.get(i)]) % 1_000_000_007;
  27. ways[stones.get(i)] = count[i];
  28. }
  29.  
  30. System.out.println(count[stones.size() - 1]);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement