結果

問題 No.245 貫け!
ユーザー eitahoeitaho
提出日時 2015-07-17 23:03:51
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,930 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 120,028 KB
実行使用メモリ 30,588 KB
最終ジャッジ日時 2024-07-08 09:26:42
合計ジャッジ時間 4,520 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
26,236 KB
testcase_01 AC 29 ms
28,528 KB
testcase_02 AC 29 ms
26,156 KB
testcase_03 AC 30 ms
26,436 KB
testcase_04 AC 29 ms
26,220 KB
testcase_05 AC 30 ms
27,960 KB
testcase_06 AC 29 ms
26,180 KB
testcase_07 AC 30 ms
26,052 KB
testcase_08 AC 33 ms
27,964 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 295 ms
28,416 KB
testcase_16 WA -
testcase_17 AC 292 ms
28,396 KB
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

class Program
{
    public void Solve()
    {
        int N = Reader.Int();
        var A = new Point[N];
        var B = new Point[N];
        var candPos = new HashSet<Point>();
        int ans = 0;

        for (int i = 0; i < N; i++)
        {
            var p = Reader.IntArray(4);
            A[i] = new Point(p[0], p[1]);
            B[i] = new Point(p[2], p[3]);
            candPos.Add(A[i]);
            candPos.Add(B[i]);
        }
        for (int pos = -100; pos <= 100; pos++)
        {
            var v1 = new Point(pos, -100);
            var v2 = new Point(pos, 100);
            var h1 = new Point(-100, pos);
            var h2 = new Point(100, pos);
            ans = Math.Max(ans, Enu.Range(0, N).Count(i => SegmentIntersect(v1, v2, A[i], B[i])));
            ans = Math.Max(ans, Enu.Range(0, N).Count(i => SegmentIntersect(h1, h2, A[i], B[i])));
        }
        foreach (var S in candPos)
            foreach (var T in candPos)
            {
                int count = 0;
                for (int i = 0; i < N; i++)
                    if (SegmentIntersect(S, T, A[i], B[i]))
                        count++;
                ans = Math.Max(ans, count);
            }

        Console.WriteLine(ans);
    }


    bool SegmentIntersect(Point a1, Point a2, Point b1, Point b2)
    {
        long c1 = (a2 - a1).Det(b1 - a1);
        if (c1 == 0 && (a1 - b1).InnerProduct(a2 - b1) <= 0) return true;
        long c2 = (a2 - a1).Det(b2 - a1);
        if (c2 == 0 && (a1 - b2).InnerProduct(a2 - b2) <= 0) return true;
        long c3 = (b2 - b1).Det(a1 - b1);
        if (c3 == 0 && (b1 - a1).InnerProduct(b2 - a1) <= 0) return true;
        long c4 = (b2 - b1).Det(a2 - b1);
        if (c4 == 0 && (b1 - a2).InnerProduct(b2 - a2) <= 0) return true;
        return c1 * c2 < 0 && c3 * c4 < 0;
    }

    struct Point : IEquatable<Point>, IComparable<Point>
    {
        public long X, Y;
        public Point(long x, long y) { X = x; Y = y; }
        public static Point operator +(Point a, Point b)
        {
            return new Point(a.X + b.X, a.Y + b.Y);
        }
        public static Point operator -(Point a, Point b)
        {
            return new Point(a.X - b.X, a.Y - b.Y);
        }
        public long DistSquare(Point b) { return (X - b.X) * (X - b.X) + (Y - b.Y) * (Y - b.Y); }
        public double Dist(Point b) { return Math.Sqrt(DistSquare(b)); }
        public long InnerProduct(Point b) { return X * b.X + Y * b.Y; }
        public long Det(Point b) { return X * b.Y - Y * b.X; }
        public bool OnSegment(Point a, Point b)
        {
            return (a - this).Det(b - this) == 0 && (a - this).InnerProduct(b - this) <= 0;
        }
        public override int GetHashCode() { return (int)(X * 100000 + Y); }
        public bool Equals(Point b) { return X == b.X && Y == b.Y; }
        public int CompareTo(Point b) { return X != b.X ? Math.Sign(X - b.X) : Math.Sign(Y - b.Y); }
        public override string ToString() { return X + ", " + Y; }
    }
}



class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    private static TextReader reader = Console.In;
    private static readonly char[] separator = { ' ' };
    private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    private static string[] A = new string[0];
    private static int i;
    private static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); }
    public static string Line() { return reader.ReadLine().Trim(); }
    private static string[] Split(string s) { return s.Split(separator, op); }
    private static string Next() { CheckNext(); return A[i++]; }
    private static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0