結果
問題 | No.2260 Adic Sum |
ユーザー | Asahi |
提出日時 | 2023-04-07 22:53:52 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 12,629 bytes |
コンパイル時間 | 3,556 ms |
コンパイル使用メモリ | 96,128 KB |
実行使用メモリ | 47,536 KB |
最終ジャッジ日時 | 2024-10-06 06:45:39 |
合計ジャッジ時間 | 8,388 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 112 ms
46,520 KB |
testcase_01 | AC | 115 ms
41,224 KB |
testcase_02 | AC | 115 ms
41,212 KB |
testcase_03 | AC | 111 ms
41,296 KB |
testcase_04 | AC | 118 ms
41,032 KB |
testcase_05 | AC | 113 ms
40,948 KB |
testcase_06 | AC | 109 ms
41,208 KB |
testcase_07 | AC | 110 ms
41,040 KB |
testcase_08 | AC | 145 ms
41,080 KB |
testcase_09 | AC | 119 ms
40,132 KB |
testcase_10 | AC | 125 ms
40,308 KB |
testcase_11 | AC | 118 ms
41,104 KB |
testcase_12 | AC | 144 ms
41,128 KB |
testcase_13 | AC | 184 ms
41,228 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
import java.util.*; import java.io.*; import java.math.*; class Main{ void solve(){ int n = ni() ; long p = nl(); long [] A = LongArray(n); long ans = 0 ; for(int i = 0 ; i < n - 1 ; i ++ ) { for(int j = i + 1 ; j < n ; j ++ ) { long d = Math.abs(A[i]-A[j]); long count = 0 ; if( d % p == 0 ) { while(d % p == 0) { d /= p ; count ++ ; } } ans += count; } } output.print(ans); } // for(int i = 0 ; i < n ; i ++ ) { // output.print(" "); // } // for(int i = 0 ; i < H ; i ++ ) { // for(int j = 0 ; j < W ; j ++ ) { // output.print(" "); // } // output.println(); // } /* 以下、ライブラリ等 */ private static PrintWriter output; private static FastScanner fs ; private static Scanner sc; private static final int Inf = 1000000000; private static final long Lnf = 1000000000000000000L; private static final String yes = "Yes"; private static final String no = "No"; //private static final long MOD = 1000000007; //private static final long MOD = 998244353 ; private static int ni() { return fs.nextInt(); } private static long nl() { return fs.nextLong(); } private static double nd() { return fs.nextDouble(); } private static String ns() { return fs.next(); } private static char nc() { return fs.next().charAt(0); } private static BigInteger bi() { return sc.nextBigInteger(); } private static BigDecimal bd() { return sc.nextBigDecimal(); } private static String cut(String S , int begin, int end) { return S.substring(begin,end); } private static char cut(String S , int idx) { return S.charAt(idx); } private static String tos(int val) { return Integer.toString(val); } private static String tos(long val) { return Long.toString(val); } private static int toi(String S) { return Integer.parseInt(S); } private static long tol(String S) { return Long.parseLong(S); } private static int min(int a , int b) { return (int)Math.min(a,b); } private static long min(long a , long b) { return (long)Math.min(a,b); } private static int max(int a , int b) { return (int)Math.max(a,b); } private static long max(long a , long b) { return (long)Math.max(a,b); } private static int abs(int a , int b) { return (int)Math.abs(a-b); } private static long abs(long a , long b) { return (long)Math.abs(a-b); } private static String t_n(int n , int m) { return Integer.toString(n,m); } private static int n_t(String n , int m) { return Integer.parseInt(n,m); } private static int [] IntArray(int size) { final int [] array = new int [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = ni(); } return array; } private static long [] LongArray(int size) { long [] array = new long [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = nl(); } return array; } private static double [] DoubleArray(int size) { double [] array = new double [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = nd(); } return array; } private static String [] StringArray(int size) { String [] array = new String [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = ns(); } return array; } private static char [] CharArray(int size) { char [] array = ns().toCharArray(); return array; } private static int [][] IntArray(int sizeI , int sizeJ) { int [][] array = new int [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = ni(); } return array; } private static long [][] LongArray(int sizeI , int sizeJ) { long [][] array = new long [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = nl(); } return array; } private static double [][] DoubleArray(int sizeI , int sizeJ) { double [][] array = new double [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = nd(); } return array; } private static String [][] StringArray(int sizeI , int sizeJ) { String [][] array = new String [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = ns(); } return array; } private static char [][] CharArray(int sizeI , int sizeJ) { char [][] array = new char [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) { array[i] = ns().toCharArray(); } return array; } public static void main(String[] args){ output = new PrintWriter(System.out); fs = new FastScanner(); sc = new Scanner(System.in); new Main().solve(); output.flush(); } ////////////////// // My Library // ////////////////// private static int upper_bound(Integer [] array , int key) { return ~Arrays.binarySearch(array, key, (x,y)->x.compareTo(y)>0?1:-1); } private static int lower_bound(Integer [] array , int key) { return ~Arrays.binarySearch(array, key, (x,y)->x.compareTo(y)>=0?1:-1); } } /* 順列生成 */ class Permutation { ArrayList<int []> perm_list ; private int [] perm ; private int [] tmp ; private int [] used ; private int size = 0; private int len = 1; private int cur = 0; public Permutation(int [] base) { this.perm_list = new ArrayList<int []>(); this.perm = new int[base.length]; this.tmp = new int[base.length]; this.used = new int[base.length]; len = 1; size = base.length; System.arraycopy(base, 0, perm, 0, size); for(int i = base.length ; i > 0 ; i -- ) len *= i; for(int i = 0 ; i < len ; i ++ ) perm_list.add(new int[base.length]); } public void next_permutation(int idx){ if(idx == size) { for(int i = 0 ; i < size ; i ++ ) { perm_list.get(cur)[i] = tmp[i]; } cur++; return; } for(int i=0;i<size;i++) { if(used[i] == 1) continue; used[i] = 1; tmp[idx] = perm[i]; next_permutation(idx+1); used[i] = 0; } } } /* 素集合データ構造 */ class DSU { int [] parent; private int[] rank; int [] size; int [] vertex ; int [] edge ; public DSU(int n) { this.parent = new int[n]; this.rank = new int[n]; this.size = new int[n]; this.vertex = new int[n]; this.edge = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } // 連結成分の個数 public int groups() { int count = 0; for(int i=0;i<parent.length;i++) { if(i == find(i)) count++; } return count; } // 各連結成分の頂点数 public void vertexes(int n) { for(int i = 0 ; i < n ; i ++ ){ vertex[find(i)]++; } } // 各連結成分の辺数 public void edges(int m , int [] from) { for(int i = 0 ; i < m ; i ++ ) { edge[find(from[i])]++; } } public int size(int x){ return size[find(x)]; } public int find(int x) { if (x == parent[x]) { return x; } else { parent[x] = find(parent[x]); return parent[x]; } } public boolean same(int x, int y) { return find(x) == find(y); } /* * yRoot -> parent */ public void unite(int x, int y) { int xRoot = find(x); int yRoot = find(y); if (xRoot == yRoot) { return; } if (rank[xRoot] > rank[yRoot]) { parent[yRoot] = xRoot; } else if (rank[xRoot] < rank[yRoot]) { parent[xRoot] = yRoot; } else { parent[xRoot] = yRoot; rank[xRoot]++; size[yRoot] += size[xRoot]; } } } /* 強連結成分分解 */ class SCC { private boolean [] check ; private List<ArrayList<Integer>> edge ; private List<ArrayList<Integer>> revEdge ; private int count ; private int [] vr ; int [] group ; /* * group[i] = 0 -> 強連結成分であるが親でない。 * group[i] = 1 -> 強連結成分でない * group[i] > 1 -> 強連結成分内の頂点数を表し、iが親である。 */ private int groupNum ; /* * 連結成分数 (頂点数1も含む) */ public SCC(int n) { this.check = new boolean[n]; this.edge = new ArrayList<>(); this.revEdge = new ArrayList<>(); this.count = 0 ; this.vr = new int[n]; this.group = new int[n]; this.groupNum = 0 ; for(int i = 0 ; i < n ; i ++ ) { edge.add(new ArrayList<>()); revEdge.add(new ArrayList<>()); } } public void addEdge(int a , int b) { edge.get(a).add(b); revEdge.get(b).add(a); } public int getGroups(){ return this.groupNum; } public void start() { int n = group.length; for(int i = 0 ; i < n ; i ++ ) { if(!check[i]) { First(i); } } Arrays.fill(check,false); for(int i = n - 1 ; i >= 0 ; i -- ) { if(!check[vr[i]]) { Second(vr[i], groupNum++); } } } public void First(int now) { check[now] = true; for(int i : edge.get(now)) { if(!check[i]) { First(i); } } vr[count++] = now; } public void Second(int now,int groupNum) { check[now] = true; group[groupNum]++; for(int i : revEdge.get(now)) { if(!check[i]) { Second(i, groupNum); } } } } class FastScanner { private final 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;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; 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() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }