id
stringlengths
22
25
content
stringlengths
327
628k
max_stars_repo_path
stringlengths
49
49
condefects-java_data_1
import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { Main o = new Main(); o.solve(); } public void solve() { FastScanner sc = new FastScanner(System.in); int N = sc.nextInt(); int[] P = new int[N]; for (int i = 0; i < N; i++) { P[i] = sc.nextInt(); } int cnt = 0; int ei = 0; int oi = 1; StringBuilder ans = new StringBuilder(); while ( ei < N && oi < N ) { while ( ei < N && P[ei] % 2 != 0 ) ei += 2; while ( oi < N && P[oi] % 2 == 0 ) oi += 2; if ( ei >= N || oi >= N ) break; int i0 = 0; if ( ei < oi ) { for (int i = ei; i <= oi - 3; i += 2) { ans.append("B "); ans.append(i + 1); ans.append("\n"); swap(P, i, i + 2); cnt++; } i0 = oi - 1; } else { for (int i = oi; i <= ei - 3; i += 2) { ans.append("B "); ans.append(i + 1); ans.append("\n"); swap(P, i, i + 2); cnt++; } i0 = ei - 1; } ans.append("A "); ans.append(i0 + 1); ans.append("\n"); swap(P, i0, i0 + 1); cnt++; } for (int p = 0; p < 2; p++) { for (int i = p; i < N; i += 2) { for (int j = p + 2; j < N - i; j += 2) { if ( P[j - 2] > P[j] ) { ans.append("B "); ans.append(j - 1); ans.append("\n"); swap(P, j - 2, j); cnt++; } } } } System.out.println(cnt); System.out.print(ans.toString()); } void swap(int[] P, int i, int j) { int tmp = P[i]; P[i] = P[j]; P[j] = tmp; } class Number implements Comparable<Number> { int val = 0; int ord = 0; Number(int val) { this.val = val; } @Override public int compareTo(Main.Number o) { return val < o.val ? -1 : 1; } } class FastScanner { private final InputStream in; private final byte[] buf = new byte[1024]; private int ptr = 0; private int buflen = 0; FastScanner( InputStream source ) { this.in = source; } private boolean hasNextByte() { if ( ptr < buflen ) return true; else { ptr = 0; try { buflen = in.read(buf); } catch (IOException e) { e.printStackTrace(); } if ( buflen <= 0 ) return false; } return true; } private int readByte() { if ( hasNextByte() ) return buf[ptr++]; else return -1; } private boolean isPrintableChar( int c ) { return 33 <= c && c <= 126; } private boolean isNumeric( int c ) { return '0' <= c && c <= '9'; } private void skipToNextPrintableChar() { while ( hasNextByte() && !isPrintableChar(buf[ptr]) ) ptr++; } public boolean hasNext() { skipToNextPrintableChar(); return hasNextByte(); } public String next() { if ( !hasNext() ) throw new NoSuchElementException(); StringBuilder ret = new StringBuilder(); int b = readByte(); while ( isPrintableChar(b) ) { ret.appendCodePoint(b); b = readByte(); } return ret.toString(); } public long nextLong() { if ( !hasNext() ) throw new NoSuchElementException(); long ret = 0; int b = readByte(); boolean negative = false; if ( b == '-' ) { negative = true; if ( hasNextByte() ) b = readByte(); } if ( !isNumeric(b) ) throw new NumberFormatException(); while ( true ) { if ( isNumeric(b) ) ret = ret * 10 + b - '0'; else if ( b == -1 || !isPrintableChar(b) ) return negative ? -ret : ret; else throw new NumberFormatException(); b = readByte(); } } public int nextInt() { return (int)nextLong(); } public double nextDouble() { return Double.parseDouble(next()); } } } import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { Main o = new Main(); o.solve(); } public void solve() { FastScanner sc = new FastScanner(System.in); int N = sc.nextInt(); int[] P = new int[N]; for (int i = 0; i < N; i++) { P[i] = sc.nextInt(); } int cnt = 0; int ei = 0; int oi = 1; StringBuilder ans = new StringBuilder(); while ( ei < N && oi < N ) { while ( ei < N && P[ei] % 2 != 0 ) ei += 2; while ( oi < N && P[oi] % 2 == 0 ) oi += 2; if ( ei >= N || oi >= N ) break; int i0 = 0; if ( ei < oi ) { for (int i = ei; i <= oi - 3; i += 2) { ans.append("B "); ans.append(i + 1); ans.append("\n"); swap(P, i, i + 2); cnt++; } i0 = oi - 1; } else { for (int i = oi; i <= ei - 3; i += 2) { ans.append("B "); ans.append(i + 1); ans.append("\n"); swap(P, i, i + 2); cnt++; } i0 = ei - 1; } ans.append("A "); ans.append(i0 + 1); ans.append("\n"); swap(P, i0, i0 + 1); cnt++; } for (int p = 0; p < 2; p++) { for (int i = p; i < N; i += 2) { for (int j = p + 2; j < N - (i - p); j += 2) { if ( P[j - 2] > P[j] ) { ans.append("B "); ans.append(j - 1); ans.append("\n"); swap(P, j - 2, j); cnt++; } } } } System.out.println(cnt); System.out.print(ans.toString()); } void swap(int[] P, int i, int j) { int tmp = P[i]; P[i] = P[j]; P[j] = tmp; } class Number implements Comparable<Number> { int val = 0; int ord = 0; Number(int val) { this.val = val; } @Override public int compareTo(Main.Number o) { return val < o.val ? -1 : 1; } } class FastScanner { private final InputStream in; private final byte[] buf = new byte[1024]; private int ptr = 0; private int buflen = 0; FastScanner( InputStream source ) { this.in = source; } private boolean hasNextByte() { if ( ptr < buflen ) return true; else { ptr = 0; try { buflen = in.read(buf); } catch (IOException e) { e.printStackTrace(); } if ( buflen <= 0 ) return false; } return true; } private int readByte() { if ( hasNextByte() ) return buf[ptr++]; else return -1; } private boolean isPrintableChar( int c ) { return 33 <= c && c <= 126; } private boolean isNumeric( int c ) { return '0' <= c && c <= '9'; } private void skipToNextPrintableChar() { while ( hasNextByte() && !isPrintableChar(buf[ptr]) ) ptr++; } public boolean hasNext() { skipToNextPrintableChar(); return hasNextByte(); } public String next() { if ( !hasNext() ) throw new NoSuchElementException(); StringBuilder ret = new StringBuilder(); int b = readByte(); while ( isPrintableChar(b) ) { ret.appendCodePoint(b); b = readByte(); } return ret.toString(); } public long nextLong() { if ( !hasNext() ) throw new NoSuchElementException(); long ret = 0; int b = readByte(); boolean negative = false; if ( b == '-' ) { negative = true; if ( hasNextByte() ) b = readByte(); } if ( !isNumeric(b) ) throw new NumberFormatException(); while ( true ) { if ( isNumeric(b) ) ret = ret * 10 + b - '0'; else if ( b == -1 || !isPrintableChar(b) ) return negative ? -ret : ret; else throw new NumberFormatException(); b = readByte(); } } public int nextInt() { return (int)nextLong(); } public double nextDouble() { return Double.parseDouble(next()); } } }
ConDefects/ConDefects/Code/arc147_b/Java/34774631
condefects-java_data_2
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); final int n = Integer.parseInt(br.readLine()); final StringTokenizer st_a = new StringTokenizer(br.readLine()); br.close(); final long[] array_a = new long[n]; for (int i = 0; i < n; i++) { array_a[i] = Long.parseLong(st_a.nextToken()); } long g = 0; for (int i = 0; i < n - 1; i++) { g = gcd(array_a[i + 1] - array_a[i], g); } System.out.println(g != 1 ? 1 : 2); } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); final int n = Integer.parseInt(br.readLine()); final StringTokenizer st_a = new StringTokenizer(br.readLine()); br.close(); final long[] array_a = new long[n]; for (int i = 0; i < n; i++) { array_a[i] = Long.parseLong(st_a.nextToken()); } long g = 0; for (int i = 0; i < n - 1; i++) { g = gcd(Math.abs(array_a[i] - array_a[i + 1]), g); } System.out.println(g != 1 ? 1 : 2); } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } }
ConDefects/ConDefects/Code/arc148_a/Java/35625720
condefects-java_data_3
import java.util.*; import java.lang.*; import java.io.*; class Main{ public static int gcd(int a, int b){ if(b == 0){ return a; } return gcd(b, a % b); } public static void main (String[] args) throws java.lang.Exception{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++){ arr[i] = sc.nextInt(); } int g = arr[1] - arr[0]; for(int i = 2; i < n; i++){ g = gcd(g, Math.abs(arr[i] - arr[i - 1])); } if(g == 1){ System.out.println(2); } else{ System.out.println(1); } } } import java.util.*; import java.lang.*; import java.io.*; class Main{ public static int gcd(int a, int b){ if(b == 0){ return a; } return gcd(b, a % b); } public static void main (String[] args) throws java.lang.Exception{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++){ arr[i] = sc.nextInt(); } int g = Math.abs(arr[1] - arr[0]); for(int i = 2; i < n; i++){ g = gcd(g, Math.abs(arr[i] - arr[i - 1])); } if(g == 1){ System.out.println(2); } else{ System.out.println(1); } } }
ConDefects/ConDefects/Code/arc148_a/Java/34806342
condefects-java_data_4
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Main { static int MOD = (int) (1e9 + 7); public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; Reader in = new Reader(inputStream); PrintWriter out = new PrintWriter(outputStream); solve(in, out); out.close(); } static int add_self(int a, int b) { a += b; return a >= MOD ? a - MOD : a; } static int sub_self(int i, int i1) { i -= i1; return i >= 0 ? i : i + MOD; } static int[][] dp; private static void solve(Reader in, PrintWriter out) throws IOException { int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } int gcd = 0; for (int i = 0; i < n - 1; i++) { gcd = calcGCD(gcd, Math.abs(arr[i + 1] - arr[i])); } if(gcd== 0 || gcd > 1) { out.print(1); } else { out.print(2); } out.close(); } static int calcGCD(int a, int b) { if(a==0) return b; return calcGCD(b % a, b); } public static int[][] parents3(int[][] g, int root) { int n = g.length; int[] par = new int[n]; Arrays.fill(par, -1); int[] depth = new int[n]; int[] q = new int[n]; q[0] = root; for (int p = 0, r = 1; p < r; p++) { int cur = q[p]; for (int nex : g[cur]) { if (par[cur] != nex) { q[r++] = nex; par[nex] = cur; depth[nex] = depth[cur] + 1; } } } return new int[][]{par, q, depth}; } static int[][] packU(int n, int[] from, int[] to) { int[][] g = new int[n][]; int[] p = new int[n]; for (int i : from) { p[i]++; } for (int i : to) { p[i]++; } for (int i = 0; i < n; i++) { g[i] = new int[p[i]]; } for (int i = 0; i < from.length; i++) { g[from[i]][--p[from[i]]] = to[i]; g[to[i]][--p[to[i]]] = from[i]; } return g; } static class Reader { BufferedReader br; StringTokenizer st; public Reader(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair<T> { T a; T b; public Pair(T a, T b) { this.a = a; this.b = b; } T first() { return a; } T second() { return b; } } public static class SegmentTreeRMQL { public int M, H, N; public long[] st; public SegmentTreeRMQL(int n) { N = n; M = Integer.highestOneBit(Math.max(N - 1, 1)) << 2; H = M >>> 1; st = new long[M]; Arrays.fill(st, 0, M, Long.MAX_VALUE); } public SegmentTreeRMQL(long[] a) { N = a.length; M = Integer.highestOneBit(Math.max(N - 1, 1)) << 2; H = M >>> 1; st = new long[M]; for (int i = 0; i < N; i++) { st[H + i] = a[i]; } Arrays.fill(st, H + N, M, Long.MAX_VALUE); for (int i = H - 1; i >= 1; i--) propagate(i); } public void update(int pos, long x) { st[H + pos] = x; for (int i = (H + pos) >>> 1; i >= 1; i >>>= 1) propagate(i); } private void propagate(int i) { st[i] = Math.min(st[2 * i], st[2 * i + 1]); } public long minx(int l, int r) { long min = Long.MAX_VALUE / 2; if (l >= r) return min; while (l != 0) { int f = l & -l; if (l + f > r) break; long v = st[(H + l) / f]; if (v < min) min = v; l += f; } while (l < r) { int f = r & -r; long v = st[(H + r) / f - 1]; if (v < min) min = v; r -= f; } return min; } public long min(int l, int r) { return l >= r ? 0 : min(l, r, 0, H, 1); } private long min(int l, int r, int cl, int cr, int cur) { if (l <= cl && cr <= r) { return st[cur]; } else { int mid = cl + cr >>> 1; long ret = Long.MAX_VALUE; if (cl < r && l < mid) { ret = Math.min(ret, min(l, r, cl, mid, 2 * cur)); } if (mid < r && l < cr) { ret = Math.min(ret, min(l, r, mid, cr, 2 * cur + 1)); } return ret; } } public int firstle(int l, long v) { int cur = H + l; while (true) { if (st[cur] <= v) { if (cur < H) { cur = 2 * cur; } else { return cur - H; } } else { cur++; if ((cur & cur - 1) == 0) return -1; if ((cur & 1) == 0) cur >>>= 1; } } } public int lastle(int l, long v) { int cur = H + l; while (true) { if (st[cur] <= v) { if (cur < H) { cur = 2 * cur + 1; } else { return cur - H; } } else { if ((cur & cur - 1) == 0) return -1; cur--; if ((cur & 1) == 1) cur >>>= 1; } } } } } import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Main { static int MOD = (int) (1e9 + 7); public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; Reader in = new Reader(inputStream); PrintWriter out = new PrintWriter(outputStream); solve(in, out); out.close(); } static int add_self(int a, int b) { a += b; return a >= MOD ? a - MOD : a; } static int sub_self(int i, int i1) { i -= i1; return i >= 0 ? i : i + MOD; } static int[][] dp; private static void solve(Reader in, PrintWriter out) throws IOException { int n = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } int gcd = 0; for (int i = 0; i < n - 1; i++) { gcd = calcGCD(gcd, Math.abs(arr[i + 1] - arr[i])); } if(gcd== 0 || gcd > 1) { out.print(1); } else { out.print(2); } out.close(); } static int calcGCD(int a, int b) { if(a==0) return b; return calcGCD(b % a, a); } public static int[][] parents3(int[][] g, int root) { int n = g.length; int[] par = new int[n]; Arrays.fill(par, -1); int[] depth = new int[n]; int[] q = new int[n]; q[0] = root; for (int p = 0, r = 1; p < r; p++) { int cur = q[p]; for (int nex : g[cur]) { if (par[cur] != nex) { q[r++] = nex; par[nex] = cur; depth[nex] = depth[cur] + 1; } } } return new int[][]{par, q, depth}; } static int[][] packU(int n, int[] from, int[] to) { int[][] g = new int[n][]; int[] p = new int[n]; for (int i : from) { p[i]++; } for (int i : to) { p[i]++; } for (int i = 0; i < n; i++) { g[i] = new int[p[i]]; } for (int i = 0; i < from.length; i++) { g[from[i]][--p[from[i]]] = to[i]; g[to[i]][--p[to[i]]] = from[i]; } return g; } static class Reader { BufferedReader br; StringTokenizer st; public Reader(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair<T> { T a; T b; public Pair(T a, T b) { this.a = a; this.b = b; } T first() { return a; } T second() { return b; } } public static class SegmentTreeRMQL { public int M, H, N; public long[] st; public SegmentTreeRMQL(int n) { N = n; M = Integer.highestOneBit(Math.max(N - 1, 1)) << 2; H = M >>> 1; st = new long[M]; Arrays.fill(st, 0, M, Long.MAX_VALUE); } public SegmentTreeRMQL(long[] a) { N = a.length; M = Integer.highestOneBit(Math.max(N - 1, 1)) << 2; H = M >>> 1; st = new long[M]; for (int i = 0; i < N; i++) { st[H + i] = a[i]; } Arrays.fill(st, H + N, M, Long.MAX_VALUE); for (int i = H - 1; i >= 1; i--) propagate(i); } public void update(int pos, long x) { st[H + pos] = x; for (int i = (H + pos) >>> 1; i >= 1; i >>>= 1) propagate(i); } private void propagate(int i) { st[i] = Math.min(st[2 * i], st[2 * i + 1]); } public long minx(int l, int r) { long min = Long.MAX_VALUE / 2; if (l >= r) return min; while (l != 0) { int f = l & -l; if (l + f > r) break; long v = st[(H + l) / f]; if (v < min) min = v; l += f; } while (l < r) { int f = r & -r; long v = st[(H + r) / f - 1]; if (v < min) min = v; r -= f; } return min; } public long min(int l, int r) { return l >= r ? 0 : min(l, r, 0, H, 1); } private long min(int l, int r, int cl, int cr, int cur) { if (l <= cl && cr <= r) { return st[cur]; } else { int mid = cl + cr >>> 1; long ret = Long.MAX_VALUE; if (cl < r && l < mid) { ret = Math.min(ret, min(l, r, cl, mid, 2 * cur)); } if (mid < r && l < cr) { ret = Math.min(ret, min(l, r, mid, cr, 2 * cur + 1)); } return ret; } } public int firstle(int l, long v) { int cur = H + l; while (true) { if (st[cur] <= v) { if (cur < H) { cur = 2 * cur; } else { return cur - H; } } else { cur++; if ((cur & cur - 1) == 0) return -1; if ((cur & 1) == 0) cur >>>= 1; } } } public int lastle(int l, long v) { int cur = H + l; while (true) { if (st[cur] <= v) { if (cur < H) { cur = 2 * cur + 1; } else { return cur - H; } } else { if ((cur & cur - 1) == 0) return -1; cur--; if ((cur & 1) == 1) cur >>>= 1; } } } } }
ConDefects/ConDefects/Code/arc148_a/Java/34851302
condefects-java_data_5
import java.io.*; import java.util.*; import java.math.*; class Main{ static Library System = new Library(java.lang.System.in,java.lang.System.out); public static void main(String[] args)throws IOException{ int N = System.in.nextInt(); int[] A = System.in.nextInt(N); long gcd = Math.abs(A[1]-A[0]); for(int i=2;i<N;i++){ gcd = System.gcd(gcd,Math.abs(A[i]-A[i-1])); } System.out.println(gcd==1?1:2); System.out.close(); } } /*//////////////////////////////////////////////// * My Library * *///////////////////////////////////////////////// class Library{ SimpleScanner in = null; PrintWriter out = null; private long[] Factorials,InFactorials; public long mod = 0; public Library(InputStream in,OutputStream out){ this.in = new SimpleScanner(in); this.out = new PrintWriter(out); } public Library(InputStream in,OutputStream out,int fac,long mod){ this(in,out); Factorials=new long[fac+1]; Factorials[1]=1; for(int i=2;i<=fac;i++)Factorials[i]=Factorials[i-1]*i%mod; InFactorials=new long[fac+1]; InFactorials[fac]=modPow(Factorials[fac],mod-2,mod); for(int i=fac;i>1;i--)InFactorials[i-1]=InFactorials[i]*i%mod; this.mod = mod; } /** * コンストラクタで渡された値までの * num!、aCbをmodで割ったあまりを返します。 */ public long getFact(int num){ return Factorials[num]; } public long getCombi(int a,int b){ return (Factorials[a]*InFactorials[a-b]%mod)*InFactorials[b]%mod; } /** * ○N! * factではa!を、 * modFactでは引数のmodかコンストラクタで渡されたmodで * 割ったあまりを返します。 */ public static long fact(long a){ long ans=1; for(long i=2;i<=a;i++)ans*=i; return ans; } public static long modFact(long a,long mod){ long ans=1; for(long i=2;i<=a;i++){ ans*=i%mod; ans%=mod; } return ans; } public long modFact(long a){ if(mod==0){ System.err.println("\u001b[00;31m"+"#mod is not defined#"); System.exit(1); } long ans=1; for(long i=2;i<=a;i++){ ans*=i%mod; ans%=mod; } return ans; } /** * ○nCr * CombiではaCb、 * modCombiでは引数のmodかコンストラクタで渡されたmodで * 割ったあまりを返します。 */ public static long combi(long a,long b){ long ans=1; if(b==0||b==a)return 1; if(b<0||b>a)return 0; b=Math.min(a-b,b); for(long i=1;i<=b;i++){ ans*=a--; ans/=i; } return ans; } public static long modCombi(long a,long b,long mod){ long ans=1; if(b==0||b==a)return 1; if(b<0||b>a)return 0; b=Math.min(a-b,b); for(long i=1;i<=b;i++){ ans*=a--; ans%=mod; ans*=modPow(i,mod-2,mod); ans%=mod; } return ans; } public long modCombi(long a,long b){ if(mod==0){ System.err.println("\u001b[00;31m"+"#mod is not defined#"); System.exit(1); } long ans=1; if(b==0||b==a)return 1; if(b<0||b>a)return 0; b=Math.min(a-b,b); for(long i=1;i<=b;i++){ ans*=a--; ans%=mod; ans*=modPow(i,mod-2,mod); ans%=mod; } return ans; } /** * ○ヒープソート * int、long型配列をソートします。 * 二次元配列の場合は[i][0]と[i][1]の大きさで * 昇順に並べ替えます。 */ public static void sort(int[] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&list[(j-1)/2]<list[j]){ int temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ int temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&list[j]<list[2*j+1])||(2*j+2<i-1&&list[j]<list[2*j+2])){ if(2*j+2==i-1||list[2*j+1]>list[2*j+2]){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } public static void sort(int[][] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&(list[(j-1)/2][0]<list[j][0]||(list[(j-1)/2][0]==list[j][0]&&list[(j-1)/2][1]<list[j][1]))){ int[] temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ int[] temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&(list[j][0]<list[2*j+1][0]||(list[j][0]==list[2*j+1][0]&&list[j][1]<list[2*j+1][1])))|| (2*j+2<i-1&&(list[j][0]<list[2*j+2][0]||(list[j][0]==list[2*j+2][0]&&list[j][1]<list[2*j+2][1])))){ if(2*j+2==i-1||(list[2*j+1][0]>list[2*j+2][0]||(list[2*j+1][0]==list[2*j+2][0]&&list[2*j+1][1]>list[2*j+2][1]))){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } public static void sort(long[] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&list[(j-1)/2]<list[j]){ long temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ long temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&list[j]<list[2*j+1])||(2*j+2<i-1&&list[j]<list[2*j+2])){ if(2*j+2==i-1||list[2*j+1]>list[2*j+2]){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } public static void sort(long[][] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&(list[(j-1)/2][0]<list[j][0]||(list[(j-1)/2][0]==list[j][0]&&list[(j-1)/2][1]<list[j][1]))){ long[] temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ long[] temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&(list[j][0]<list[2*j+1][0]||(list[j][0]==list[2*j+1][0]&&list[j][1]<list[2*j+1][1])))|| (2*j+2<i-1&&(list[j][0]<list[2*j+2][0]||(list[j][0]==list[2*j+2][0]&&list[j][1]<list[2*j+2][1])))){ if(2*j+2==i-1||(list[2*j+1][0]>list[2*j+2][0]||(list[2*j+1][0]==list[2*j+2][0]&&list[2*j+1][1]>list[2*j+2][1]))){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } /** * ○カウントソート * int型配列をソートします。 * 最大値が小さい場合は有効です。 */ public static void countSort(int[] nums,int limit){ int[] list=new int[limit+1]; for(int i=0;i<nums.length;i++)list[nums[i]]++; int temp=0; for(int i=0;i<list.length;i++)for(int j=0;j<list[i];j++)nums[temp++]=i; } /** * ○ユークリッドの互除法 * gcdは最大公約数を、 * lcmは最小公倍数を返します。 * lcmはオーバーフローの可能性があるのでご注意を。 * 戻り値はlong型です。 */ public static long gcd(long a,long b){ if(a==0||b==0) return Math.max(a,b); long temp; while((temp=a%b)!=0){ a=b; b=temp; } return b; } public static long lcm(long a,long b){ long mult=a*b,temp; while((temp=a%b)!=0){ a=b; b=temp; } return mult/b; } /** * ○ミラーラビン素数判定法 * BigIntegerクラスのものを使用します。 * 素数である確率が高いならtrue、 * 確実に合成数ならfalseを返します。 * 誤判定の確率は1/2^20以下です。 */ public static boolean isPrime(long num){ return BigInteger.valueOf(num).isProbablePrime(20); } /** * ○エラトステネスの篩 * 引数まで(引数含む)の素数を返します。 * 2^30以上の素数列挙はできないのでご注意を。 */ public static int[] prime(int num){ BitSet nums=new BitSet(num+1); nums.set(2,num+1); for(int i=2;i<=Math.sqrt(num);i++)if(nums.get(i))for(int j=i*i;j<=num;j+=i)nums.clear(j); int[] answer=new int[nums.cardinality()]; int i=2,index=0; while(true){ i=nums.nextSetBit(i); answer[index++]=i++; if(index==answer.length)break; } return answer; } /** * ○繰り返し二乗法 * powではそのままの結果を、 * modPowでは引数のmodかコンストラクタで渡されたmodで * 割ったあまりを返します。 */ public static long pow(long a,long b){ long ans=1; while(b>0){ if((b&1)==1)ans*=a; a*=a; b>>=1; } return ans; } public static long modPow(long a,long b,long mod){ long ans=1; a%=mod; while(b>0){ if((b&1)==1)ans*=a; ans%=mod; a*=a; a%=mod; b>>=1; } return ans; } public long modPow(long a,long b){ if(mod==0){ System.err.println("\u001b[00;31m"+"#mod is not defined#"); System.exit(1); } long ans=1; a%=mod; while(b>0){ if((b&1)==1)ans*=a; ans%=mod; a*=a; a%=mod; b>>=1; } return ans; } /** * ○文字列→整数変換 * Stringをint、longに変換します。 * 数値以外の文字であっても無理矢理数値変換してしまうので * 使用の際はご注意を。 */ public static int parseInt(String str){ char[] nums=str.toCharArray(); int ans=0; boolean plus=true; if(nums[0]=='-'){ plus=!plus; nums[0]='0'; } for(int i=0;i<nums.length;i++)ans=ans*10+nums[i]-'0'; return plus?ans:-ans; } public static long parseLong(String str){ char[] nums=str.toCharArray(); long ans=0; boolean plus=true; if(nums[0]=='-'){ plus=!plus; nums[0]='0'; } for(int i=0;i<nums.length;i++)ans=ans*10+nums[i]-'0'; return plus?ans:-ans; } /** * ○二分探索 * downsearchではnum以下を、 * upsearchではnum以上を探します。 * 引数の配列(List)のインデックスを返します。 */ public static int downsearch(int[] nums,int num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(int[] nums,int num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(long[] nums,long num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(long[] nums,long num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(Integer[] nums,int num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(Integer[] nums,int num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(Long[] nums,long num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(Long[] nums,long num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(ArrayList<Integer> nums,int num){ int a=0,b=nums.size()-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(ArrayList<Integer> nums,int num){ int a=0,b=nums.size()-1,ans=nums.size(),c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(ArrayList<Long> nums,long num){ int a=0,b=nums.size()-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(ArrayList<Long> nums,long num){ int a=0,b=nums.size()-1,ans=nums.size(),c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>=num)b=(ans=c)-1; else a=c+1; } return ans; } public void exit(int num){ try{ in.close(); out.close(); }catch(Exception e){ }finally{ System.exit(num); } } @Override public String toString(){ StringBuilder answer=new StringBuilder(); if(Factorials!=null)answer.append("Factorials are defined. (You can use 0~"+(Factorials.length-1)+" for index)"); else answer.append("Factorial is not defined."); answer.append("\n"); if(InFactorials!=null)answer.append("InFactorials are defined. (You can use 0~"+(InFactorials.length-1)+" for index)"); else answer.append("InFactorial is not defined."); answer.append("\n"); if(mod!=0)answer.append("mod is "+mod); else answer.append("mod is not defined."); return answer.toString(); } } /*//////////////////////////////////////////////// * 入力用 * *///////////////////////////////////////////////// class SimpleScanner{ final private int buff_size = 1<<12; private InputStream is; private byte[] buff; private int point,length; public SimpleScanner(InputStream is){ this.is = is; buff = new byte[buff_size]; point = length = 0; } private void reload()throws IOException{ do{ length = is.read(buff,point = 0,buff_size); }while(length==-1); } private byte read()throws IOException{ if(point==length)reload(); return buff[point++]; } public byte nextByte()throws IOException{ byte c = read(); while(c<=' ')c = read(); return c; } public int nextInt()throws IOException{ int ans = 0; byte c = read(); while(c<=' ')c = read(); boolean negate = c == '-'; if(c=='-')c = read(); while('0'<=c&&c<='9'){ ans = ans*10+c-'0'; c = read(); } return negate ? -ans : ans; } public long nextLong()throws IOException{ long ans = 0; byte c = read(); while(c<=' ')c = read(); boolean negate = c == '-'; if(c=='-')c = read(); while('0'<=c&&c<='9'){ ans = ans*10+c-'0'; c = read(); } return negate ? -ans : ans; } public char nextChar()throws IOException{ byte c = read(); while(c<=' ')c = read(); return (char)c; } public String next()throws IOException{ StringBuilder ans = new StringBuilder(); byte c = read(); while(c<=' ')c = read(); while(c>' '){ ans.append((char)c); c = read(); } return ans.toString(); } public byte[] nextByte(int n)throws IOException{ byte[] ans = new byte[n]; for(int i=0;i<n;i++){ ans[i] = nextByte(); } return ans; } public int[] nextInt(int n)throws IOException{ int[] ans = new int[n]; for(int i=0;i<n;i++){ ans[i] = nextInt(); } return ans; } public long[] nextLong(int n)throws IOException{ long[] ans = new long[n]; for(int i=0;i<n;i++){ ans[i] = nextLong(); } return ans; } public String[] next(int n)throws IOException{ String[] ans = new String[n]; for(int i=0;i<n;i++){ ans[i] = next(); } return ans; } public char[] nextCharArray()throws IOException{ return next().toCharArray(); } public void close()throws IOException{ is.close(); } } import java.io.*; import java.util.*; import java.math.*; class Main{ static Library System = new Library(java.lang.System.in,java.lang.System.out); public static void main(String[] args)throws IOException{ int N = System.in.nextInt(); int[] A = System.in.nextInt(N); long gcd = Math.abs(A[1]-A[0]); for(int i=2;i<N;i++){ gcd = System.gcd(gcd,Math.abs(A[i]-A[i-1])); } System.out.println(gcd==1?2:1); System.out.close(); } } /*//////////////////////////////////////////////// * My Library * *///////////////////////////////////////////////// class Library{ SimpleScanner in = null; PrintWriter out = null; private long[] Factorials,InFactorials; public long mod = 0; public Library(InputStream in,OutputStream out){ this.in = new SimpleScanner(in); this.out = new PrintWriter(out); } public Library(InputStream in,OutputStream out,int fac,long mod){ this(in,out); Factorials=new long[fac+1]; Factorials[1]=1; for(int i=2;i<=fac;i++)Factorials[i]=Factorials[i-1]*i%mod; InFactorials=new long[fac+1]; InFactorials[fac]=modPow(Factorials[fac],mod-2,mod); for(int i=fac;i>1;i--)InFactorials[i-1]=InFactorials[i]*i%mod; this.mod = mod; } /** * コンストラクタで渡された値までの * num!、aCbをmodで割ったあまりを返します。 */ public long getFact(int num){ return Factorials[num]; } public long getCombi(int a,int b){ return (Factorials[a]*InFactorials[a-b]%mod)*InFactorials[b]%mod; } /** * ○N! * factではa!を、 * modFactでは引数のmodかコンストラクタで渡されたmodで * 割ったあまりを返します。 */ public static long fact(long a){ long ans=1; for(long i=2;i<=a;i++)ans*=i; return ans; } public static long modFact(long a,long mod){ long ans=1; for(long i=2;i<=a;i++){ ans*=i%mod; ans%=mod; } return ans; } public long modFact(long a){ if(mod==0){ System.err.println("\u001b[00;31m"+"#mod is not defined#"); System.exit(1); } long ans=1; for(long i=2;i<=a;i++){ ans*=i%mod; ans%=mod; } return ans; } /** * ○nCr * CombiではaCb、 * modCombiでは引数のmodかコンストラクタで渡されたmodで * 割ったあまりを返します。 */ public static long combi(long a,long b){ long ans=1; if(b==0||b==a)return 1; if(b<0||b>a)return 0; b=Math.min(a-b,b); for(long i=1;i<=b;i++){ ans*=a--; ans/=i; } return ans; } public static long modCombi(long a,long b,long mod){ long ans=1; if(b==0||b==a)return 1; if(b<0||b>a)return 0; b=Math.min(a-b,b); for(long i=1;i<=b;i++){ ans*=a--; ans%=mod; ans*=modPow(i,mod-2,mod); ans%=mod; } return ans; } public long modCombi(long a,long b){ if(mod==0){ System.err.println("\u001b[00;31m"+"#mod is not defined#"); System.exit(1); } long ans=1; if(b==0||b==a)return 1; if(b<0||b>a)return 0; b=Math.min(a-b,b); for(long i=1;i<=b;i++){ ans*=a--; ans%=mod; ans*=modPow(i,mod-2,mod); ans%=mod; } return ans; } /** * ○ヒープソート * int、long型配列をソートします。 * 二次元配列の場合は[i][0]と[i][1]の大きさで * 昇順に並べ替えます。 */ public static void sort(int[] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&list[(j-1)/2]<list[j]){ int temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ int temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&list[j]<list[2*j+1])||(2*j+2<i-1&&list[j]<list[2*j+2])){ if(2*j+2==i-1||list[2*j+1]>list[2*j+2]){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } public static void sort(int[][] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&(list[(j-1)/2][0]<list[j][0]||(list[(j-1)/2][0]==list[j][0]&&list[(j-1)/2][1]<list[j][1]))){ int[] temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ int[] temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&(list[j][0]<list[2*j+1][0]||(list[j][0]==list[2*j+1][0]&&list[j][1]<list[2*j+1][1])))|| (2*j+2<i-1&&(list[j][0]<list[2*j+2][0]||(list[j][0]==list[2*j+2][0]&&list[j][1]<list[2*j+2][1])))){ if(2*j+2==i-1||(list[2*j+1][0]>list[2*j+2][0]||(list[2*j+1][0]==list[2*j+2][0]&&list[2*j+1][1]>list[2*j+2][1]))){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } public static void sort(long[] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&list[(j-1)/2]<list[j]){ long temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ long temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&list[j]<list[2*j+1])||(2*j+2<i-1&&list[j]<list[2*j+2])){ if(2*j+2==i-1||list[2*j+1]>list[2*j+2]){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } public static void sort(long[][] list){ for(int i=0;i<list.length;i++){ int j=i; while(j>0&&(list[(j-1)/2][0]<list[j][0]||(list[(j-1)/2][0]==list[j][0]&&list[(j-1)/2][1]<list[j][1]))){ long[] temp=list[(j-1)/2]; list[(j-1)/2]=list[j]; list[j]=temp; j=(j-1)/2; } } for(int i=list.length;i>0;i--){ long[] temp=list[i-1]; list[i-1]=list[0]; list[0]=temp; int j=0; while((2*j+1<i-1&&(list[j][0]<list[2*j+1][0]||(list[j][0]==list[2*j+1][0]&&list[j][1]<list[2*j+1][1])))|| (2*j+2<i-1&&(list[j][0]<list[2*j+2][0]||(list[j][0]==list[2*j+2][0]&&list[j][1]<list[2*j+2][1])))){ if(2*j+2==i-1||(list[2*j+1][0]>list[2*j+2][0]||(list[2*j+1][0]==list[2*j+2][0]&&list[2*j+1][1]>list[2*j+2][1]))){ temp=list[2*j+1]; list[2*j+1]=list[j]; list[j]=temp; j<<=1; j++; } else{ temp=list[2*j+2]; list[2*j+2]=list[j]; list[j]=temp; j<<=1; j+=2; } } } } /** * ○カウントソート * int型配列をソートします。 * 最大値が小さい場合は有効です。 */ public static void countSort(int[] nums,int limit){ int[] list=new int[limit+1]; for(int i=0;i<nums.length;i++)list[nums[i]]++; int temp=0; for(int i=0;i<list.length;i++)for(int j=0;j<list[i];j++)nums[temp++]=i; } /** * ○ユークリッドの互除法 * gcdは最大公約数を、 * lcmは最小公倍数を返します。 * lcmはオーバーフローの可能性があるのでご注意を。 * 戻り値はlong型です。 */ public static long gcd(long a,long b){ if(a==0||b==0) return Math.max(a,b); long temp; while((temp=a%b)!=0){ a=b; b=temp; } return b; } public static long lcm(long a,long b){ long mult=a*b,temp; while((temp=a%b)!=0){ a=b; b=temp; } return mult/b; } /** * ○ミラーラビン素数判定法 * BigIntegerクラスのものを使用します。 * 素数である確率が高いならtrue、 * 確実に合成数ならfalseを返します。 * 誤判定の確率は1/2^20以下です。 */ public static boolean isPrime(long num){ return BigInteger.valueOf(num).isProbablePrime(20); } /** * ○エラトステネスの篩 * 引数まで(引数含む)の素数を返します。 * 2^30以上の素数列挙はできないのでご注意を。 */ public static int[] prime(int num){ BitSet nums=new BitSet(num+1); nums.set(2,num+1); for(int i=2;i<=Math.sqrt(num);i++)if(nums.get(i))for(int j=i*i;j<=num;j+=i)nums.clear(j); int[] answer=new int[nums.cardinality()]; int i=2,index=0; while(true){ i=nums.nextSetBit(i); answer[index++]=i++; if(index==answer.length)break; } return answer; } /** * ○繰り返し二乗法 * powではそのままの結果を、 * modPowでは引数のmodかコンストラクタで渡されたmodで * 割ったあまりを返します。 */ public static long pow(long a,long b){ long ans=1; while(b>0){ if((b&1)==1)ans*=a; a*=a; b>>=1; } return ans; } public static long modPow(long a,long b,long mod){ long ans=1; a%=mod; while(b>0){ if((b&1)==1)ans*=a; ans%=mod; a*=a; a%=mod; b>>=1; } return ans; } public long modPow(long a,long b){ if(mod==0){ System.err.println("\u001b[00;31m"+"#mod is not defined#"); System.exit(1); } long ans=1; a%=mod; while(b>0){ if((b&1)==1)ans*=a; ans%=mod; a*=a; a%=mod; b>>=1; } return ans; } /** * ○文字列→整数変換 * Stringをint、longに変換します。 * 数値以外の文字であっても無理矢理数値変換してしまうので * 使用の際はご注意を。 */ public static int parseInt(String str){ char[] nums=str.toCharArray(); int ans=0; boolean plus=true; if(nums[0]=='-'){ plus=!plus; nums[0]='0'; } for(int i=0;i<nums.length;i++)ans=ans*10+nums[i]-'0'; return plus?ans:-ans; } public static long parseLong(String str){ char[] nums=str.toCharArray(); long ans=0; boolean plus=true; if(nums[0]=='-'){ plus=!plus; nums[0]='0'; } for(int i=0;i<nums.length;i++)ans=ans*10+nums[i]-'0'; return plus?ans:-ans; } /** * ○二分探索 * downsearchではnum以下を、 * upsearchではnum以上を探します。 * 引数の配列(List)のインデックスを返します。 */ public static int downsearch(int[] nums,int num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(int[] nums,int num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(long[] nums,long num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(long[] nums,long num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(Integer[] nums,int num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(Integer[] nums,int num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(Long[] nums,long num){ int a=0,b=nums.length-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(Long[] nums,long num){ int a=0,b=nums.length-1,ans=nums.length,c=-1; while(a-b<1){ c=(a+b)/2; if(nums[c]>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(ArrayList<Integer> nums,int num){ int a=0,b=nums.size()-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(ArrayList<Integer> nums,int num){ int a=0,b=nums.size()-1,ans=nums.size(),c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>=num)b=(ans=c)-1; else a=c+1; } return ans; } public static int downsearch(ArrayList<Long> nums,long num){ int a=0,b=nums.size()-1,ans=-1,c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>num)b=c-1; else a=(ans=c)+1; } return ans; } public static int upsearch(ArrayList<Long> nums,long num){ int a=0,b=nums.size()-1,ans=nums.size(),c=-1; while(a-b<1){ c=(a+b)/2; if(nums.get(c)>=num)b=(ans=c)-1; else a=c+1; } return ans; } public void exit(int num){ try{ in.close(); out.close(); }catch(Exception e){ }finally{ System.exit(num); } } @Override public String toString(){ StringBuilder answer=new StringBuilder(); if(Factorials!=null)answer.append("Factorials are defined. (You can use 0~"+(Factorials.length-1)+" for index)"); else answer.append("Factorial is not defined."); answer.append("\n"); if(InFactorials!=null)answer.append("InFactorials are defined. (You can use 0~"+(InFactorials.length-1)+" for index)"); else answer.append("InFactorial is not defined."); answer.append("\n"); if(mod!=0)answer.append("mod is "+mod); else answer.append("mod is not defined."); return answer.toString(); } } /*//////////////////////////////////////////////// * 入力用 * *///////////////////////////////////////////////// class SimpleScanner{ final private int buff_size = 1<<12; private InputStream is; private byte[] buff; private int point,length; public SimpleScanner(InputStream is){ this.is = is; buff = new byte[buff_size]; point = length = 0; } private void reload()throws IOException{ do{ length = is.read(buff,point = 0,buff_size); }while(length==-1); } private byte read()throws IOException{ if(point==length)reload(); return buff[point++]; } public byte nextByte()throws IOException{ byte c = read(); while(c<=' ')c = read(); return c; } public int nextInt()throws IOException{ int ans = 0; byte c = read(); while(c<=' ')c = read(); boolean negate = c == '-'; if(c=='-')c = read(); while('0'<=c&&c<='9'){ ans = ans*10+c-'0'; c = read(); } return negate ? -ans : ans; } public long nextLong()throws IOException{ long ans = 0; byte c = read(); while(c<=' ')c = read(); boolean negate = c == '-'; if(c=='-')c = read(); while('0'<=c&&c<='9'){ ans = ans*10+c-'0'; c = read(); } return negate ? -ans : ans; } public char nextChar()throws IOException{ byte c = read(); while(c<=' ')c = read(); return (char)c; } public String next()throws IOException{ StringBuilder ans = new StringBuilder(); byte c = read(); while(c<=' ')c = read(); while(c>' '){ ans.append((char)c); c = read(); } return ans.toString(); } public byte[] nextByte(int n)throws IOException{ byte[] ans = new byte[n]; for(int i=0;i<n;i++){ ans[i] = nextByte(); } return ans; } public int[] nextInt(int n)throws IOException{ int[] ans = new int[n]; for(int i=0;i<n;i++){ ans[i] = nextInt(); } return ans; } public long[] nextLong(int n)throws IOException{ long[] ans = new long[n]; for(int i=0;i<n;i++){ ans[i] = nextLong(); } return ans; } public String[] next(int n)throws IOException{ String[] ans = new String[n]; for(int i=0;i<n;i++){ ans[i] = next(); } return ans; } public char[] nextCharArray()throws IOException{ return next().toCharArray(); } public void close()throws IOException{ is.close(); } }
ConDefects/ConDefects/Code/arc148_a/Java/34827248
condefects-java_data_6
import java.util.Scanner; public class Main { public static void main( String[] args) { Scanner scn = new Scanner( System.in); int N = scn.nextInt(); int[] array = new int[N]; for ( int i = 0; i < N; i++) { array[i] = scn.nextInt(); } int[] difArray = new int[N - 1]; for ( int j = 0; j < N - 1; j++) { difArray[j] = array[j + 1] - array[j]; } int firstDif = difArray[0]; for ( int dif : difArray) { while ( firstDif > 1) { if ( dif % firstDif == 0) { break; } int tmp = dif % firstDif; dif = firstDif; firstDif = tmp; } if ( firstDif == 1) { System.out.println( 2); return; } } System.out.println( 1); } } import java.util.Arrays; import java.util.Scanner; public class Main { public static void main( String[] args) { Scanner scn = new Scanner( System.in); int N = scn.nextInt(); int[] array = new int[N]; for ( int i = 0; i < N; i++) { array[i] = scn.nextInt(); } Arrays.parallelSort( array); int[] difArray = new int[N - 1]; for ( int j = 0; j < N - 1; j++) { difArray[j] = array[j + 1] - array[j]; } int firstDif = difArray[0]; for ( int dif : difArray) { while ( firstDif > 1) { if ( dif % firstDif == 0) { break; } int tmp = dif % firstDif; dif = firstDif; firstDif = tmp; } if ( firstDif == 1) { System.out.println( 2); return; } } System.out.println( 1); } }
ConDefects/ConDefects/Code/arc148_a/Java/40885914
condefects-java_data_7
import java.io.*; import java.util.*; import java.util.function.*; class Solver { private static final long INF = Long.MAX_VALUE; private final int n; private final long m; private final long[] ds; private ModCalculator mc; private long[] ghTable; private long[] cache; private long gcd(long a, long b) { return a % b == 0 ? b : gcd(b, a % b); } private long lcm(long a, long b) { if (a == INF || b == INF) { return INF; } long g = gcd(a, b); a /= g; double ad = a; double bd = b; if (ad * bd > 2 * m) { return INF; } long candidate = a * b; if (candidate > m) { return INF; } return candidate; } private long gh(int bitset) { long lcmValue = 1; for (int i = 0; i < n; i++) { if (((bitset >> i) & 1) == 1) { lcmValue = lcm(lcmValue, ds[i]); } } long v = Integer.bitCount(bitset) % 2 == 1 ? 1 : mc.norm(-1); v = mc.mul(v, mc.getF(Integer.bitCount(bitset) - 1)); v = mc.mul(v, m / lcmValue); return v; } private long solve(int bitset) { if (bitset == 0) { return 1; } if (cache[bitset] >= 0) { return cache[bitset]; } cache[bitset] = 0; for (int subBitset = bitset; subBitset > 0; subBitset = (subBitset - 1) & bitset) { if ((subBitset & Integer.lowestOneBit(bitset)) != 0) { long v = mc.mul(ghTable[subBitset], solve(bitset - subBitset)); cache[bitset] = mc.add(cache[bitset], v); } } return cache[bitset]; } public Solver(int n, long m, long[] ds) { this.n = n; this.m = m; this.ds = ds; } public long solve() { mc = new ModCalculator(998244353); ghTable = new long[1 << n]; for (int bitset = 1; bitset < (1 << n); bitset++) { ghTable[bitset] = gh(bitset); } cache = new long[1 << n]; Arrays.fill(cache, -1); return solve((1 << n) - 1); } }; class ModCalculator { private final long mod; private final ModInverseCache modInverseCache; private final ModCombinationCache modCombinationCache; ModCalculator(long mod) { this.mod = mod; this.modInverseCache = new ModInverseCache(); this.modCombinationCache = new ModCombinationCache(); } public long norm(long v) { long nogmalized = v % mod; if (nogmalized < 0) { nogmalized += mod; } return nogmalized; } public long add(long a, long b) { return norm(a + b); } public long sub(long a, long b) { return norm(a - b + mod); } public long mul(long a, long b) { return norm(a * b); } public long pow(long a, long b) { if (b == 0) { return 1; } long v = pow(mul(a, a), b / 2); if (b % 2 == 1) { return mul(v, a); } else { return v; } } public long inverse(long a) { return pow(a, mod - 2); } public long inverseFromCache(int a) { return modInverseCache.get(a); } public long div(long a, long b) { return mul(a, inverse(b)); } // Verify ARC 042 D // https://atcoder.jp/contests/arc042/tasks/arc042_d // a^x mod p === b // return -1 there is no such positive x public long log(long a, long b) { Map<Long, Long> map = new HashMap<>(); long powA = 1; long rootP = 0; while (true) { if (powA == b && rootP != 0) { return rootP; } if (map.containsKey(powA)) { return -1; } map.put(powA, rootP); powA = mul(powA, a); rootP++; if (rootP * rootP > mod) { break; } } long inversePowA = inverse(powA); for (int i = 1; i <= rootP; i++) { b = mul(b, inversePowA); Long value = map.get(b); if (value != null && value + rootP * i > 0) { return value + rootP * i; } } return -1; } public long getF(int n) { return modCombinationCache.getF(n); } public long getP(int n, int r) { return modCombinationCache.getP(n, r); } public long getC(int n, int k) { return modCombinationCache.getC(n, k); } // Verify ttpc2019 J // https://atcoder.jp/contests/ttpc2019/tasks/ttpc2019_j class PrimitiveLongList { long[] values; int size; public PrimitiveLongList() { values = new long[10]; } private void resize() { long[] newValues = new long[values.length * 2]; System.arraycopy(values, 0, newValues, 0, values.length); values = newValues; } public void add(long value) { if (size >= values.length) { resize(); } values[size] = value; size++; } private void validateIndex(int index) { if (index < 0 || size <= index) { throw new IndexOutOfBoundsException( String.format("size: %d, index: %d", size, index)); } } public long get(int index) { validateIndex(index); return values[index]; } public void set(int index, long value) { validateIndex(index); values[index] = value; } public int size() { return size; } } // Verify AGC 040 C // https://atcoder.jp/contests/agc040/tasks/agc040_c class ModInverseCache { private final PrimitiveLongList inverseCache; public ModInverseCache() { inverseCache = new PrimitiveLongList(); inverseCache.add(0L); inverseCache.add(1L); } private void resize(int n) { for (int i = inverseCache.size(); i <= n; i++) { long k = mod / i; int r = (int)(mod % i); long inverse = mul(-k, inverseCache.get(r)); inverseCache.add(inverse); } } long get(int n) { resize(n); return inverseCache.get(n); } } class ModCombinationCache { private final PrimitiveLongList factorialCache; private final PrimitiveLongList factorialInverseCache; public ModCombinationCache() { factorialCache = new PrimitiveLongList(); factorialCache.add(1L); factorialInverseCache = new PrimitiveLongList(); factorialInverseCache.add(1L); } private void resize(int n) { for (int i = factorialCache.size() - 1; i < n; i++) { factorialCache.add(mul(factorialCache.get(i), i + 1)); factorialInverseCache.add( mul(factorialInverseCache.get(i), modInverseCache.get(i + 1))); } } long getF(int n) { resize(n); return factorialCache.get(n); } long getP(int n, int r) { resize(n); return mul(factorialCache.get(n), factorialInverseCache.get(n - r)); } long getC(int n, int k) { resize(n); return mul(factorialCache.get(n), mul(factorialInverseCache.get(k), factorialInverseCache.get(n - k))); } } } public class Main { private static void execute(ContestReader reader, ContestWriter out) { int n = reader.nextInt(); long m = reader.nextLong(); long[] ds = reader.nextLong(n); out.println(new Solver(n, m, ds).solve()); } public static void main(String[] args) { ContestReader reader = new ContestReader(System.in); ContestWriter out = new ContestWriter(System.out); execute(reader, out); out.flush(); } } class ContestWriter extends PrintWriter { ContestWriter(PrintStream printStream) { super(printStream); } public void printList(List<? extends Object> list) { for (Object object : list) { println(object); } } public void printListOneLine(List<? extends Object> list) { List<String> stringList = new ArrayList<>(); for (Object object : list) { stringList.add(object.toString()); } println(String.join(" ", stringList)); } } class ContestReader { private static final int BUFFER_SIZE = 1024; private final InputStream stream; private final byte[] buffer; private int pointer; private int bufferLength; ContestReader(InputStream stream) { this.stream = stream; this.buffer = new byte[BUFFER_SIZE]; this.pointer = 0; this.bufferLength = 0; } private boolean hasNextByte() { if (pointer < bufferLength) { return true; } pointer = 0; try { bufferLength = stream.read(buffer); } catch (IOException e) { throw new RuntimeException(e); } return bufferLength > 0; } private int readByte() { if (hasNextByte()) { return buffer[pointer++]; } else { return -1; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[pointer])) { pointer++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); while(true) { int b = readByte(); if (!isPrintableChar(b)) { break; } sb.appendCodePoint(b); } return sb.toString(); } public String nextLine() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); while(true) { int b = readByte(); if (!isPrintableChar(b) && b != 0x20) { break; } sb.appendCodePoint(b); } return sb.toString(); } public char nextChar() { return next().charAt(0); } public int nextInt() { if (!hasNext()) { throw new NoSuchElementException(); } int n = 0; boolean minus = false; { int b = readByte(); if (b == '-') { minus = true; } else if ('0' <= b && b <= '9') { n = b - '0'; } else { throw new NumberFormatException(); } } while(true){ int b = readByte(); if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } } } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; { int b = readByte(); if (b == '-') { minus = true; } else if ('0' <= b && b <= '9') { n = b - '0'; } else { throw new NumberFormatException(); } } while(true){ int b = readByte(); if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } } } public double nextDouble() { return Double.parseDouble(next()); } public String[] next(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = next(); } return array; } public String[] nextLine(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = nextLine(); } return array; } public char[] nextChar(int n) { char[] array = new char[n]; for (int i = 0; i < n; i++) { array[i] = nextChar(); } return array; } public int[] nextInt(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } public long[] nextLong(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = nextLong(); } return array; } public double[] nextDouble(int n) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = nextDouble(); } return array; } public char[] nextCharArray() { return next().toCharArray(); } public String[][] next(int n, int m) { String[][] matrix = new String[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = next(); } } return matrix; } public int[][] nextInt(int n, int m) { int[][] matrix = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextInt(); } } return matrix; } public char[][] nextChar(int n, int m) { char[][] matrix = new char[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextChar(); } } return matrix; } public long[][] nextLong(int n, int m) { long[][] matrix = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextLong(); } } return matrix; } public double[][] nextDouble(int n, int m) { double[][] matrix = new double[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextDouble(); } } return matrix; } public char[][] nextCharArray(int n) { char[][] matrix = new char[n][]; for (int i = 0; i < n; i++) { matrix[i] = next().toCharArray(); } return matrix; } } class MyAssert { public static void myAssert(boolean flag, String message) { if (!flag) { throw new RuntimeException(message); } } public static void myAssert(boolean flag) { myAssert(flag, ""); } } import java.io.*; import java.util.*; import java.util.function.*; class Solver { private static final long INF = Long.MAX_VALUE; private final int n; private final long m; private final long[] ds; private ModCalculator mc; private long[] ghTable; private long[] cache; private long gcd(long a, long b) { return a % b == 0 ? b : gcd(b, a % b); } private long lcm(long a, long b) { if (a == INF || b == INF) { return INF; } long g = gcd(a, b); a /= g; double ad = a; double bd = b; if (ad * bd > 2 * m) { return INF; } long candidate = a * b; if (candidate > m) { return INF; } return candidate; } private long gh(int bitset) { long lcmValue = 1; for (int i = 0; i < n; i++) { if (((bitset >> i) & 1) == 1) { lcmValue = lcm(lcmValue, ds[i]); } } long v = Integer.bitCount(bitset) % 2 == 1 ? 1 : mc.norm(-1); v = mc.mul(v, mc.getF(Integer.bitCount(bitset) - 1)); v = mc.mul(v, mc.norm(m / lcmValue)); return v; } private long solve(int bitset) { if (bitset == 0) { return 1; } if (cache[bitset] >= 0) { return cache[bitset]; } cache[bitset] = 0; for (int subBitset = bitset; subBitset > 0; subBitset = (subBitset - 1) & bitset) { if ((subBitset & Integer.lowestOneBit(bitset)) != 0) { long v = mc.mul(ghTable[subBitset], solve(bitset - subBitset)); cache[bitset] = mc.add(cache[bitset], v); } } return cache[bitset]; } public Solver(int n, long m, long[] ds) { this.n = n; this.m = m; this.ds = ds; } public long solve() { mc = new ModCalculator(998244353); ghTable = new long[1 << n]; for (int bitset = 1; bitset < (1 << n); bitset++) { ghTable[bitset] = gh(bitset); } cache = new long[1 << n]; Arrays.fill(cache, -1); return solve((1 << n) - 1); } }; class ModCalculator { private final long mod; private final ModInverseCache modInverseCache; private final ModCombinationCache modCombinationCache; ModCalculator(long mod) { this.mod = mod; this.modInverseCache = new ModInverseCache(); this.modCombinationCache = new ModCombinationCache(); } public long norm(long v) { long nogmalized = v % mod; if (nogmalized < 0) { nogmalized += mod; } return nogmalized; } public long add(long a, long b) { return norm(a + b); } public long sub(long a, long b) { return norm(a - b + mod); } public long mul(long a, long b) { return norm(a * b); } public long pow(long a, long b) { if (b == 0) { return 1; } long v = pow(mul(a, a), b / 2); if (b % 2 == 1) { return mul(v, a); } else { return v; } } public long inverse(long a) { return pow(a, mod - 2); } public long inverseFromCache(int a) { return modInverseCache.get(a); } public long div(long a, long b) { return mul(a, inverse(b)); } // Verify ARC 042 D // https://atcoder.jp/contests/arc042/tasks/arc042_d // a^x mod p === b // return -1 there is no such positive x public long log(long a, long b) { Map<Long, Long> map = new HashMap<>(); long powA = 1; long rootP = 0; while (true) { if (powA == b && rootP != 0) { return rootP; } if (map.containsKey(powA)) { return -1; } map.put(powA, rootP); powA = mul(powA, a); rootP++; if (rootP * rootP > mod) { break; } } long inversePowA = inverse(powA); for (int i = 1; i <= rootP; i++) { b = mul(b, inversePowA); Long value = map.get(b); if (value != null && value + rootP * i > 0) { return value + rootP * i; } } return -1; } public long getF(int n) { return modCombinationCache.getF(n); } public long getP(int n, int r) { return modCombinationCache.getP(n, r); } public long getC(int n, int k) { return modCombinationCache.getC(n, k); } // Verify ttpc2019 J // https://atcoder.jp/contests/ttpc2019/tasks/ttpc2019_j class PrimitiveLongList { long[] values; int size; public PrimitiveLongList() { values = new long[10]; } private void resize() { long[] newValues = new long[values.length * 2]; System.arraycopy(values, 0, newValues, 0, values.length); values = newValues; } public void add(long value) { if (size >= values.length) { resize(); } values[size] = value; size++; } private void validateIndex(int index) { if (index < 0 || size <= index) { throw new IndexOutOfBoundsException( String.format("size: %d, index: %d", size, index)); } } public long get(int index) { validateIndex(index); return values[index]; } public void set(int index, long value) { validateIndex(index); values[index] = value; } public int size() { return size; } } // Verify AGC 040 C // https://atcoder.jp/contests/agc040/tasks/agc040_c class ModInverseCache { private final PrimitiveLongList inverseCache; public ModInverseCache() { inverseCache = new PrimitiveLongList(); inverseCache.add(0L); inverseCache.add(1L); } private void resize(int n) { for (int i = inverseCache.size(); i <= n; i++) { long k = mod / i; int r = (int)(mod % i); long inverse = mul(-k, inverseCache.get(r)); inverseCache.add(inverse); } } long get(int n) { resize(n); return inverseCache.get(n); } } class ModCombinationCache { private final PrimitiveLongList factorialCache; private final PrimitiveLongList factorialInverseCache; public ModCombinationCache() { factorialCache = new PrimitiveLongList(); factorialCache.add(1L); factorialInverseCache = new PrimitiveLongList(); factorialInverseCache.add(1L); } private void resize(int n) { for (int i = factorialCache.size() - 1; i < n; i++) { factorialCache.add(mul(factorialCache.get(i), i + 1)); factorialInverseCache.add( mul(factorialInverseCache.get(i), modInverseCache.get(i + 1))); } } long getF(int n) { resize(n); return factorialCache.get(n); } long getP(int n, int r) { resize(n); return mul(factorialCache.get(n), factorialInverseCache.get(n - r)); } long getC(int n, int k) { resize(n); return mul(factorialCache.get(n), mul(factorialInverseCache.get(k), factorialInverseCache.get(n - k))); } } } public class Main { private static void execute(ContestReader reader, ContestWriter out) { int n = reader.nextInt(); long m = reader.nextLong(); long[] ds = reader.nextLong(n); out.println(new Solver(n, m, ds).solve()); } public static void main(String[] args) { ContestReader reader = new ContestReader(System.in); ContestWriter out = new ContestWriter(System.out); execute(reader, out); out.flush(); } } class ContestWriter extends PrintWriter { ContestWriter(PrintStream printStream) { super(printStream); } public void printList(List<? extends Object> list) { for (Object object : list) { println(object); } } public void printListOneLine(List<? extends Object> list) { List<String> stringList = new ArrayList<>(); for (Object object : list) { stringList.add(object.toString()); } println(String.join(" ", stringList)); } } class ContestReader { private static final int BUFFER_SIZE = 1024; private final InputStream stream; private final byte[] buffer; private int pointer; private int bufferLength; ContestReader(InputStream stream) { this.stream = stream; this.buffer = new byte[BUFFER_SIZE]; this.pointer = 0; this.bufferLength = 0; } private boolean hasNextByte() { if (pointer < bufferLength) { return true; } pointer = 0; try { bufferLength = stream.read(buffer); } catch (IOException e) { throw new RuntimeException(e); } return bufferLength > 0; } private int readByte() { if (hasNextByte()) { return buffer[pointer++]; } else { return -1; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[pointer])) { pointer++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); while(true) { int b = readByte(); if (!isPrintableChar(b)) { break; } sb.appendCodePoint(b); } return sb.toString(); } public String nextLine() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); while(true) { int b = readByte(); if (!isPrintableChar(b) && b != 0x20) { break; } sb.appendCodePoint(b); } return sb.toString(); } public char nextChar() { return next().charAt(0); } public int nextInt() { if (!hasNext()) { throw new NoSuchElementException(); } int n = 0; boolean minus = false; { int b = readByte(); if (b == '-') { minus = true; } else if ('0' <= b && b <= '9') { n = b - '0'; } else { throw new NumberFormatException(); } } while(true){ int b = readByte(); if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } } } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; { int b = readByte(); if (b == '-') { minus = true; } else if ('0' <= b && b <= '9') { n = b - '0'; } else { throw new NumberFormatException(); } } while(true){ int b = readByte(); if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } } } public double nextDouble() { return Double.parseDouble(next()); } public String[] next(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = next(); } return array; } public String[] nextLine(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = nextLine(); } return array; } public char[] nextChar(int n) { char[] array = new char[n]; for (int i = 0; i < n; i++) { array[i] = nextChar(); } return array; } public int[] nextInt(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } public long[] nextLong(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = nextLong(); } return array; } public double[] nextDouble(int n) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = nextDouble(); } return array; } public char[] nextCharArray() { return next().toCharArray(); } public String[][] next(int n, int m) { String[][] matrix = new String[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = next(); } } return matrix; } public int[][] nextInt(int n, int m) { int[][] matrix = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextInt(); } } return matrix; } public char[][] nextChar(int n, int m) { char[][] matrix = new char[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextChar(); } } return matrix; } public long[][] nextLong(int n, int m) { long[][] matrix = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextLong(); } } return matrix; } public double[][] nextDouble(int n, int m) { double[][] matrix = new double[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = nextDouble(); } } return matrix; } public char[][] nextCharArray(int n) { char[][] matrix = new char[n][]; for (int i = 0; i < n; i++) { matrix[i] = next().toCharArray(); } return matrix; } } class MyAssert { public static void myAssert(boolean flag, String message) { if (!flag) { throw new RuntimeException(message); } } public static void myAssert(boolean flag) { myAssert(flag, ""); } }
ConDefects/ConDefects/Code/abc236_h/Java/29799526
condefects-java_data_8
// OM NAMAH SHIVAY // Stay strong. Be brave. Always belief. import com.sun.source.tree.Tree; import javax.swing.*; import java.math.BigInteger; import java.rmi.server.RMIServerSocketFactory; import java.util.*; import java.io.*; public class Main { static boolean prime[]; static class Pair implements Comparable<Pair> { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o){ if(this.y!=o.y) return this.y-o.y; else return o.x-this.x; } } static long power(long x, long y, long p) { if (y == 0) return 1; if (x == 0) return 0; long res = 1l; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readlongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static void sieveOfEratosthenes(int n) { prime = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } public static int log2(long x) { int v = (int) (Math.log(x) / Math.log(2)); return v; } static long binomialCoeff(long n, long r) { if (r > n) return 0l; long inv[] = new long[(int) r + 1]; inv[0] = 1; if (r + 1 >= 2) inv[1] = 1; for (int i = 2; i <= r; i++) { inv[i] = mod1 - (mod1 / i) * inv[(int) (mod1 % i)] % mod1; } long ans = 1l; for (int i = 2; i <= r; i++) { ans = (int) (((ans % mod1) * (inv[i] % mod1)) % mod1); } for (int i = (int) n; i >= (n - r + 1); i--) { ans = (int) (((ans % mod1) * (i % mod1)) % mod1); } return ans; } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } static long[] facts = new long[3_000_00]; static BigInteger bi(String str) { return new BigInteger(str); } static FastScanner fs = null; static long mod1 = 1000000007; static int pre[]; static PrintWriter out; static long h[][]; static long w[][]; static ArrayList<Long> a1; static int fuck_edge = -1; static int dis[]; static int low[]; static int timer; //static boolean vis[]; static Pair a[]; static boolean vis[]; static long dp[][]; static boolean bip = true; static int col[]; static long mod = 998244353; static ArrayList<int[]> al[]; public static void main(String[] args) { fs = new FastScanner(); out = new PrintWriter(System.out); int t = 1; outer: while (t-- > 0) { long ans = -1; int n = fs.nextInt(); int m = fs.nextInt(); long a[] = fs.readlongArray(n); long l = 0; long r = (long) 1e18; while (l <= r) { long mid = (l + r) >> 1; if (check(mid, a, m)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } out.println(ans); } out.close(); } public static boolean check(long len, long a[],int line){ long lin = 0l; long curr = len; long cur=0; for(int i=0;i<a.length;i++){ if(cur>0) curr--; if(curr<a[i]) { lin++; curr = len; cur=0; } if(lin>line || curr<a[i]) return false; curr -= a[i]; cur++; } return lin<=line; } static long ans; static class SegmentTree{ int tree[]; int ar[]; SegmentTree(int n,int arr[]){ tree = new int[4*n]; this.ar = arr; build(1,arr,0,arr.length-1); } public void build(int node, int arr[], int l, int r){ if(l==r) { tree[node] = arr[l]; ar[l]=arr[l]; } int mid = (l+r)/2; build(node*2,arr,l,mid); build(node*2 +1, arr,mid+1,r); tree[node] = Math.max(tree[2*node],tree[2*node + 1]); } public void update(int node, int pos, int val, int l , int r){ if(l==r) { tree[node] = val; ar[l]=node; } if(l>r) return; int mid = (l+r)/2; if(mid<pos){ update(2*node+1,pos,val,mid+1,r); }else{ update(2*node,pos,val,l,mid); } tree[node] = Math.max(tree[node*2],tree[2*node + 1]); } public int query(int node, int queryLeft, int queryRight, int left, int right){ if (queryLeft <= left && right <= queryRight) return tree[node]; int mid = left + (right - left) / 2; int minValue = Integer.MIN_VALUE; if (queryLeft <= mid) minValue = Math.max(minValue, query(2 * node + 1, left, mid, queryLeft, queryRight)); if (queryRight > mid) minValue = Math.max(minValue, query(2 * node + 2, mid + 1, right, queryLeft, queryRight)); return minValue; } } static long expo(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) > 0) res = (res * a) % mod; a = (a * a) % mod; b = b >> 1; } return res; } static long mminvprime(long a, long b) { return expo(a, b - 2, b); } static long mod_add(long a, long b, long m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; } static long mod_ml(long a, long b, long m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; } static long mod_sb(long a, long b, long m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; } static long mod_dv(long a, long b, long m) { a = a % m; b = b % m; return (mod_ml(a, mminvprime(b, m), m) + m) % m; } } class DisjointSetUnion{ int[] parent; private int N; public DisjointSetUnion(int n){ this.N = n; this.parent = new int[this.N]; for(int i = 0; i < this.N; i++){ this.parent[i] = i; } } public boolean areConnected(int u, int v){ return find(u) == find(v); } public void union(int u, int v){ if(u != v){ int a = find(u); int b = find(v); parent[a] = b; } } public int find(int u){ int x = u; while(x != this.parent[x]){ x = this.parent[x]; } this.parent[u] = x; return x; } } class Fenwick{ long bit[]; int n; Fenwick(int n){ bit = new long[n+1]; this.n=n; } public void update(int x, int v){ int i=x; while(i<=this.n){ bit[i] += v; i += i&(-i); } } public long sum(int x){ long sum=0; int i=x; while(i>=1){ sum += bit[i]; i -= i&(-i); } return sum; } } // Arrays.sort(one, Comparator.comparingLong(o->o[0])); //Arrays.sort(wt,(t1,t2) -> { // return (int)(t2.w - t1.w); // }); //Arrays.sort(arr, new Comparator<int[]>() { //public int compare(int[] frst, int[] scnd) { // if(frst[colmn-1] > scnd[colmn-1]) { // return 1; // } // else return -1; // } // }); //class Trie{ // Trie[] links; // public Trie(int m){ // links = new Trie[m+1]; // } // OM NAMAH SHIVAY // Stay strong. Be brave. Always belief. import com.sun.source.tree.Tree; import javax.swing.*; import java.math.BigInteger; import java.rmi.server.RMIServerSocketFactory; import java.util.*; import java.io.*; public class Main { static boolean prime[]; static class Pair implements Comparable<Pair> { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o){ if(this.y!=o.y) return this.y-o.y; else return o.x-this.x; } } static long power(long x, long y, long p) { if (y == 0) return 1; if (x == 0) return 0; long res = 1l; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readlongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static void sieveOfEratosthenes(int n) { prime = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } public static int log2(long x) { int v = (int) (Math.log(x) / Math.log(2)); return v; } static long binomialCoeff(long n, long r) { if (r > n) return 0l; long inv[] = new long[(int) r + 1]; inv[0] = 1; if (r + 1 >= 2) inv[1] = 1; for (int i = 2; i <= r; i++) { inv[i] = mod1 - (mod1 / i) * inv[(int) (mod1 % i)] % mod1; } long ans = 1l; for (int i = 2; i <= r; i++) { ans = (int) (((ans % mod1) * (inv[i] % mod1)) % mod1); } for (int i = (int) n; i >= (n - r + 1); i--) { ans = (int) (((ans % mod1) * (i % mod1)) % mod1); } return ans; } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } static long[] facts = new long[3_000_00]; static BigInteger bi(String str) { return new BigInteger(str); } static FastScanner fs = null; static long mod1 = 1000000007; static int pre[]; static PrintWriter out; static long h[][]; static long w[][]; static ArrayList<Long> a1; static int fuck_edge = -1; static int dis[]; static int low[]; static int timer; //static boolean vis[]; static Pair a[]; static boolean vis[]; static long dp[][]; static boolean bip = true; static int col[]; static long mod = 998244353; static ArrayList<int[]> al[]; public static void main(String[] args) { fs = new FastScanner(); out = new PrintWriter(System.out); int t = 1; outer: while (t-- > 0) { long ans = -1; int n = fs.nextInt(); int m = fs.nextInt(); long a[] = fs.readlongArray(n); long l = 0; long r = (long) 1e18; while (l <= r) { long mid = (l + r) >> 1; if (check(mid, a, m)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } out.println(ans); } out.close(); } public static boolean check(long len, long a[],int line){ long lin = 1l; long curr = len; long cur=0; for(int i=0;i<a.length;i++){ if(cur>0) curr--; if(curr<a[i]) { lin++; curr = len; cur=0; } if(lin>line || curr<a[i]) return false; curr -= a[i]; cur++; } return lin<=line; } static long ans; static class SegmentTree{ int tree[]; int ar[]; SegmentTree(int n,int arr[]){ tree = new int[4*n]; this.ar = arr; build(1,arr,0,arr.length-1); } public void build(int node, int arr[], int l, int r){ if(l==r) { tree[node] = arr[l]; ar[l]=arr[l]; } int mid = (l+r)/2; build(node*2,arr,l,mid); build(node*2 +1, arr,mid+1,r); tree[node] = Math.max(tree[2*node],tree[2*node + 1]); } public void update(int node, int pos, int val, int l , int r){ if(l==r) { tree[node] = val; ar[l]=node; } if(l>r) return; int mid = (l+r)/2; if(mid<pos){ update(2*node+1,pos,val,mid+1,r); }else{ update(2*node,pos,val,l,mid); } tree[node] = Math.max(tree[node*2],tree[2*node + 1]); } public int query(int node, int queryLeft, int queryRight, int left, int right){ if (queryLeft <= left && right <= queryRight) return tree[node]; int mid = left + (right - left) / 2; int minValue = Integer.MIN_VALUE; if (queryLeft <= mid) minValue = Math.max(minValue, query(2 * node + 1, left, mid, queryLeft, queryRight)); if (queryRight > mid) minValue = Math.max(minValue, query(2 * node + 2, mid + 1, right, queryLeft, queryRight)); return minValue; } } static long expo(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) > 0) res = (res * a) % mod; a = (a * a) % mod; b = b >> 1; } return res; } static long mminvprime(long a, long b) { return expo(a, b - 2, b); } static long mod_add(long a, long b, long m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; } static long mod_ml(long a, long b, long m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; } static long mod_sb(long a, long b, long m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; } static long mod_dv(long a, long b, long m) { a = a % m; b = b % m; return (mod_ml(a, mminvprime(b, m), m) + m) % m; } } class DisjointSetUnion{ int[] parent; private int N; public DisjointSetUnion(int n){ this.N = n; this.parent = new int[this.N]; for(int i = 0; i < this.N; i++){ this.parent[i] = i; } } public boolean areConnected(int u, int v){ return find(u) == find(v); } public void union(int u, int v){ if(u != v){ int a = find(u); int b = find(v); parent[a] = b; } } public int find(int u){ int x = u; while(x != this.parent[x]){ x = this.parent[x]; } this.parent[u] = x; return x; } } class Fenwick{ long bit[]; int n; Fenwick(int n){ bit = new long[n+1]; this.n=n; } public void update(int x, int v){ int i=x; while(i<=this.n){ bit[i] += v; i += i&(-i); } } public long sum(int x){ long sum=0; int i=x; while(i>=1){ sum += bit[i]; i -= i&(-i); } return sum; } } // Arrays.sort(one, Comparator.comparingLong(o->o[0])); //Arrays.sort(wt,(t1,t2) -> { // return (int)(t2.w - t1.w); // }); //Arrays.sort(arr, new Comparator<int[]>() { //public int compare(int[] frst, int[] scnd) { // if(frst[colmn-1] > scnd[colmn-1]) { // return 1; // } // else return -1; // } // }); //class Trie{ // Trie[] links; // public Trie(int m){ // links = new Trie[m+1]; // }
ConDefects/ConDefects/Code/abc319_d/Java/45440803
condefects-java_data_9
import java.util.*; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long m = sc.nextInt(); long[] line = new long[n]; long sum = 0; long max = 0; for(int i = 0;i < n;i++) { line[i] = Integer.parseInt(sc.next()); sum += line[i]; max = Math.max(max, line[i]); }long right = max * ((long)n - m + 1) + ((long)n - m) + 1; long left = 0; while(left < right - 1) { long mid = (left + right)/2; long nowW = 0; long nowH = 0; for(int i = 0;i < n;i++) { if(nowW + line[i] <= mid) { nowW += line[i]; nowW++; }else if(nowW + line[i] > mid) { nowW = line[i]; nowW++; nowH++; }if(nowW >= mid && i != n - 1) { nowH++; nowW = 0; } }if(nowH <= m - 1) { right = mid; }else if(nowH > m - 1){ left = mid; } //System.out.println(left + " " + right); }System.out.print(right); } } import java.util.*; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long m = sc.nextInt(); long[] line = new long[n]; long sum = 0; long max = 0; for(int i = 0;i < n;i++) { line[i] = Integer.parseInt(sc.next()); sum += line[i]; max = Math.max(max, line[i]); }long right = max * ((long)n - m + 1) + ((long)n - m) + 1; long left = max - 1; while(left < right - 1) { long mid = (left + right)/2; long nowW = 0; long nowH = 0; for(int i = 0;i < n;i++) { if(nowW + line[i] <= mid) { nowW += line[i]; nowW++; }else if(nowW + line[i] > mid) { nowW = line[i]; nowW++; nowH++; }if(nowW >= mid && i != n - 1) { nowH++; nowW = 0; } }if(nowH <= m - 1) { right = mid; }else if(nowH > m - 1){ left = mid; } //System.out.println(left + " " + right); }System.out.print(right); } }
ConDefects/ConDefects/Code/abc319_d/Java/45403304
condefects-java_data_10
// 18:32:21 09-09-2023 // D - Minimum Width // https://atcoder.jp/contests/abc319/tasks/abc319_d // 2000 ms import java.io.*; import java.util.*; import java.util.function.IntUnaryOperator; import java.util.function.LongUnaryOperator; import java.util.stream.Collectors; public class Main { static In in = new FastIn(); static Out out = new Out(false); static final long inf = 0x1fffffffffffffffL; static final int iinf = 0x3fffffff; static final double eps = 1e-9; static long mod = 998244353; void solve() { int n = inp() , k = inp(); long[] arr = in.nextLongArray(n); long l = -1 , r = 1_000_000_000_000_000L; while(r - l > 1){ long m = (l + r) / 2; if(check(arr , m) <= k) r = m; else l = m; } // out.println(check(arr , 26L)); out.println(r); } int check(long[] arr , long m){ int cnt = 0; long sum = 0; for(int i = 0 ; i < arr.length ; i++){ sum = sum + arr[i] + 1; if(sum - 1 == m){ sum = 0; cnt++; continue; } if(sum > m){ cnt++; sum = arr[i] + 1; } } if(sum > 0) cnt++; return cnt; } public static void main(String... args) { int ntc = 1; // ntc = in.nextInt(); for(int i = 1 ; i <= ntc ; i++) new Main().solve(); out.flush(); } int inp(){ return in.nextInt(); } } class FastIn extends In { private final BufferedInputStream reader = new BufferedInputStream(System.in); private final byte[] buffer = new byte[0x10000]; private int i = 0; private int length = 0; public int read() { if (i == length) { i = 0; try { length = reader.read(buffer); } catch (IOException ignored) { } if (length == -1) { return 0; } } if (length <= i) { throw new RuntimeException(); } return buffer[i++]; } String next() { StringBuilder builder = new StringBuilder(); int b = read(); while (b < '!' || '~' < b) { b = read(); } while ('!' <= b && b <= '~') { builder.appendCodePoint(b); b = read(); } return builder.toString(); } String nextLine() { StringBuilder builder = new StringBuilder(); int b = read(); while (b != 0 && b != '\r' && b != '\n') { builder.appendCodePoint(b); b = read(); } if (b == '\r') { read(); } return builder.toString(); } int nextInt() { long val = nextLong(); if ((int)val != val) { throw new NumberFormatException(); } return (int)val; } long nextLong() { int b = read(); while (b < '!' || '~' < b) { b = read(); } boolean neg = false; if (b == '-') { neg = true; b = read(); } long n = 0; int c = 0; while ('0' <= b && b <= '9') { n = n * 10 + b - '0'; b = read(); c++; } if (c == 0 || c >= 2 && n == 0) { throw new NumberFormatException(); } return neg ? -n : n; } } class In { private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000); private StringTokenizer tokenizer; String next() { try { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (IOException ignored) { } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char[] nextCharArray() { return next().toCharArray(); } String[] nextStringArray(int n) { String[] s = new String[n]; for (int i = 0; i < n; i++) { s[i] = next(); } return s; } char[][] nextCharGrid(int n, int m) { char[][] a = new char[n][m]; for (int i = 0; i < n; i++) { a[i] = next().toCharArray(); } return a; } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } int[] nextIntArray(int n, IntUnaryOperator op) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsInt(nextInt()); } return a; } int[][] nextIntMatrix(int h, int w) { int[][] a = new int[h][w]; for (int i = 0; i < h; i++) { a[i] = nextIntArray(w); } return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } long[] nextLongArray(int n, LongUnaryOperator op) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsLong(nextLong()); } return a; } long[][] nextLongMatrix(int h, int w) { long[][] a = new long[h][w]; for (int i = 0; i < h; i++) { a[i] = nextLongArray(w); } return a; } List<List<Integer>> nextEdges(int n, int m, boolean directed) { List<List<Integer>> res = new ArrayList<>(); for (int i = 0; i < n; i++) { res.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; res.get(u).add(v); if (!directed) { res.get(v).add(u); } } return res; } } class Out { private final PrintWriter out = new PrintWriter(System.out); private final PrintWriter err = new PrintWriter(System.err); boolean autoFlush = false; boolean enableDebug; Out(boolean enableDebug) { this.enableDebug = enableDebug; } void println(Object... args) { if (args == null || args.getClass() != Object[].class) { args = new Object[] {args}; } out.println(Arrays.stream(args).map(obj -> { Class<?> clazz = obj == null ? null : obj.getClass(); return clazz == Double.class ? String.format("%.10f", obj) : clazz == byte[].class ? Arrays.toString((byte[])obj) : clazz == short[].class ? Arrays.toString((short[])obj) : clazz == int[].class ? Arrays.toString((int[])obj) : clazz == long[].class ? Arrays.toString((long[])obj) : clazz == char[].class ? Arrays.toString((char[])obj) : clazz == float[].class ? Arrays.toString((float[])obj) : clazz == double[].class ? Arrays.toString((double[])obj) : clazz == boolean[].class ? Arrays.toString((boolean[])obj) : obj instanceof Object[] ? Arrays.deepToString((Object[])obj) : String.valueOf(obj); }).collect(Collectors.joining(" "))); if (autoFlush) { out.flush(); } } void debug(Object... args) { if (!enableDebug) { return; } if (args == null || args.getClass() != Object[].class) { args = new Object[] {args}; } err.println(Arrays.stream(args).map(obj -> { Class<?> clazz = obj == null ? null : obj.getClass(); return clazz == Double.class ? String.format("%.10f", obj) : clazz == byte[].class ? Arrays.toString((byte[])obj) : clazz == short[].class ? Arrays.toString((short[])obj) : clazz == int[].class ? Arrays.toString((int[])obj) : clazz == long[].class ? Arrays.toString((long[])obj) : clazz == char[].class ? Arrays.toString((char[])obj) : clazz == float[].class ? Arrays.toString((float[])obj) : clazz == double[].class ? Arrays.toString((double[])obj) : clazz == boolean[].class ? Arrays.toString((boolean[])obj) : obj instanceof Object[] ? Arrays.deepToString((Object[])obj) : String.valueOf(obj); }).collect(Collectors.joining(" "))); err.flush(); } void println(char a) { out.println(a); if (autoFlush) { out.flush(); } } void println(int a) { out.println(a); if (autoFlush) { out.flush(); } } void println(long a) { out.println(a); if (autoFlush) { out.flush(); } } void println(double a) { out.println(String.format("%.10f", a)); if (autoFlush) { out.flush(); } } void println(String s) { out.println(s); if (autoFlush) { out.flush(); } } void println(char[] s) { out.println(String.valueOf(s)); if (autoFlush) { out.flush(); } } void println(int[] a) { StringJoiner joiner = new StringJoiner(" "); for (int i : a) { joiner.add(Integer.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void println(long[] a) { StringJoiner joiner = new StringJoiner(" "); for (long i : a) { joiner.add(Long.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void flush() { err.flush(); out.flush(); } } // template - Yu_212 // 18:32:21 09-09-2023 // D - Minimum Width // https://atcoder.jp/contests/abc319/tasks/abc319_d // 2000 ms import java.io.*; import java.util.*; import java.util.function.IntUnaryOperator; import java.util.function.LongUnaryOperator; import java.util.stream.Collectors; public class Main { static In in = new FastIn(); static Out out = new Out(false); static final long inf = 0x1fffffffffffffffL; static final int iinf = 0x3fffffff; static final double eps = 1e-9; static long mod = 998244353; void solve() { int n = inp() , k = inp(); long[] arr = in.nextLongArray(n); long l = -1 , r = 1_000_000_000_000_000L; while(r - l > 1){ long m = (l + r) / 2; if(check(arr , m) <= k) r = m; else l = m; } // out.println(check(arr , 26L)); out.println(r); } int check(long[] arr , long m){ int cnt = 0; long sum = 0; long max = Arrays.stream(arr).max().getAsLong(); if(max > m) return iinf; for(int i = 0 ; i < arr.length ; i++){ sum = sum + arr[i] + 1; if(sum - 1 == m){ sum = 0; cnt++; continue; } if(sum > m){ cnt++; sum = arr[i] + 1; } } if(sum > 0) cnt++; return cnt; } public static void main(String... args) { int ntc = 1; // ntc = in.nextInt(); for(int i = 1 ; i <= ntc ; i++) new Main().solve(); out.flush(); } int inp(){ return in.nextInt(); } } class FastIn extends In { private final BufferedInputStream reader = new BufferedInputStream(System.in); private final byte[] buffer = new byte[0x10000]; private int i = 0; private int length = 0; public int read() { if (i == length) { i = 0; try { length = reader.read(buffer); } catch (IOException ignored) { } if (length == -1) { return 0; } } if (length <= i) { throw new RuntimeException(); } return buffer[i++]; } String next() { StringBuilder builder = new StringBuilder(); int b = read(); while (b < '!' || '~' < b) { b = read(); } while ('!' <= b && b <= '~') { builder.appendCodePoint(b); b = read(); } return builder.toString(); } String nextLine() { StringBuilder builder = new StringBuilder(); int b = read(); while (b != 0 && b != '\r' && b != '\n') { builder.appendCodePoint(b); b = read(); } if (b == '\r') { read(); } return builder.toString(); } int nextInt() { long val = nextLong(); if ((int)val != val) { throw new NumberFormatException(); } return (int)val; } long nextLong() { int b = read(); while (b < '!' || '~' < b) { b = read(); } boolean neg = false; if (b == '-') { neg = true; b = read(); } long n = 0; int c = 0; while ('0' <= b && b <= '9') { n = n * 10 + b - '0'; b = read(); c++; } if (c == 0 || c >= 2 && n == 0) { throw new NumberFormatException(); } return neg ? -n : n; } } class In { private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000); private StringTokenizer tokenizer; String next() { try { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (IOException ignored) { } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char[] nextCharArray() { return next().toCharArray(); } String[] nextStringArray(int n) { String[] s = new String[n]; for (int i = 0; i < n; i++) { s[i] = next(); } return s; } char[][] nextCharGrid(int n, int m) { char[][] a = new char[n][m]; for (int i = 0; i < n; i++) { a[i] = next().toCharArray(); } return a; } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } int[] nextIntArray(int n, IntUnaryOperator op) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsInt(nextInt()); } return a; } int[][] nextIntMatrix(int h, int w) { int[][] a = new int[h][w]; for (int i = 0; i < h; i++) { a[i] = nextIntArray(w); } return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } long[] nextLongArray(int n, LongUnaryOperator op) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsLong(nextLong()); } return a; } long[][] nextLongMatrix(int h, int w) { long[][] a = new long[h][w]; for (int i = 0; i < h; i++) { a[i] = nextLongArray(w); } return a; } List<List<Integer>> nextEdges(int n, int m, boolean directed) { List<List<Integer>> res = new ArrayList<>(); for (int i = 0; i < n; i++) { res.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; res.get(u).add(v); if (!directed) { res.get(v).add(u); } } return res; } } class Out { private final PrintWriter out = new PrintWriter(System.out); private final PrintWriter err = new PrintWriter(System.err); boolean autoFlush = false; boolean enableDebug; Out(boolean enableDebug) { this.enableDebug = enableDebug; } void println(Object... args) { if (args == null || args.getClass() != Object[].class) { args = new Object[] {args}; } out.println(Arrays.stream(args).map(obj -> { Class<?> clazz = obj == null ? null : obj.getClass(); return clazz == Double.class ? String.format("%.10f", obj) : clazz == byte[].class ? Arrays.toString((byte[])obj) : clazz == short[].class ? Arrays.toString((short[])obj) : clazz == int[].class ? Arrays.toString((int[])obj) : clazz == long[].class ? Arrays.toString((long[])obj) : clazz == char[].class ? Arrays.toString((char[])obj) : clazz == float[].class ? Arrays.toString((float[])obj) : clazz == double[].class ? Arrays.toString((double[])obj) : clazz == boolean[].class ? Arrays.toString((boolean[])obj) : obj instanceof Object[] ? Arrays.deepToString((Object[])obj) : String.valueOf(obj); }).collect(Collectors.joining(" "))); if (autoFlush) { out.flush(); } } void debug(Object... args) { if (!enableDebug) { return; } if (args == null || args.getClass() != Object[].class) { args = new Object[] {args}; } err.println(Arrays.stream(args).map(obj -> { Class<?> clazz = obj == null ? null : obj.getClass(); return clazz == Double.class ? String.format("%.10f", obj) : clazz == byte[].class ? Arrays.toString((byte[])obj) : clazz == short[].class ? Arrays.toString((short[])obj) : clazz == int[].class ? Arrays.toString((int[])obj) : clazz == long[].class ? Arrays.toString((long[])obj) : clazz == char[].class ? Arrays.toString((char[])obj) : clazz == float[].class ? Arrays.toString((float[])obj) : clazz == double[].class ? Arrays.toString((double[])obj) : clazz == boolean[].class ? Arrays.toString((boolean[])obj) : obj instanceof Object[] ? Arrays.deepToString((Object[])obj) : String.valueOf(obj); }).collect(Collectors.joining(" "))); err.flush(); } void println(char a) { out.println(a); if (autoFlush) { out.flush(); } } void println(int a) { out.println(a); if (autoFlush) { out.flush(); } } void println(long a) { out.println(a); if (autoFlush) { out.flush(); } } void println(double a) { out.println(String.format("%.10f", a)); if (autoFlush) { out.flush(); } } void println(String s) { out.println(s); if (autoFlush) { out.flush(); } } void println(char[] s) { out.println(String.valueOf(s)); if (autoFlush) { out.flush(); } } void println(int[] a) { StringJoiner joiner = new StringJoiner(" "); for (int i : a) { joiner.add(Integer.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void println(long[] a) { StringJoiner joiner = new StringJoiner(" "); for (long i : a) { joiner.add(Long.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void flush() { err.flush(); out.flush(); } } // template - Yu_212
ConDefects/ConDefects/Code/abc319_d/Java/45416107
condefects-java_data_11
import java.util.Arrays; import java.util.Scanner; class D { public static void main(String... args) { final Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); final int[] L = new int[N]; Arrays.setAll(L, $ -> sc.nextInt()); long sum = 0; for (int l : L) sum += l; long lo = sum / M; long hi = sum + N - 1; while (hi - lo > 1) { final long W = (hi + lo + 1) / 2; boolean failed = L[0] > W; long w = L[0]; for (int i = 1, j = 0; i < N; i++) { if (w + L[i] + 1 <= W) { w += L[i] + 1; } else { if (++j >= M || L[i] > W) { failed = true; break; } w = L[i]; } } if (failed) lo = W; else hi = W; } System.out.println(hi); } } public class Main { public static void main(String... args) { D.main(); } } import java.util.Arrays; import java.util.Scanner; class D { public static void main(String... args) { final Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); final int[] L = new int[N]; Arrays.setAll(L, $ -> sc.nextInt()); long sum = 0; for (int l : L) sum += l; long lo = sum / M - 1; long hi = sum + N - 1; while (hi - lo > 1) { final long W = (hi + lo + 1) / 2; boolean failed = L[0] > W; long w = L[0]; for (int i = 1, j = 0; i < N; i++) { if (w + L[i] + 1 <= W) { w += L[i] + 1; } else { if (++j >= M || L[i] > W) { failed = true; break; } w = L[i]; } } if (failed) lo = W; else hi = W; } System.out.println(hi); } } public class Main { public static void main(String... args) { D.main(); } }
ConDefects/ConDefects/Code/abc319_d/Java/45408839
condefects-java_data_12
import java.util.Scanner; public class Main { static int N, M; static long[] L; static boolean isPossible(long W) { int lines = 1; long line_width = 0; for (int i = 0; i < N; i++) { if (L[i] > W) { return false; } if (line_width + L[i] <= W) { line_width += L[i] + 1; } else { lines++; line_width = L[i] + 1; } } return lines <= M; } static long binarySearch(long left, long right) { long result = -1; while (left <= right) { long mid = (left + right) / 2; if (isPossible(mid)) { result = mid; right = mid - 1; } else { left = mid + 1; } } return result; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); N = scanner.nextInt(); M = scanner.nextInt(); L = new long[N]; for (int i = 0; i < N; i++) { L[i] = scanner.nextLong(); } } } import java.util.Scanner; public class Main { static int N, M; static long[] L; static boolean isPossible(long W) { int lines = 1; long line_width = 0; for (int i = 0; i < N; i++) { if (L[i] > W) { return false; } if (line_width + L[i] <= W) { line_width += L[i] + 1; } else { lines++; line_width = L[i] + 1; } } return lines <= M; } static long binarySearch(long left, long right) { long result = -1; while (left <= right) { long mid = (left + right) / 2; if (isPossible(mid)) { result = mid; right = mid - 1; } else { left = mid + 1; } } return result; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); N = scanner.nextInt(); M = scanner.nextInt(); L = new long[N]; for (int i = 0; i < N; i++) { L[i] = scanner.nextLong(); } long min_width = binarySearch(1, (long) 1e18); System.out.println(min_width); } }
ConDefects/ConDefects/Code/abc319_d/Java/45403392
condefects-java_data_13
//make sure to make new file! import java.io.*; import java.util.*; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); long[] array = new long[n]; st = new StringTokenizer(f.readLine()); long max = 0L; for(int k = 0; k < n; k++){ array[k] = Long.parseLong(st.nextToken()); max = Math.max(max,array[k]); } long l = max; long r = 200000001000000L; long ans = -1; while(l <= r){ long mid = l + (r-l)/2L; //see if width = mid works int lines = 1; long curline = 0; for(int k = 0; k < n; k++){ if(curline + array[k] > mid){ lines++; curline = array[k]; } else { curline += array[k]+1; } } if(lines <= m){ ans = mid; r = mid-1; } else { l = mid+1; } } out.println(ans); out.close(); } } //make sure to make new file! import java.io.*; import java.util.*; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); long[] array = new long[n]; st = new StringTokenizer(f.readLine()); long max = 0L; for(int k = 0; k < n; k++){ array[k] = Long.parseLong(st.nextToken()); max = Math.max(max,array[k]); } long l = max; long r = 200000001000000L; long ans = -1; while(l <= r){ long mid = l + (r-l)/2L; //see if width = mid works int lines = 1; long curline = 0; for(int k = 0; k < n; k++){ if(curline + array[k] > mid){ lines++; curline = array[k]+1; } else { curline += array[k]+1; } } if(lines <= m){ ans = mid; r = mid-1; } else { l = mid+1; } } out.println(ans); out.close(); } }
ConDefects/ConDefects/Code/abc319_d/Java/45430736
condefects-java_data_14
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static FastReader sc; public static void main(String[] args) throws IOException { sc = new FastReader(); int n = sc.nextInt(); int m = sc.nextInt(); long[] L = new long[n]; long total = 0; for (int i=0;i<n;i++) { L[i] = sc.nextLong(); total += L[i]; } long ans = 0; long ng = 0; // ありうる値-1 long ok = total + n; // ありうる値+1 while (Math.abs(ok - ng) > 1) { long mid = (ok + ng) / 2; if (check(L, mid, m)) { ok = mid; } else { ng = mid; } } System.out.println(ok); } static boolean check(long[] a, long mid, long m) { int cnt = 0; long tmp = 0; int i = 0; while (true) { if (a[i] > mid) { return false; } if (i > 0 && tmp + a[i] >= mid) { if (tmp + a[i] == mid) { i++; if (i > a.length -1) { cnt++; break; } } tmp = a[i]; cnt++; } else { tmp += a[i] + 1; } i++; if (i > a.length -1) { cnt++; break; } } return cnt <= m; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] readLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static FastReader sc; public static void main(String[] args) throws IOException { sc = new FastReader(); int n = sc.nextInt(); int m = sc.nextInt(); long[] L = new long[n]; long total = 0; for (int i=0;i<n;i++) { L[i] = sc.nextLong(); total += L[i]; } long ans = 0; long ng = 0; // ありうる値-1 long ok = total + n; // ありうる値+1 while (Math.abs(ok - ng) > 1) { long mid = (ok + ng) / 2; if (check(L, mid, m)) { ok = mid; } else { ng = mid; } } System.out.println(ok); } static boolean check(long[] a, long mid, long m) { int cnt = 0; long tmp = 0; int i = 0; while (true) { if (a[i] > mid) { return false; } if (i > 0 && tmp + a[i] >= mid) { if (tmp + a[i] == mid) { i++; if (i > a.length -1) { cnt++; break; } } tmp = a[i] + 1; cnt++; } else { tmp += a[i] + 1; } i++; if (i > a.length -1) { cnt++; break; } } return cnt <= m; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readIntArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] readLongArray(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } }
ConDefects/ConDefects/Code/abc319_d/Java/45470117
condefects-java_data_15
import java.util.*; public class Main { private static boolean possible(int[] arr, int lines, long maxWidth) { long curWidth = 1; for(int i = 0; i < arr.length && lines >= 0; i++) { if(curWidth + (arr[i] - 1) > maxWidth) { lines--; curWidth = 1; } curWidth += (arr[i] - 1); curWidth += 2; } return lines > 0; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] len = new int[n]; long ans = -1, l = 1, h = (long)(1e14) * 2; for(int i = 0; i < n; i++) { len[i] = sc.nextInt(); l = Math.max(l, len[i]); } while(l <= h) { long mid = (l + h) >> 1; if(possible(len, m, mid)) { ans = mid; h = mid - 1; } else { l = mid + 1; } } System.out.println(ans); } } import java.util.*; public class Main { private static boolean possible(int[] arr, int lines, long maxWidth) { long curWidth = 1; for(int i = 0; i < arr.length && lines >= 0; i++) { if(curWidth + (arr[i] - 1) > maxWidth) { lines--; curWidth = 1; } curWidth += (arr[i] - 1); curWidth += 2; } return lines > 0; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] len = new int[n]; long ans = -1, l = 1, h = (long)(1e15); for(int i = 0; i < n; i++) { len[i] = sc.nextInt(); l = Math.max(l, len[i]); } while(l <= h) { long mid = (l + h) >> 1; if(possible(len, m, mid)) { ans = mid; h = mid - 1; } else { l = mid + 1; } } System.out.println(ans); } }
ConDefects/ConDefects/Code/abc319_d/Java/45424477
condefects-java_data_16
import java.io.PrintWriter; import java.util.*; public class Main { private static final ContestScanner in = new ContestScanner(System.in); private static final PrintWriter pw = new PrintWriter(System.out); private static int n, m; private static int[] l; public static void main(String[] args) { n = in.nextInt(); m = in.nextInt(); l = new int[n]; for (int i = 0; i < n; i++) l[i] = in.nextInt(); solve(); } private static void solve() { long l = 1, r = (long) 1e9 * n; while (l <= r) { long mid = (l + r) / 2; if (check(mid)) r = mid - 1; else l = mid + 1; } write(l); } private static boolean check(long w) { if (l[0] > w) return false; long rows = 1, curW = l[0]; int p = 1; for (; p < n; p++) { if (l[p] > w) return false; if (curW + 1 + l[p] > w) { curW = l[p]; rows++; } else { curW += 1 + l[p]; } } return rows <= m; } private static void write(long num) { pw.println(num); pw.flush(); } private static void write(String s) { pw.println(s); pw.flush(); } private static void write(int[] arr, int begin, int end) { StringBuilder line = new StringBuilder(); for (int i = begin; i <= end; i++) { line.append(arr[i]).append(" "); } write(line.toString()); } } /** * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java */ class ContestScanner { private final java.io.InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public ContestScanner(java.io.InputStream in){ this.in = in; } public ContestScanner(java.io.File file) throws java.io.FileNotFoundException { this(new java.io.BufferedInputStream(new java.io.FileInputStream(file))); } public ContestScanner(){ this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (java.io.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 java.util.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 java.util.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') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString((char)b)) ); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString((char)b)) ); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit) ); } n = n * 10 + digit; }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()); } } import java.io.PrintWriter; import java.util.*; public class Main { private static final ContestScanner in = new ContestScanner(System.in); private static final PrintWriter pw = new PrintWriter(System.out); private static int n, m; private static int[] l; public static void main(String[] args) { n = in.nextInt(); m = in.nextInt(); l = new int[n]; for (int i = 0; i < n; i++) l[i] = in.nextInt(); solve(); } private static void solve() { long l = 1, r = (long) 1e9 * n + n - 1; while (l <= r) { long mid = (l + r) / 2; if (check(mid)) r = mid - 1; else l = mid + 1; } write(l); } private static boolean check(long w) { if (l[0] > w) return false; long rows = 1, curW = l[0]; int p = 1; for (; p < n; p++) { if (l[p] > w) return false; if (curW + 1 + l[p] > w) { curW = l[p]; rows++; } else { curW += 1 + l[p]; } } return rows <= m; } private static void write(long num) { pw.println(num); pw.flush(); } private static void write(String s) { pw.println(s); pw.flush(); } private static void write(int[] arr, int begin, int end) { StringBuilder line = new StringBuilder(); for (int i = begin; i <= end; i++) { line.append(arr[i]).append(" "); } write(line.toString()); } } /** * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java */ class ContestScanner { private final java.io.InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public ContestScanner(java.io.InputStream in){ this.in = in; } public ContestScanner(java.io.File file) throws java.io.FileNotFoundException { this(new java.io.BufferedInputStream(new java.io.FileInputStream(file))); } public ContestScanner(){ this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (java.io.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 java.util.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 java.util.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') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString((char)b)) ); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString((char)b)) ); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit) ); } n = n * 10 + digit; }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()); } }
ConDefects/ConDefects/Code/abc319_d/Java/45470029
condefects-java_data_17
import com.sun.source.tree.Tree; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; /** * # * * @author pttrung */ public class Main { public static long MOD = 998244353; static long[] dp; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); int n = in.nextInt(); int m = in.nextInt(); long[]data = new long[n]; long st = 0; long ed = 0; for(int i = 0; i < n; i++){ data[i] = in.nextInt(); st = Long.max(st, data[i]); ed += data[i]; } long re = ed; while(st <= ed){ long mid = (st + ed)/2; int total = 1; long cur = 0; for(int i = 0; i < n; i++){ if(cur + data[i] > mid){ cur = data[i] + 1; total++; continue; } cur += data[i] + 1; } if(total <= m){ re = mid; ed = mid - 1; continue; } st = mid + 1; } out.println(re); out.close(); } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point implements Comparable<Point> { int x, y; public Point(int start, int end) { this.x = start; this.y = end; } @Override public int compareTo(Point o) { if (x != o.x) { return Integer.compare(x, o.x); } return Integer.compare(y, o.y); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Point point = (Point) o; return x == point.x && y == point.y; } @Override public int hashCode() { return Objects.hash(x, y); } public String toString() { return x + " " + y; } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, int b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return (val * val) % MOD; } else { return (val * ((val * a) % MOD)) % MOD; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } } import com.sun.source.tree.Tree; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; /** * # * * @author pttrung */ public class Main { public static long MOD = 998244353; static long[] dp; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); int n = in.nextInt(); int m = in.nextInt(); long[]data = new long[n]; long st = 0; long ed = n - 1; for(int i = 0; i < n; i++){ data[i] = in.nextInt(); st = Long.max(st, data[i]); ed += data[i]; } long re = ed; while(st <= ed){ long mid = (st + ed)/2; int total = 1; long cur = 0; for(int i = 0; i < n; i++){ if(cur + data[i] > mid){ cur = data[i] + 1; total++; continue; } cur += data[i] + 1; } if(total <= m){ re = mid; ed = mid - 1; continue; } st = mid + 1; } out.println(re); out.close(); } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point implements Comparable<Point> { int x, y; public Point(int start, int end) { this.x = start; this.y = end; } @Override public int compareTo(Point o) { if (x != o.x) { return Integer.compare(x, o.x); } return Integer.compare(y, o.y); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Point point = (Point) o; return x == point.x && y == point.y; } @Override public int hashCode() { return Objects.hash(x, y); } public String toString() { return x + " " + y; } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, int b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return (val * val) % MOD; } else { return (val * ((val * a) % MOD)) % MOD; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
ConDefects/ConDefects/Code/abc319_d/Java/45446792
condefects-java_data_18
import java.util.Scanner; public class Main { public static void main(final String[] args) { try (final Scanner sc = new Scanner(System.in)) { final int N = Integer.parseInt(sc.next()); final int M = Integer.parseInt(sc.next()); final int[] L = new int[N]; long strLength = 0; long maxLetter = Integer.MIN_VALUE; for (int i = 0; i < N; i++) { L[i] = Integer.parseInt(sc.next()) + 1; strLength += L[i]; if (maxLetter < L[i] - 1) { maxLetter += L[i] - 1; } } // 二分探索 while (maxLetter + 1 < strLength) { final long middle = (maxLetter + strLength) / 2; int rows = 1; // 今の行数 long length = 0; // 先頭から何文字目か for (int i = 0; i < N; ++i) { length += L[i]; // 行の末尾に追加してみる if (length > middle) { // はみ出たら ++rows; // 改行して length = L[i]; // 先頭に追加 } } if (rows > M) { // 縦幅が足りていなければ maxLetter = middle; // 答えは middle より大きい } else { // 縦幅が足りていなければ strLength = middle; // 答えは middle 以下 } } // 答えから 1 を引いて出力 System.out.println(strLength - 1); } } } import java.util.Scanner; public class Main { public static void main(final String[] args) { try (final Scanner sc = new Scanner(System.in)) { final int N = Integer.parseInt(sc.next()); final int M = Integer.parseInt(sc.next()); final int[] L = new int[N]; long strLength = 0; long maxLetter = Integer.MIN_VALUE; for (int i = 0; i < N; i++) { L[i] = Integer.parseInt(sc.next()) + 1; strLength += L[i]; if (maxLetter < L[i] - 1) { maxLetter = L[i] - 1; } } // 二分探索 while (maxLetter + 1 < strLength) { final long middle = (maxLetter + strLength) / 2; int rows = 1; // 今の行数 long length = 0; // 先頭から何文字目か for (int i = 0; i < N; ++i) { length += L[i]; // 行の末尾に追加してみる if (length > middle) { // はみ出たら ++rows; // 改行して length = L[i]; // 先頭に追加 } } if (rows > M) { // 縦幅が足りていなければ maxLetter = middle; // 答えは middle より大きい } else { // 縦幅が足りていなければ strLength = middle; // 答えは middle 以下 } } // 答えから 1 を引いて出力 System.out.println(strLength - 1); } } }
ConDefects/ConDefects/Code/abc319_d/Java/45539729
condefects-java_data_19
import java.io.*; import java.math.*; import java.util.*; public class Main { static class Pair { long x; int y; Pair(long x, int y) { this.x = x; this.y = y; } } static class Compare { void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if (p1.x != p2.x) { return (int) (p1.x - p2.x); } else { return (int) (p1.y - p2.y); } // return Double.compare(a[0], b[0]); } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + " " + arr[i].y + " "); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static boolean function(int a[],long mid,int m) { long till = 0; int fill = 0; int i = 0; while(i < a.length) { if(a[i] > mid) { break; } if(a[i] + till <= mid) { till += a[i] + 1; i++; } else { fill++; till = 0; } } return (i == a.length && fill + 1 <= m); } public static void main(String args[]) throws Exception { Scanner sc = new Scanner(); StringBuilder res = new StringBuilder(); int tc = 1; while (tc-- > 0) { int n = sc.nextInt(); int m = sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); } long l = 1; long r = (long)(1e11); long ans = -1; while(l <= r) { long mid = l + (r - l)/2; if(function(a,mid,m)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } res.append(ans); } System.out.println(res); } } import java.io.*; import java.math.*; import java.util.*; public class Main { static class Pair { long x; int y; Pair(long x, int y) { this.x = x; this.y = y; } } static class Compare { void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if (p1.x != p2.x) { return (int) (p1.x - p2.x); } else { return (int) (p1.y - p2.y); } // return Double.compare(a[0], b[0]); } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + " " + arr[i].y + " "); // } // System.out.println(); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static boolean function(int a[],long mid,int m) { long till = 0; int fill = 0; int i = 0; while(i < a.length) { if(a[i] > mid) { break; } if(a[i] + till <= mid) { till += a[i] + 1; i++; } else { fill++; till = 0; } } return (i == a.length && fill + 1 <= m); } public static void main(String args[]) throws Exception { Scanner sc = new Scanner(); StringBuilder res = new StringBuilder(); int tc = 1; while (tc-- > 0) { int n = sc.nextInt(); int m = sc.nextInt(); int a[] = new int[n]; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); } long l = 1; long r = (long)(1e15); long ans = -1; while(l <= r) { long mid = l + (r - l)/2; if(function(a,mid,m)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } res.append(ans); } System.out.println(res); } }
ConDefects/ConDefects/Code/abc319_d/Java/45492458
condefects-java_data_20
import java.util.*; import java.io.*; public class Main { static final FastReader sc = new FastReader(); static final PrintWriter out = new PrintWriter(System.out, true); private static boolean debug = System.getProperty("ONLINE_JUDGE") == null; static void trace(Object... o) { if (debug) { System.err.println(Arrays.deepToString(o)); } } public static void main(String[] args) { int N = sc.nextInt(), M = sc.nextInt(); long[] L = new long[N]; for (int i = 0; i < N; i++) L[i] = sc.nextInt() + 1; long l = Arrays.stream(L).max().getAsLong(), r = Arrays.stream(L).sum(); while (l < r - 1) { long mid = (l + r) / 2; long curr = 0; int nRows = 1; for (int i = 0; i < N; i++) { curr += L[i]; if (curr > mid) { nRows++; curr = L[i]; } } if (nRows > M) l = mid; else r = mid; } out.println(r - 1); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } import java.util.*; import java.io.*; public class Main { static final FastReader sc = new FastReader(); static final PrintWriter out = new PrintWriter(System.out, true); private static boolean debug = System.getProperty("ONLINE_JUDGE") == null; static void trace(Object... o) { if (debug) { System.err.println(Arrays.deepToString(o)); } } public static void main(String[] args) { int N = sc.nextInt(), M = sc.nextInt(); long[] L = new long[N]; for (int i = 0; i < N; i++) L[i] = sc.nextInt() + 1; long l = Arrays.stream(L).max().getAsLong() - 1, r = Arrays.stream(L).sum(); while (l < r - 1) { long mid = (l + r) / 2; long curr = 0; int nRows = 1; for (int i = 0; i < N; i++) { curr += L[i]; if (curr > mid) { nRows++; curr = L[i]; } } if (nRows > M) l = mid; else r = mid; } out.println(r - 1); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
ConDefects/ConDefects/Code/abc319_d/Java/45667550
condefects-java_data_21
import java.io.PrintWriter; import java.util.Scanner; public class Main { public static String solve(String s, int n) { if (n == 1) return s; if(s.lastIndexOf('A')>s.indexOf('B')) return "A"; else return "B"; } public static void main(String[] args) { var sc = new Scanner(System.in); var out = new PrintWriter(System.out, false); //true for Interactive try { for (int i = sc.nextInt(); i > 0; i--) { int n = sc.nextInt(); String s = sc.next(); solve(s, n); } out.flush(); } catch (Exception e) { out.flush(); throw e; } } } import java.io.PrintWriter; import java.util.Scanner; public class Main { public static String solve(String s, int n) { if (n == 1) return s; if(s.lastIndexOf('A')>s.indexOf('B')) return "A"; else return "B"; } public static void main(String[] args) { var sc = new Scanner(System.in); var out = new PrintWriter(System.out, false); //true for Interactive try { for (int i = sc.nextInt(); i > 0; i--) { int n = sc.nextInt(); String s = sc.next(); out.println(solve(s, n)); } out.flush(); } catch (Exception e) { out.flush(); throw e; } } }
ConDefects/ConDefects/Code/agc062_a/Java/41785329
condefects-java_data_22
import java.util.Scanner; public class Main { public static void main(String[] args) { var sc = new Scanner(System.in); var t = sc.nextInt(); var n = new int[t]; var s = new String[t]; for (var i = 0; i < t; i++) { n[i] = sc.nextInt(); s[i] = sc.next(); } sc.close(); var sb = new StringBuilder(); for (var i = 0; i < t; i++) { var result = calc(n[i], s[i]); sb.append(result); sb.append("\r\n"); } System.out.println(sb.toString()); } private static String calc(int n, String s) { var chars = s.toCharArray(); var count1 = 0; var count2 = 0; for (var i = 0; i < n; i++) { if (chars[i] == 'B') { break; } count1++; } for (var i = n-1; i >= 0; i--) { if (chars[i] == 'A') { break; } count2++; } if (count1 + count2 == n && count2 >= count1) { return "B"; } return "A"; } } import java.util.Scanner; public class Main { public static void main(String[] args) { var sc = new Scanner(System.in); var t = sc.nextInt(); var n = new int[t]; var s = new String[t]; for (var i = 0; i < t; i++) { n[i] = sc.nextInt(); s[i] = sc.next(); } sc.close(); var sb = new StringBuilder(); for (var i = 0; i < t; i++) { var result = calc(n[i], s[i]); sb.append(result); sb.append("\r\n"); } System.out.println(sb.toString()); } private static String calc(int n, String s) { var chars = s.toCharArray(); var count1 = 0; var count2 = 0; for (var i = 0; i < n; i++) { if (chars[i] == 'B') { break; } count1++; } for (var i = n-1; i >= 0; i--) { if (chars[i] == 'A') { break; } count2++; } if (count1 + count2 == n && count2 > 0) { return "B"; } return "A"; } }
ConDefects/ConDefects/Code/agc062_a/Java/41606513
condefects-java_data_23
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); System.out.println(t); for (int i = 0; i < t; i++) { System.out.println(i); int n = sc.nextInt(); String s = sc.next(); String newS = s.replaceAll("A", ""); if (newS.length() == 0) { System.out.println("A"); continue; } newS = s.replace("BA", ""); if (newS.length() != s.length()) { System.out.println("A"); continue; } System.out.println("B"); } } } import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); String s = sc.next(); String newS = s.replaceAll("A", ""); if (newS.length() == 0) { System.out.println("A"); continue; } newS = s.replace("BA", ""); if (newS.length() != s.length()) { System.out.println("A"); continue; } System.out.println("B"); } } }
ConDefects/ConDefects/Code/agc062_a/Java/41607744
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
71
Edit dataset card