結果
問題 | No.229 線分上を往復する3つの動点の一致 |
ユーザー | ぴろず |
提出日時 | 2015-06-19 23:18:37 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 177 ms / 5,000 ms |
コード長 | 3,594 bytes |
コンパイル時間 | 2,556 ms |
コンパイル使用メモリ | 80,028 KB |
実行使用メモリ | 42,812 KB |
最終ジャッジ日時 | 2024-07-07 04:16:50 |
合計ジャッジ時間 | 11,613 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 169 ms
42,460 KB |
testcase_01 | AC | 168 ms
42,564 KB |
testcase_02 | AC | 168 ms
42,492 KB |
testcase_03 | AC | 166 ms
42,368 KB |
testcase_04 | AC | 167 ms
42,284 KB |
testcase_05 | AC | 164 ms
42,404 KB |
testcase_06 | AC | 167 ms
42,660 KB |
testcase_07 | AC | 167 ms
42,284 KB |
testcase_08 | AC | 169 ms
42,276 KB |
testcase_09 | AC | 167 ms
42,412 KB |
testcase_10 | AC | 171 ms
42,452 KB |
testcase_11 | AC | 171 ms
42,332 KB |
testcase_12 | AC | 167 ms
42,748 KB |
testcase_13 | AC | 169 ms
42,396 KB |
testcase_14 | AC | 170 ms
42,540 KB |
testcase_15 | AC | 166 ms
42,508 KB |
testcase_16 | AC | 168 ms
42,512 KB |
testcase_17 | AC | 167 ms
42,492 KB |
testcase_18 | AC | 165 ms
42,692 KB |
testcase_19 | AC | 166 ms
42,320 KB |
testcase_20 | AC | 165 ms
42,520 KB |
testcase_21 | AC | 165 ms
42,668 KB |
testcase_22 | AC | 167 ms
42,400 KB |
testcase_23 | AC | 167 ms
42,752 KB |
testcase_24 | AC | 166 ms
42,672 KB |
testcase_25 | AC | 177 ms
42,524 KB |
testcase_26 | AC | 168 ms
42,500 KB |
testcase_27 | AC | 169 ms
42,392 KB |
testcase_28 | AC | 166 ms
42,524 KB |
testcase_29 | AC | 164 ms
42,544 KB |
testcase_30 | AC | 151 ms
41,992 KB |
testcase_31 | AC | 171 ms
42,456 KB |
testcase_32 | AC | 164 ms
42,432 KB |
testcase_33 | AC | 165 ms
42,456 KB |
testcase_34 | AC | 165 ms
42,484 KB |
testcase_35 | AC | 167 ms
42,324 KB |
testcase_36 | AC | 164 ms
42,328 KB |
testcase_37 | AC | 166 ms
42,580 KB |
testcase_38 | AC | 163 ms
42,376 KB |
testcase_39 | AC | 172 ms
42,660 KB |
testcase_40 | AC | 169 ms
42,812 KB |
testcase_41 | AC | 166 ms
42,504 KB |
testcase_42 | AC | 164 ms
42,416 KB |
testcase_43 | AC | 167 ms
42,560 KB |
testcase_44 | AC | 166 ms
42,228 KB |
testcase_45 | AC | 162 ms
42,508 KB |
ソースコード
package no229; import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Frac[] t = new Frac[3]; for(int i=0;i<3;i++) { t[i] = new Frac(2, sc.nextInt()); } Frac ans = new Frac(Long.MAX_VALUE); for(int i=0;i<8;i++) { Frac[] s = new Frac[3]; for(int j=0;j<3;j++) { s[j] = ((i >> j & 1 ) == 0) ? t[j] : t[j].multiply(new Frac(-1)); } Frac x = s[0].subtract(s[1]).abs().inverse().lcm(s[1].subtract(s[2]).abs().inverse()).multiply(new Frac(2)); ans = ans.min(x); } System.out.println(ans); } } class Frac { public static Frac ZERO = new Frac(0,1); BigInteger a,b; public Frac(long a) { this.a = BigInteger.valueOf(a); this.b = BigInteger.ONE; } public Frac(long a,long b) { this(BigInteger.valueOf(a),BigInteger.valueOf(b)); } public Frac(BigInteger a,BigInteger b) { int sign = a.signum() * b.signum(); a = a.abs(); b = b.abs(); BigInteger gcd = a.gcd(b); this.a = a.divide(gcd); this.b = b.divide(gcd); if (sign < 0) { this.a = this.a.negate(); } } public Frac add(Frac y) { Frac x = this; return new Frac(x.a.multiply(y.b).add(x.b.multiply(y.a)), x.b.multiply(y.b)); } public Frac subtract(Frac y) { Frac x = this; return new Frac(x.a.multiply(y.b).subtract(x.b.multiply(y.a)), x.b.multiply(y.b)); } public Frac multiply(Frac y) { Frac x = this; return new Frac(x.a.multiply(y.a),x.b.multiply(y.b)); } public Frac divide(Frac y) { Frac x = this; return new Frac(x.a.multiply(y.b),x.b.multiply(y.a)); } public long longValueExact() { if (!b.equals(BigInteger.ONE)) { throw new ArithmeticException(); } return a.longValueExact(); } public boolean equals(Object o) { if (o instanceof Frac) { Frac f = (Frac) o; return this.a.equals(f.a) && this.b.equals(f.b); } return super.equals(o); } public int hashCode() { return a.hashCode() ^ b.hashCode(); } public String toString() { return a + "/" + b; } public Frac lcm(Frac y) { return new Frac(lcm(a.multiply(y.b),b.multiply(y.a)),b.multiply(y.b)); } private static BigInteger lcm(BigInteger a,BigInteger b) { return a.divide(a.gcd(b)).multiply(b); } public Frac abs() { return new Frac(a.abs(), b); } public Frac inverse() { return new Frac(b,a); } public Frac min(Frac y) { if (a.multiply(y.b).compareTo(y.a.multiply(b)) < 0) { return this; }else{ return y; } } } class Mod { public static long n(long x,long mod) { x %= mod; if (x < 0) { x += mod; } return x; } public static long pow(long a,long n,long mod) { long res = 1; while(n > 0) { if ((n & 1) > 0) { res = (res * a) % mod; } a = (a * a) % mod; n/=2; } return res; } public static long inverse(long a,long mod) { long b = mod, u = 1, v = 0; while(b > 0) { long temp; long t = a / b; a -= t * b; temp = a; a = b; b = temp; u -= t * v; temp = u; u = v; v = temp; } return (u % mod + mod) % mod; } /** * @return [a,m] where x = a (mod m) */ public static long[] linearCongruence(long[] A,long[] B,long[] M) { long x = 0; long m = 1; for(int i=0;i<A.length;i++) { long a = A[i] * m; long b = B[i] - A[i] * x; long d = gcd(M[i],a); if (b % d != 0) { return null; } long t = b / d * inverse(a / d, M[i] / d) % (M[i] / d); x = x + m * t; m *= M[i] / d; } long[] ret = {x%m, m}; return ret; } public static long gcd(long a,long b) { while(b!=0) { long r = a%b; a = b; b = r; } return a; } }