結果

問題 No.2355 Unhappy Back Dance
ユーザー tentententen
提出日時 2023-07-05 12:30:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,728 ms / 6,000 ms
コード長 3,103 bytes
コンパイル時間 2,526 ms
コンパイル使用メモリ 81,364 KB
実行使用メモリ 56,772 KB
最終ジャッジ日時 2023-09-26 12:13:45
合計ジャッジ時間 26,890 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,228 KB
testcase_01 AC 45 ms
49,256 KB
testcase_02 AC 45 ms
49,336 KB
testcase_03 AC 45 ms
49,352 KB
testcase_04 AC 44 ms
49,404 KB
testcase_05 AC 45 ms
49,240 KB
testcase_06 AC 90 ms
50,508 KB
testcase_07 AC 89 ms
50,608 KB
testcase_08 AC 82 ms
51,484 KB
testcase_09 AC 111 ms
50,536 KB
testcase_10 AC 409 ms
56,772 KB
testcase_11 AC 298 ms
56,688 KB
testcase_12 AC 82 ms
50,428 KB
testcase_13 AC 80 ms
50,388 KB
testcase_14 AC 340 ms
54,468 KB
testcase_15 AC 44 ms
49,440 KB
testcase_16 AC 1,689 ms
55,832 KB
testcase_17 AC 1,714 ms
54,028 KB
testcase_18 AC 1,682 ms
55,948 KB
testcase_19 AC 1,728 ms
55,888 KB
testcase_20 AC 1,697 ms
55,924 KB
testcase_21 AC 826 ms
55,308 KB
testcase_22 AC 277 ms
55,332 KB
testcase_23 AC 278 ms
55,728 KB
testcase_24 AC 1,644 ms
56,552 KB
testcase_25 AC 936 ms
55,552 KB
testcase_26 AC 929 ms
55,732 KB
testcase_27 AC 830 ms
55,520 KB
testcase_28 AC 105 ms
52,504 KB
testcase_29 AC 152 ms
54,240 KB
testcase_30 AC 1,477 ms
55,908 KB
testcase_31 AC 1,125 ms
55,672 KB
testcase_32 AC 231 ms
55,204 KB
testcase_33 AC 718 ms
55,496 KB
testcase_34 AC 73 ms
51,760 KB
testcase_35 AC 113 ms
54,476 KB
testcase_36 AC 822 ms
55,284 KB
testcase_37 AC 500 ms
55,496 KB
testcase_38 AC 592 ms
55,428 KB
testcase_39 AC 487 ms
55,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            points[i] = new Point(sc.nextLong(), sc.nextLong());
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            HashSet<Vect> vects = new HashSet<>();
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }
                Vect x = points[i].getVect(points[j]);
                if (vects.contains(x)) {
                    ans++;
                    break;
                }
                vects.add(x);
            }
        }
        System.out.println(ans);
    }
    
    static class Point {
        long x;
        long y;

        public Point(long x, long y) {
            this.x = x;
            this.y = y;
        }
        
        public Vect getVect(Point p) {
            return new Vect(x - p.x, y - p.y);
        }
    }
    
    static class Vect {
        long x;
        long y;
        
        public Vect(long x, long y) {
            this.x = x;
            this.y = y;
            init();
        }
        
        private void init() {
            long gcd = getGCD(Math.abs(x), Math.abs(y));
            x /= gcd;
            y /= gcd;
        }
        
        private long getGCD(long x, long y) {
            if (y == 0) {
                return x;
            } else {
                return getGCD(y, x % y);
            }
        }
        
        public int hashCode() {
            return (int)(x + y);
        }
        
        public boolean equals(Object o) {
            Vect v = (Vect)o;
            return x == v.x && y == v.y;
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0