結果
問題 | No.2259 Gas Station |
ユーザー | Asahi |
提出日時 | 2023-04-07 22:31:42 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 12,721 bytes |
コンパイル時間 | 2,792 ms |
コンパイル使用メモリ | 93,452 KB |
実行使用メモリ | 41,516 KB |
最終ジャッジ日時 | 2024-10-02 19:58:28 |
合計ジャッジ時間 | 6,517 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
40,728 KB |
testcase_01 | AC | 117 ms
40,576 KB |
testcase_02 | AC | 115 ms
40,764 KB |
testcase_03 | AC | 116 ms
40,796 KB |
testcase_04 | AC | 117 ms
40,844 KB |
testcase_05 | AC | 113 ms
40,972 KB |
testcase_06 | AC | 115 ms
41,420 KB |
testcase_07 | AC | 110 ms
40,844 KB |
testcase_08 | AC | 116 ms
40,608 KB |
testcase_09 | AC | 116 ms
40,572 KB |
testcase_10 | AC | 117 ms
41,124 KB |
testcase_11 | AC | 118 ms
41,180 KB |
testcase_12 | AC | 116 ms
41,020 KB |
testcase_13 | AC | 111 ms
40,708 KB |
testcase_14 | AC | 114 ms
40,712 KB |
testcase_15 | AC | 117 ms
41,312 KB |
testcase_16 | AC | 119 ms
40,976 KB |
testcase_17 | AC | 117 ms
40,808 KB |
testcase_18 | AC | 116 ms
40,904 KB |
testcase_19 | AC | 117 ms
41,472 KB |
testcase_20 | AC | 116 ms
41,516 KB |
testcase_21 | AC | 107 ms
39,984 KB |
testcase_22 | AC | 105 ms
40,444 KB |
testcase_23 | AC | 114 ms
41,292 KB |
ソースコード
import java.util.*; import java.io.*; import java.math.*; class Main{ // 0になったら終了? void solve(){ long l = nl() , r = nl() , C = nl(); long min = Lnf; for(long i = l ; i <= r ; i ++ ) { long over = (i * C / 1000) + 1; min = Math.min(min,(1000 * over - C * i)%1000); if(min == 0) break; } output.print(min); } // for(int i = 0 ; i < n ; i ++ ) { // output.print(" "); // } // for(int i = 0 ; i < H ; i ++ ) { // for(int j = 0 ; j < W ; j ++ ) { // output.print(" "); // } // output.println(); // } /* 以下、ライブラリ等 */ private static PrintWriter output; private static FastScanner fs ; private static Scanner sc; private static final int Inf = 1000000000; private static final long Lnf = 1000000000000000000L; private static final String yes = "Yes"; private static final String no = "No"; //private static final long MOD = 1000000007; //private static final long MOD = 998244353 ; private static int ni() { return fs.nextInt(); } private static long nl() { return fs.nextLong(); } private static double nd() { return fs.nextDouble(); } private static String ns() { return fs.next(); } private static char nc() { return fs.next().charAt(0); } private static BigInteger bi() { return sc.nextBigInteger(); } private static BigDecimal bd() { return sc.nextBigDecimal(); } private static String cut(String S , int begin, int end) { return S.substring(begin,end); } private static char cut(String S , int idx) { return S.charAt(idx); } private static String tos(int val) { return Integer.toString(val); } private static String tos(long val) { return Long.toString(val); } private static int toi(String S) { return Integer.parseInt(S); } private static long tol(String S) { return Long.parseLong(S); } private static int min(int a , int b) { return (int)Math.min(a,b); } private static long min(long a , long b) { return (long)Math.min(a,b); } private static int max(int a , int b) { return (int)Math.max(a,b); } private static long max(long a , long b) { return (long)Math.max(a,b); } private static int abs(int a , int b) { return (int)Math.abs(a-b); } private static long abs(long a , long b) { return (long)Math.abs(a-b); } private static String t_n(int n , int m) { return Integer.toString(n,m); } private static int n_t(String n , int m) { return Integer.parseInt(n,m); } // i⌒i // | |(゚)(゚) // | |彡 と // | |_ノ ー、 // (ミ)、 !フ / // ¢\二二二__ノ // | / // / ソ⌒ 、ヽ // ( < ヽ ) // ⊂_) (_つ private static int [] IntArray(int size) { final int [] array = new int [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = ni(); } return array; } private static long [] LongArray(int size) { long [] array = new long [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = nl(); } return array; } private static double [] DoubleArray(int size) { double [] array = new double [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = nd(); } return array; } private static String [] StringArray(int size) { String [] array = new String [size]; for(int i = 0 ; i < size ; i ++ ) { array[i] = ns(); } return array; } private static char [] CharArray(int size) { char [] array = ns().toCharArray(); return array; } private static int [][] IntArray(int sizeI , int sizeJ) { int [][] array = new int [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = ni(); } return array; } private static long [][] LongArray(int sizeI , int sizeJ) { long [][] array = new long [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = nl(); } return array; } private static double [][] DoubleArray(int sizeI , int sizeJ) { double [][] array = new double [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = nd(); } return array; } private static String [][] StringArray(int sizeI , int sizeJ) { String [][] array = new String [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) for(int j = 0 ; j < sizeJ ; j ++ ) { array[i][j] = ns(); } return array; } private static char [][] CharArray(int sizeI , int sizeJ) { char [][] array = new char [sizeI][sizeJ]; for(int i = 0 ; i < sizeI ; i ++ ) { array[i] = ns().toCharArray(); } return array; } public static void main(String[] args){ output = new PrintWriter(System.out); fs = new FastScanner(); sc = new Scanner(System.in); new Main().solve(); output.flush(); } ////////////////// // My Library // ////////////////// private static int upper_bound(Integer [] array , int key) { return ~Arrays.binarySearch(array, key, (x,y)->x.compareTo(y)>0?1:-1); } private static int lower_bound(Integer [] array , int key) { return ~Arrays.binarySearch(array, key, (x,y)->x.compareTo(y)>=0?1:-1); } } /* 順列生成 */ class Permutation { ArrayList<int []> perm_list ; private int [] perm ; private int [] tmp ; private int [] used ; private int size = 0; private int len = 1; private int cur = 0; public Permutation(int [] base) { this.perm_list = new ArrayList<int []>(); this.perm = new int[base.length]; this.tmp = new int[base.length]; this.used = new int[base.length]; len = 1; size = base.length; System.arraycopy(base, 0, perm, 0, size); for(int i = base.length ; i > 0 ; i -- ) len *= i; for(int i = 0 ; i < len ; i ++ ) perm_list.add(new int[base.length]); } public void next_permutation(int idx){ if(idx == size) { for(int i = 0 ; i < size ; i ++ ) { perm_list.get(cur)[i] = tmp[i]; } cur++; return; } for(int i=0;i<size;i++) { if(used[i] == 1) continue; used[i] = 1; tmp[idx] = perm[i]; next_permutation(idx+1); used[i] = 0; } } } /* 素集合データ構造 */ class DSU { int [] parent; private int[] rank; int [] size; int [] vertex ; int [] edge ; public DSU(int n) { this.parent = new int[n]; this.rank = new int[n]; this.size = new int[n]; this.vertex = new int[n]; this.edge = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } // 連結成分の個数 public int groups() { int count = 0; for(int i=0;i<parent.length;i++) { if(i == find(i)) count++; } return count; } // 各連結成分の頂点数 public void vertexes(int n) { for(int i = 0 ; i < n ; i ++ ){ vertex[find(i)]++; } } // 各連結成分の辺数 public void edges(int m , int [] from) { for(int i = 0 ; i < m ; i ++ ) { edge[find(from[i])]++; } } public int size(int x){ return size[find(x)]; } public int find(int x) { if (x == parent[x]) { return x; } else { parent[x] = find(parent[x]); return parent[x]; } } public boolean same(int x, int y) { return find(x) == find(y); } /* * yRoot -> parent */ public void unite(int x, int y) { int xRoot = find(x); int yRoot = find(y); if (xRoot == yRoot) { return; } if (rank[xRoot] > rank[yRoot]) { parent[yRoot] = xRoot; } else if (rank[xRoot] < rank[yRoot]) { parent[xRoot] = yRoot; } else { parent[xRoot] = yRoot; rank[xRoot]++; size[yRoot] += size[xRoot]; } } } /* 強連結成分分解 */ class SCC { private boolean [] check ; private List<ArrayList<Integer>> edge ; private List<ArrayList<Integer>> revEdge ; private int count ; private int [] vr ; int [] group ; /* * group[i] = 0 -> 強連結成分であるが親でない。 * group[i] = 1 -> 強連結成分でない * group[i] > 1 -> 強連結成分内の頂点数を表し、iが親である。 */ private int groupNum ; /* * 連結成分数 (頂点数1も含む) */ public SCC(int n) { this.check = new boolean[n]; this.edge = new ArrayList<>(); this.revEdge = new ArrayList<>(); this.count = 0 ; this.vr = new int[n]; this.group = new int[n]; this.groupNum = 0 ; for(int i = 0 ; i < n ; i ++ ) { edge.add(new ArrayList<>()); revEdge.add(new ArrayList<>()); } } public void addEdge(int a , int b) { edge.get(a).add(b); revEdge.get(b).add(a); } public int getGroups(){ return this.groupNum; } public void start() { int n = group.length; for(int i = 0 ; i < n ; i ++ ) { if(!check[i]) { First(i); } } Arrays.fill(check,false); for(int i = n - 1 ; i >= 0 ; i -- ) { if(!check[vr[i]]) { Second(vr[i], groupNum++); } } } public void First(int now) { check[now] = true; for(int i : edge.get(now)) { if(!check[i]) { First(i); } } vr[count++] = now; } public void Second(int now,int groupNum) { check[now] = true; group[groupNum]++; for(int i : revEdge.get(now)) { if(!check[i]) { Second(i, groupNum); } } } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }