結果

問題 No.438 Cwwプログラミング入門
ユーザー 古寺いろは古寺いろは
提出日時 2016-10-29 00:23:20
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 4,807 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 110,020 KB
実行使用メモリ 23,004 KB
最終ジャッジ日時 2023-08-18 15:40:37
合計ジャッジ時間 13,824 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
20,888 KB
testcase_01 AC 54 ms
18,816 KB
testcase_02 AC 52 ms
22,904 KB
testcase_03 AC 52 ms
22,808 KB
testcase_04 AC 54 ms
20,872 KB
testcase_05 AC 53 ms
22,820 KB
testcase_06 AC 50 ms
20,884 KB
testcase_07 AC 52 ms
22,900 KB
testcase_08 AC 53 ms
20,900 KB
testcase_09 AC 52 ms
20,804 KB
testcase_10 AC 51 ms
18,876 KB
testcase_11 AC 50 ms
20,976 KB
testcase_12 AC 51 ms
20,792 KB
testcase_13 AC 52 ms
20,856 KB
testcase_14 AC 55 ms
22,964 KB
testcase_15 AC 54 ms
20,784 KB
testcase_16 AC 51 ms
20,968 KB
testcase_17 AC 50 ms
22,864 KB
testcase_18 AC 51 ms
20,760 KB
testcase_19 AC 50 ms
20,852 KB
testcase_20 AC 51 ms
20,976 KB
testcase_21 AC 50 ms
20,876 KB
testcase_22 AC 51 ms
20,880 KB
testcase_23 AC 50 ms
20,800 KB
testcase_24 AC 50 ms
20,864 KB
testcase_25 AC 51 ms
20,728 KB
testcase_26 AC 51 ms
22,784 KB
testcase_27 AC 50 ms
20,812 KB
testcase_28 AC 51 ms
20,848 KB
testcase_29 AC 51 ms
20,748 KB
testcase_30 AC 51 ms
20,860 KB
testcase_31 AC 52 ms
22,792 KB
testcase_32 AC 54 ms
22,752 KB
testcase_33 AC 51 ms
20,792 KB
testcase_34 AC 49 ms
18,808 KB
testcase_35 AC 55 ms
20,724 KB
testcase_36 AC 52 ms
20,768 KB
testcase_37 AC 54 ms
20,868 KB
testcase_38 AC 51 ms
20,800 KB
testcase_39 AC 51 ms
20,916 KB
testcase_40 AC 50 ms
22,888 KB
testcase_41 AC 53 ms
20,792 KB
testcase_42 AC 51 ms
20,772 KB
testcase_43 AC 49 ms
22,956 KB
testcase_44 AC 49 ms
18,912 KB
testcase_45 AC 51 ms
20,804 KB
testcase_46 AC 51 ms
20,784 KB
testcase_47 AC 52 ms
20,844 KB
testcase_48 AC 52 ms
22,840 KB
testcase_49 AC 53 ms
20,892 KB
testcase_50 AC 52 ms
20,852 KB
testcase_51 AC 51 ms
20,864 KB
testcase_52 AC 53 ms
22,816 KB
testcase_53 AC 53 ms
20,920 KB
testcase_54 AC 50 ms
20,972 KB
testcase_55 AC 52 ms
20,928 KB
testcase_56 AC 52 ms
20,804 KB
testcase_57 AC 51 ms
18,928 KB
testcase_58 AC 52 ms
23,004 KB
testcase_59 AC 52 ms
22,868 KB
testcase_60 AC 52 ms
18,788 KB
testcase_61 AC 52 ms
20,964 KB
testcase_62 AC 49 ms
22,756 KB
testcase_63 AC 51 ms
20,784 KB
testcase_64 AC 52 ms
18,844 KB
testcase_65 AC 49 ms
22,904 KB
testcase_66 AC 51 ms
20,716 KB
testcase_67 AC 50 ms
20,912 KB
testcase_68 AC 50 ms
20,856 KB
testcase_69 AC 53 ms
20,960 KB
testcase_70 AC 51 ms
20,768 KB
testcase_71 AC 52 ms
20,760 KB
testcase_72 AC 53 ms
20,784 KB
testcase_73 AC 52 ms
20,808 KB
testcase_74 AC 53 ms
20,748 KB
testcase_75 AC 54 ms
22,900 KB
testcase_76 AC 50 ms
20,784 KB
testcase_77 AC 51 ms
22,928 KB
testcase_78 AC 53 ms
22,900 KB
testcase_79 AC 50 ms
22,796 KB
testcase_80 AC 51 ms
22,800 KB
testcase_81 AC 50 ms
20,948 KB
testcase_82 AC 55 ms
20,880 KB
testcase_83 AC 52 ms
18,720 KB
testcase_84 AC 51 ms
20,856 KB
testcase_85 AC 52 ms
22,880 KB
testcase_86 AC 54 ms
20,856 KB
testcase_87 AC 54 ms
20,780 KB
testcase_88 AC 53 ms
22,820 KB
testcase_89 AC 50 ms
20,792 KB
testcase_90 AC 51 ms
22,896 KB
testcase_91 AC 52 ms
20,768 KB
testcase_92 AC 51 ms
22,892 KB
testcase_93 AC 52 ms
20,872 KB
testcase_94 AC 52 ms
20,744 KB
testcase_95 AC 53 ms
20,968 KB
testcase_96 AC 53 ms
22,824 KB
testcase_97 AC 51 ms
22,924 KB
testcase_98 AC 51 ms
20,972 KB
testcase_99 AC 53 ms
20,820 KB
testcase_100 AC 53 ms
22,792 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;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Iroha
{
    public Iroha() { }
    public static int Main()
    {
        new Iroha().calc();
        return 0;
    }

    Scanner cin;

    long x, y, z;

    //こういう分かりにくい出力ってあんまり良くないと思いますよ?
    string NG = "mourennaihasimasenn";

    void calc()
    {
        cin = new Scanner();
        x = cin.nextLong();
        y = cin.nextLong();
        z = cin.nextLong();
        long p = 0, q = 0;
        if (z == 0)
        {
            Console.WriteLine("ccW");
            return;
        }
        if(x == 0 && y == 0)
        {
            Console.WriteLine(NG);
            return;
        }
        if(x == 0)
        {
            if(z % y == 0 && z / y < 5001)
            {
                StringBuilder tsb = new StringBuilder();
                tsb.Append('w');
                for (int i = 1; i < z / y; i++)
                {
                    tsb.Append("wC");
                }
                Console.WriteLine(tsb.ToString());
            }
            else Console.WriteLine(NG);
            return;
        }
        if (y == 0)
        {
            if (z % x == 0 && z / x < 5001)
            {
                StringBuilder tsb = new StringBuilder();
                tsb.Append('c');
                for (int i = 1; i < z / x; i++)
                {
                    tsb.Append("cC");
                }
                Console.WriteLine(tsb.ToString());
            }
            else Console.WriteLine(NG);
            return;
        }

        extgcd(x, y, ref p, ref q);
        long g = gcd(x, y);
        
        if(z % g != 0)
        {
            Console.WriteLine(NG);
            return;
        }
        p *= (z / g);
        q *= (z / g);

        //throw new Exception("errorcheck");
        //return;

        while (Math.Abs(p) + Math.Abs(q) > Math.Abs(p + (y / g) * 10000) + Math.Abs(q - (x / g) * 10000))
        {
            p += (y / g) * 10000;
            q -= (x / g) * 10000;
        }

        while (Math.Abs(p) + Math.Abs(q) > Math.Abs(p - (y / g) * 10000) + Math.Abs(q + (x / g) * 10000))
        {
            p -= (y / g) * 10000;
            q += (x / g) * 10000;
        }


        while (Math.Abs(p) + Math.Abs(q) > Math.Abs(p + y / g) + Math.Abs(q - x / g))
        {
            p += y / g;
            q -= x / g;
        }

        while (Math.Abs(p) + Math.Abs(q) > Math.Abs(p - y / g) + Math.Abs(q + x / g))
        {
            p -= y / g;
            q += x / g;
        }

        StringBuilder sb = new StringBuilder();
        int WCount = 0;
        int firstadd = 0;

        while (sb.Length <= 10000 && p < 0)
        {
            sb.Append('c');
            WCount++;
            p++;
        }

        while (sb.Length <= 10000 && q < 0)
        {
            sb.Append('w');
            WCount++;
            q++;
        }

        while (sb.Length <= 10000 && p > 0)
        {
            sb.Append('c');
            if (firstadd != 0)
            {
                sb.Append('C');
            }
            else firstadd++;
            p--;
        }

        while (sb.Length <= 10000 && q > 0)
        {
            sb.Append('w');
            if (firstadd != 0)
            {
                sb.Append('C');
            }
            else firstadd++;
            q--;
        }

        sb.Append(new string('W', WCount));


        if (sb.Length > 10000) Console.WriteLine(NG);
        else Console.WriteLine(sb.ToString());

    }

    //swap
    void swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    }

    long gcd(long a, long b)
    {
        return b != 0 ? gcd(b, a % b) : a;
    }
    long lcm(long a, long b)
    {
        return a * b / gcd(a, b);
    }

    // a x + b y = gcd(a, b)
    long extgcd(long a, long b, ref long x, ref long y)
    {
        long g = a; x = 1; y = 0;
        if (b != 0) {
            g = extgcd(b, a % b, ref y, ref x);
            y -= (a / b) * x;
        }
        return g;
    }


}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}
0