結果
問題 | No.245 貫け! |
ユーザー |
![]() |
提出日時 | 2015-07-17 22:54:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 2,261 ms / 5,000 ms |
コード長 | 1,978 bytes |
コンパイル時間 | 2,665 ms |
コンパイル使用メモリ | 89,148 KB |
実行使用メモリ | 52,968 KB |
最終ジャッジ日時 | 2024-07-08 09:20:24 |
合計ジャッジ時間 | 28,519 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
package no245;import java.util.ArrayList;import java.util.Collections;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();Vector2[][] seg = new Vector2[n][2];for(int i=0;i<n;i++) {seg[i][0] = new Vector2(sc.nextLong(), sc.nextLong());seg[i][1] = new Vector2(sc.nextLong(), sc.nextLong());}int ans = 0;for(int i=0;i<=200;i++) {for(int j=-200;j<=200;j++) {if (i == 0 && j == 0) {continue;}Vector2 d = new Vector2(i, j);ArrayList<Event> al = new ArrayList<>();for(int k=0;k<n;k++) {long x1 = seg[k][0].dot(d);long x2 = seg[k][1].dot(d);al.add(new Event(Math.min(x1, x2), 1));al.add(new Event(Math.max(x1, x2), -1));}Collections.sort(al);int sum = 0;for(Event e:al) {sum += e.a;ans = Math.max(ans, sum);}}}System.out.println(ans);}}class Event implements Comparable<Event>{long x,a;public Event(long x,long a) {this.x = x;this.a = a;}public int compareTo(Event o) {if (x != o.x) {return Long.compare(x, o.x);}return - Long.compare(a, o.a);}public String toString() {return "[" + x + "," + a + "]";}}class Vector2 {long x = 0;long y = 0;public Vector2(long x,long y) {this.x = x;this.y = y;}public long dot(Vector2 v) {return this.x*v.x+this.y*v.y;}public long cross(Vector2 v) {return this.x*v.y-this.y*v.x;}public Vector2 add(Vector2 v) {return new Vector2(this.x+v.x,this.y+v.y);}public Vector2 subtract(Vector2 v) {return new Vector2(this.x-v.x,this.y-v.y);}public Vector2 multiply(long k) {return new Vector2(k*this.x,k*this.y);}public String toString() {return this.x + " " + this.y;}public boolean equals(Object o) {if (o instanceof Vector2) {Vector2 v = (Vector2) o;return x == v.x && y == v.y;}return super.equals(o);}}