結果

問題 No.2247 01 ZigZag
ユーザー 👑 kakel-sankakel-san
提出日時 2023-03-17 22:12:38
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 3,020 bytes
コンパイル時間 5,809 ms
コンパイル使用メモリ 112,456 KB
実行使用メモリ 26,396 KB
最終ジャッジ日時 2023-10-18 20:13:02
合計ジャッジ時間 5,294 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
25,712 KB
testcase_01 AC 28 ms
25,652 KB
testcase_02 AC 29 ms
25,652 KB
testcase_03 AC 34 ms
25,768 KB
testcase_04 AC 29 ms
25,652 KB
testcase_05 AC 33 ms
25,704 KB
testcase_06 AC 33 ms
25,704 KB
testcase_07 AC 29 ms
25,652 KB
testcase_08 AC 35 ms
25,704 KB
testcase_09 AC 35 ms
25,804 KB
testcase_10 AC 29 ms
25,652 KB
testcase_11 AC 34 ms
25,704 KB
testcase_12 AC 33 ms
25,704 KB
testcase_13 AC 33 ms
25,704 KB
testcase_14 AC 29 ms
25,652 KB
testcase_15 AC 34 ms
25,704 KB
testcase_16 AC 34 ms
25,704 KB
testcase_17 AC 34 ms
26,008 KB
testcase_18 AC 29 ms
25,652 KB
testcase_19 AC 28 ms
25,652 KB
testcase_20 AC 29 ms
25,652 KB
testcase_21 AC 31 ms
25,704 KB
testcase_22 AC 36 ms
25,820 KB
testcase_23 AC 32 ms
25,704 KB
testcase_24 AC 29 ms
25,652 KB
testcase_25 AC 34 ms
25,708 KB
testcase_26 AC 34 ms
25,704 KB
testcase_27 AC 33 ms
25,704 KB
testcase_28 AC 34 ms
26,036 KB
testcase_29 AC 35 ms
25,840 KB
testcase_30 AC 36 ms
26,144 KB
testcase_31 AC 28 ms
25,652 KB
testcase_32 AC 34 ms
25,692 KB
testcase_33 AC 32 ms
25,692 KB
testcase_34 AC 32 ms
25,692 KB
testcase_35 AC 32 ms
25,692 KB
testcase_36 AC 32 ms
25,692 KB
testcase_37 AC 31 ms
25,704 KB
testcase_38 AC 33 ms
25,704 KB
testcase_39 AC 32 ms
25,688 KB
testcase_40 AC 29 ms
25,652 KB
testcase_41 AC 32 ms
25,712 KB
testcase_42 AC 32 ms
25,712 KB
testcase_43 AC 29 ms
25,652 KB
testcase_44 AC 29 ms
25,652 KB
testcase_45 AC 37 ms
26,396 KB
testcase_46 AC 37 ms
26,396 KB
testcase_47 AC 30 ms
25,652 KB
testcase_48 AC 31 ms
25,652 KB
testcase_49 AC 29 ms
25,652 KB
testcase_50 AC 29 ms
25,652 KB
testcase_51 AC 29 ms
25,652 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 static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
         Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, k) = (c[0], c[1], c[2]);
        WriteLine(Zig(n, m, k));
    }
    static string Zig(int n, int m, int k)
    {
        if (n == 0)
        {
            if (k == 0) return string.Concat(Enumerable.Repeat('1', m));
            else return "-1";
        }
        if (m == 0)
        {
            if (k == 0) return string.Concat(Enumerable.Repeat('0', n));
            else return "-1";
        }
        if (k == 0)
        {
            return "-1";
        }
        if (n + m - 1 == k)
        {
            var sub = new List<char>(n + m - 1);
            for (var i = 0; i < Math.Min(n, m); ++i)
            {
                sub.Add('0');
                sub.Add('1');
            }
            if (n + 1 == m) sub.Insert(0, '1');
            else if (n == m + 1) sub.Add('0');
            else if (n == m)
            {
            }
            else return "-1";
            return string.Concat(sub);
        }
        var max = Math.Min(Math.Min(n, m) * 2, n + m - 1);
        if (max < k)
        {
            return "-1";
        }
        var ans = new List<char>(n + m);
        if (k % 2 == 0)
        {
            if (n < m && n * 2 == k)
            {
                ans.Add('1');
                --m;
                for (var i = 0; i < n; ++i)
                {
                    ans.Add('0');
                    ans.Add('1');
                    --m;
                }
                for (var i = 0; i < m; ++i) ans.Add('1');
            }
            else
            {
                var mid = new List<char>();
                for (var i = 0; i < k / 2; ++i)
                {
                    mid.Add('0');
                    mid.Add('1');
                    --n;
                    --m;
                }
                for (var i = 0; i + 1 < n; ++i) ans.Add('0');
                ans.AddRange(mid);
                for (var i = 0; i < m; ++i) ans.Add('1');
                ans.Add('0');
            }
        }
        else
        {
            var mid = new List<char>();
            for (var i = 0; i < k / 2; ++i)
            {
                mid.Add('1');
                mid.Add('0');
                --n;
                --m;
            }
            for (var i = 0; i < n; ++i) ans.Add('0');
            ans.AddRange(mid);
            for (var i = 0; i < m; ++i) ans.Add('1');
        }
        return string.Concat(ans);
    }
}
0