結果

提出番号 1821
提出者 inmir
言語 Java
提出日時 2018-08-04 14:05:31
問題名 (71)音楽ゲーム
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 96ms 100560KB
2 AC 100% 75ms 99136KB
3 AC 100% 87ms 101120KB
4 AC 100% 122ms 104400KB
5 AC 100% 99ms 102560KB
6 AC 100% 87ms 102416KB
7 AC 100% 64ms 97792KB
8 AC 100% 120ms 103776KB
9 AC 100% 111ms 104976KB
10 AC 100% 100ms 102608KB
11 AC 100% 94ms 102320KB
12 AC 100% 110ms 106944KB
13 AC 100% 77ms 101520KB
14 AC 100% 105ms 111792KB
15 AC 100% 96ms 100240KB
16 AC 100% 82ms 96000KB
17 AC 100% 109ms 106112KB
18 AC 100% 111ms 106368KB
19 AC 100% 96ms 101424KB
20 AC 100% 130ms 107392KB
21 AC 100% 121ms 107328KB
22 AC 100% 98ms 105136KB
23 AC 100% 121ms 111984KB
24 AC 100% 78ms 98432KB
25 AC 100% 139ms 113584KB
26 AC 100% 107ms 105808KB
27 AC 100% 115ms 106800KB
28 AC 100% 151ms 112528KB
29 AC 100% 121ms 112592KB
30 AC 100% 167ms 114752KB

ソースコード

import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Set; 

class Main{ 

	static void solve(){ 
		int n = ni();
		int[] a = nia(n);
		boolean[] used = new boolean[100001];
		long mod = (long)1e9+7;
		Arrays.sort(a);
		long[] dp = new long[n+1];
		long sum=0;
		for(int i=0;i<n;++i){
			if(used[a[i]]){
				dp[i]=dp[i-1];
			}else{
				used[a[i]]=true;
				dp[i]=(i==0 ? 1:sum);
			}
			sum = (sum+dp[i])%mod;
		}
		out.println(sum);
	} 
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
}