結果
問題 | No.797 Noelちゃんとピラミッド |
ユーザー | Suunn |
提出日時 | 2019-03-15 21:26:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 7,544 bytes |
コンパイル時間 | 2,440 ms |
コンパイル使用メモリ | 82,864 KB |
実行使用メモリ | 46,400 KB |
最終ジャッジ日時 | 2024-07-01 20:20:14 |
合計ジャッジ時間 | 16,256 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 83 ms
45,088 KB |
testcase_01 | AC | 82 ms
45,124 KB |
testcase_02 | AC | 81 ms
45,076 KB |
testcase_03 | AC | 285 ms
46,400 KB |
testcase_04 | AC | 284 ms
46,240 KB |
testcase_05 | AC | 285 ms
46,288 KB |
testcase_06 | AC | 285 ms
46,220 KB |
testcase_07 | AC | 282 ms
46,340 KB |
testcase_08 | AC | 284 ms
46,108 KB |
testcase_09 | AC | 284 ms
46,284 KB |
testcase_10 | AC | 284 ms
46,284 KB |
testcase_11 | AC | 285 ms
46,180 KB |
testcase_12 | AC | 284 ms
46,240 KB |
testcase_13 | AC | 283 ms
46,348 KB |
testcase_14 | AC | 283 ms
46,240 KB |
testcase_15 | AC | 286 ms
46,160 KB |
testcase_16 | AC | 282 ms
46,332 KB |
testcase_17 | AC | 282 ms
46,260 KB |
testcase_18 | AC | 285 ms
46,284 KB |
testcase_19 | AC | 285 ms
46,340 KB |
testcase_20 | AC | 284 ms
46,352 KB |
testcase_21 | AC | 285 ms
46,356 KB |
testcase_22 | AC | 285 ms
46,128 KB |
testcase_23 | AC | 235 ms
46,236 KB |
testcase_24 | AC | 144 ms
46,172 KB |
testcase_25 | AC | 213 ms
46,272 KB |
testcase_26 | AC | 212 ms
46,300 KB |
testcase_27 | AC | 281 ms
46,312 KB |
testcase_28 | AC | 264 ms
46,236 KB |
testcase_29 | AC | 128 ms
46,264 KB |
testcase_30 | AC | 142 ms
46,240 KB |
testcase_31 | AC | 238 ms
46,320 KB |
testcase_32 | AC | 163 ms
46,228 KB |
testcase_33 | AC | 214 ms
46,320 KB |
testcase_34 | AC | 183 ms
46,300 KB |
testcase_35 | AC | 286 ms
46,140 KB |
testcase_36 | AC | 126 ms
46,376 KB |
testcase_37 | AC | 263 ms
46,352 KB |
testcase_38 | AC | 270 ms
46,360 KB |
testcase_39 | AC | 211 ms
46,188 KB |
testcase_40 | AC | 123 ms
46,088 KB |
testcase_41 | AC | 134 ms
46,268 KB |
testcase_42 | AC | 207 ms
46,324 KB |
testcase_43 | AC | 85 ms
45,356 KB |
testcase_44 | AC | 84 ms
45,308 KB |
testcase_45 | AC | 85 ms
45,132 KB |
testcase_46 | AC | 82 ms
44,900 KB |
testcase_47 | AC | 83 ms
45,060 KB |
testcase_48 | AC | 82 ms
45,096 KB |
testcase_49 | AC | 81 ms
45,076 KB |
testcase_50 | AC | 85 ms
45,176 KB |
testcase_51 | AC | 85 ms
45,124 KB |
testcase_52 | AC | 84 ms
45,172 KB |
testcase_53 | AC | 83 ms
45,048 KB |
testcase_54 | AC | 82 ms
44,964 KB |
testcase_55 | AC | 86 ms
45,264 KB |
testcase_56 | AC | 85 ms
45,316 KB |
testcase_57 | AC | 84 ms
45,148 KB |
testcase_58 | AC | 82 ms
45,016 KB |
testcase_59 | AC | 83 ms
45,228 KB |
testcase_60 | AC | 84 ms
44,860 KB |
testcase_61 | AC | 82 ms
45,180 KB |
testcase_62 | AC | 85 ms
45,356 KB |
ソースコード
import java.io.IOException; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Comparator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.PriorityQueue; import java.util.TreeSet; public class Main{ public static void main(String[] args){ FastScanner sc = new FastScanner(); Mathplus mp = new Mathplus(); int N = sc.nextInt(); long ans = 0; for(int i=0;i<N;i++){ ans += sc.nextLong() * mp.comb(N-1,i); ans %= 1000000007; } System.out.println(ans); } } class UnionFindTree { int[] root; int[] rank; UnionFindTree(int N){ root = new int[N]; rank = new int[N]; for(int i=0;i<N;i++){ root[i] = i; } } public int find(int x){ if(root[x]==x){ return x; }else{ return find(root[x]); } } public void unite(int x,int y){ x = find(x); y = find(y); if(x==y){ return; }else{ if(rank[x]<rank[y]){ root[x] = y; }else{ root[y] = x; if(rank[x]==rank[y]){ rank[x]++; } } } } public boolean same(int x,int y){ return find(x)==find(y); } } class Graph { ArrayList<Edge>[] list; int size; @SuppressWarnings("unchecked") Graph(int N){ size = N; list = new ArrayList[N]; for(int i=0;i<N;i++){ list[i] = new ArrayList<Edge>(); } } void addEdge(int a,int b){ list[a].add(new Edge(b,1)); } void addWeightedEdge(int a,int b,int c){ list[a].add(new Edge(b,c)); } void addEgdes(int[] a,int[] b){ int size = a.length; for(int i=0;i<size;i++){ list[a[i]].add(new Edge(b[i],1)); } } void addWeighterEdges(int[] a ,int[] b ,int[] c){ int size = a.length; for(int i=0;i<size;i++){ list[a[i]].add(new Edge(b[i],c[1])); } } long[] bfs(int s){ long[] L = new long[size]; for(int i=0;i<size;i++){ L[i] = -1; } L[s] = 0; ArrayDeque<Integer> Q = new ArrayDeque<Integer>(); Q.add(s); while(!Q.isEmpty()){ int v = Q.poll(); for(Edge e:list[v]){ int w = e.to; long c = e.cost; if(L[w]==-1){ L[w] = L[v] + c; Q.add(w); } } } return L; } long[] dijkstra(int s){ long[] L = new long[size]; for(int i=0;i<size;i++){ L[i] = -1; } int[] visited = new int[size]; L[s] = 0; PriorityQueue<Pair> Q = new PriorityQueue<Pair>(new SampleComparator()); Q.add(new Pair(0,s)); while(!Q.isEmpty()){ Pair C = Q.poll(); if(visited[(int)C.b]==0){ L[(int)C.b] = C.a; visited[(int) C.b] = 1; for(Edge D:list[(int) C.b]){ Q.add(new Pair(L[(int)C.b]+D.cost,D.to)); } } } return L; } long Kruskal(){ long ans = 0; UnionFindTree UF = new UnionFindTree(size); TreeSet<LinkEdge> Edges = new TreeSet<LinkEdge>(new LinkEdgeComparator()); for(LinkEdge e:Edges){ if(!UF.same(e.a,e.b)){ ans += e.L; UF.unite(e.a,e.b); } } return ans; } } class LinkEdge{ long L; int a ; int b; LinkEdge(long l,int A,int B){ L = l; a = A; b = B; } public boolean equals(Object o){ LinkEdge O = (LinkEdge) o; if(O.a==this.a&&O.b==this.b&&O.L==this.L){ return true; }else{ return false; } } public int hashCode(){ return Objects.hash(L,a,b); } } class Edge{ int to; long cost; Edge(int a,long b){ to = a; cost = b; } } class LinkEdgeComparator implements Comparator<LinkEdge>{ public int compare(LinkEdge P, LinkEdge Q) { long temp = P.L-Q.L; if(temp==0){ if(P.a>Q.a){ return 1; }else{ if(P.b>Q.b){ return 1; }else{ return -1; } } } if(temp>=0){ return 1; }else{ return -1; } } } class Pair{ long a; long b; Pair(long p,long q){ this.a = p; this.b = q; } public boolean equals(Object o){ Pair O = (Pair) o; if(O.a==this.a&&O.b==this.b){ return true; }else{ return false; } } public int hashCode(){ return Objects.hash(a,b); } } class SampleComparator implements Comparator<Pair>{ public int compare(Pair P, Pair Q) { long temp = P.a-Q.a; if(temp==0){ if(P.b>Q.b){ return 1; }else{ return -1; } } if(temp>=0){ return 1; }else{ return -1; } } } class FastScanner { private final java.io.InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} public boolean hasNext() { skipUnprintable(); return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return (minus ? -n : n); }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return (int) (minus ? -n : n); }else{ throw new NumberFormatException(); } b = readByte(); } } } class Mathplus{ int mod = 1000000007; long[] fac = new long[1000001]; boolean isBuild = false; void buildFac(){ fac[0] = 1; for(int i=1;i<=1000000;i++){ fac[i] = (fac[i-1] * i)%mod; } isBuild = true; } long gcd(long a, long b){ if(a<b){ a^=b; b^=a; a^=b; } if(a%b==0){ return b; }else{ return gcd(b,a%b); } } long lcm(long a, long b){ return a / gcd(a,b) * b; } public long comb(int a,int num){ if(!isBuild){ buildFac(); } return fac[a] * (rev(fac[num])*rev(fac[a-num])%mod)%mod; } long rev(long l) { return pow(l,mod-2); } long pow(long l, int i) { if(i==0){ return 1; }else{ if(i%2==0){ long val = pow(l,i/2); return val * val % mod; }else{ return pow(l,i-1) * l % mod; } } } }