結果

問題 No.455 冬の大三角
ユーザー eitahoeitaho
提出日時 2016-12-06 00:09:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 4,485 bytes
コンパイル時間 4,518 ms
コンパイル使用メモリ 111,132 KB
実行使用メモリ 22,952 KB
最終ジャッジ日時 2023-09-12 08:12:54
合計ジャッジ時間 9,970 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
20,772 KB
testcase_01 AC 58 ms
20,848 KB
testcase_02 AC 58 ms
20,848 KB
testcase_03 AC 57 ms
20,780 KB
testcase_04 AC 59 ms
20,784 KB
testcase_05 AC 58 ms
20,764 KB
testcase_06 AC 58 ms
20,844 KB
testcase_07 AC 59 ms
22,744 KB
testcase_08 AC 59 ms
20,756 KB
testcase_09 AC 57 ms
20,752 KB
testcase_10 AC 59 ms
22,848 KB
testcase_11 AC 58 ms
22,884 KB
testcase_12 AC 58 ms
20,900 KB
testcase_13 AC 58 ms
22,824 KB
testcase_14 AC 58 ms
20,848 KB
testcase_15 AC 59 ms
22,820 KB
testcase_16 AC 58 ms
22,908 KB
testcase_17 AC 59 ms
20,760 KB
testcase_18 AC 57 ms
20,784 KB
testcase_19 AC 57 ms
22,808 KB
testcase_20 AC 60 ms
20,780 KB
testcase_21 AC 57 ms
20,740 KB
testcase_22 AC 58 ms
20,888 KB
testcase_23 AC 58 ms
20,756 KB
testcase_24 AC 58 ms
18,756 KB
testcase_25 AC 58 ms
20,752 KB
testcase_26 AC 59 ms
20,764 KB
testcase_27 AC 58 ms
20,864 KB
testcase_28 AC 58 ms
18,668 KB
testcase_29 AC 59 ms
22,872 KB
testcase_30 AC 59 ms
18,724 KB
testcase_31 AC 59 ms
20,780 KB
testcase_32 AC 60 ms
20,864 KB
testcase_33 AC 60 ms
20,972 KB
testcase_34 AC 58 ms
22,936 KB
testcase_35 AC 58 ms
22,804 KB
testcase_36 AC 58 ms
20,892 KB
testcase_37 AC 59 ms
20,900 KB
testcase_38 AC 58 ms
20,776 KB
testcase_39 AC 59 ms
20,968 KB
testcase_40 AC 59 ms
22,816 KB
testcase_41 AC 59 ms
22,824 KB
testcase_42 AC 59 ms
20,872 KB
testcase_43 AC 58 ms
22,836 KB
testcase_44 AC 58 ms
20,872 KB
testcase_45 AC 59 ms
20,916 KB
testcase_46 AC 58 ms
20,860 KB
testcase_47 AC 59 ms
22,952 KB
testcase_48 AC 60 ms
20,864 KB
testcase_49 AC 58 ms
20,748 KB
testcase_50 AC 57 ms
20,796 KB
testcase_51 AC 58 ms
22,916 KB
testcase_52 AC 59 ms
22,788 KB
testcase_53 AC 58 ms
22,744 KB
testcase_54 AC 58 ms
20,836 KB
testcase_55 AC 59 ms
22,816 KB
testcase_56 AC 58 ms
22,732 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int H = Reader.Int(), W = Reader.Int();
        var grid = Reader.StringArray(H);
        var P = new List<Point>();

        for (int y = 0; y < H; y++)
            for (int x = 0; x < W; x++)
                if (grid[y][x] == '*') P.Add(new Point(x, y));
        var line = new Line(P[0], P[1]);
        for (int y = 0, found = 0; y < H && found == 0; y++)
            for (int x = 0; x < W; x++)
                if (grid[y][x] == '-' && !OnLine(new Point(x, y), line))
                {
                    grid[y] = grid[y].Remove(x, 1).Insert(x, "*");
                    found = 1;
                    break;
                }

        Console.WriteLine(string.Join("\n", grid));
    }

    public bool OnLine(Point p, Line line)
    {
        return (line.A - p).Det(line.B - p) == 0;
    }
    public class Line
    {
        public Point A, B;
        public Point this[int i]
        {
            get { if (i == 0) return A; if (i == 1) return B; throw new ArgumentException(); }
        }
        public Line(Point a, Point b) { Debug.Assert(a != b); A = a; B = b; }
        public override string ToString() { return A + " - " + B; }
    }
    public 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 Dot(Point b) { return X * b.X + Y * b.Y; }
        public long Det(Point b) { return X * b.Y - Y * b.X; }
        public bool Equals(Point b) { return X == b.X && Y == b.Y; }
        public override bool Equals(object obj) { return Equals((Point)obj); }
        public static bool operator ==(Point a, Point b) { return a.Equals(b); }
        public static bool operator !=(Point a, Point b) { return !a.Equals(b); }
        public int CompareTo(Point b) { return X != b.X ? Math.Sign(X - b.X) : Math.Sign(Y - b.Y); }
        public override int GetHashCode() { return (int)(X * 100000 + Y); }
        public override string ToString() { return X + ", " + Y; }
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    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 Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    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