結果

問題 No.1053 ゲーミング棒
ユーザー Lily89164763Lily89164763
提出日時 2020-05-15 23:59:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,901 bytes
コンパイル時間 2,507 ms
コンパイル使用メモリ 111,292 KB
実行使用メモリ 42,324 KB
最終ジャッジ日時 2023-10-19 18:20:30
合計ジャッジ時間 5,139 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
26,476 KB
testcase_01 AC 32 ms
26,488 KB
testcase_02 AC 32 ms
26,488 KB
testcase_03 AC 32 ms
26,484 KB
testcase_04 AC 31 ms
26,476 KB
testcase_05 AC 32 ms
26,488 KB
testcase_06 AC 32 ms
26,488 KB
testcase_07 AC 31 ms
26,488 KB
testcase_08 AC 32 ms
26,476 KB
testcase_09 AC 31 ms
26,488 KB
testcase_10 AC 33 ms
26,488 KB
testcase_11 AC 33 ms
26,484 KB
testcase_12 AC 33 ms
26,484 KB
testcase_13 AC 32 ms
26,492 KB
testcase_14 AC 32 ms
26,488 KB
testcase_15 AC 32 ms
26,476 KB
testcase_16 AC 31 ms
26,488 KB
testcase_17 AC 32 ms
26,476 KB
testcase_18 AC 32 ms
26,476 KB
testcase_19 AC 32 ms
26,488 KB
testcase_20 AC 32 ms
26,488 KB
testcase_21 AC 32 ms
26,488 KB
testcase_22 AC 32 ms
26,476 KB
testcase_23 AC 72 ms
38,240 KB
testcase_24 AC 74 ms
38,240 KB
testcase_25 AC 84 ms
42,324 KB
testcase_26 AC 84 ms
42,324 KB
testcase_27 AC 32 ms
26,488 KB
testcase_28 AC 31 ms
26,488 KB
testcase_29 AC 31 ms
26,488 KB
testcase_30 AC 56 ms
30,780 KB
testcase_31 AC 57 ms
30,776 KB
testcase_32 AC 56 ms
30,776 KB
testcase_33 AC 57 ms
30,780 KB
testcase_34 AC 57 ms
30,780 KB
testcase_35 AC 59 ms
31,728 KB
testcase_36 AC 60 ms
31,576 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.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] a = sc.IntArray();

        var g = new List<Pair>();
        int target = a[0];
        int cnt = 1;
        for (int i = 1; i < n; i++)
        {
            if (target != a[i])
            {
                g.Add(new Pair(target, cnt));
                cnt = 0;
                target = a[i];
            }
            cnt++;
        }
        g.Add(new Pair(target, cnt));

        // もともと条件を満たす

        {
            var hs = new HashSet<int>();
            bool f = true;
            foreach (var p in g)
            {
                f &= hs.Add(p.A);
            }
            if (f)
            {
                Console.WriteLine(0);
                return;
            }
        }

        // 先頭と最後が同じ
        {
            var hs = new HashSet<int>();
            bool f = g[0].A == g[g.Count - 1].A;

            for (int i = 0; i < g.Count - 1; i++)
            {
                f &= hs.Add(g[i].A);
            }
            if (f)
            {
                Console.WriteLine(1);
                return;
            }
        }
        Console.WriteLine("-1");
    }

    public static void Main(string[] args) => new Program().Solve();
}

struct Pair
{
    public int A, C;
    public Pair(int a, int c)
    {
        A = a;
        C = c;
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}
0