結果

問題 No.345 最小チワワ問題
ユーザー fujitafujita
提出日時 2023-05-10 17:47:35
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 2,596 bytes
コンパイル時間 14,109 ms
コンパイル使用メモリ 168,120 KB
実行使用メモリ 181,304 KB
最終ジャッジ日時 2024-05-05 04:42:49
合計ジャッジ時間 16,756 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
27,136 KB
testcase_01 AC 48 ms
27,008 KB
testcase_02 AC 47 ms
27,260 KB
testcase_03 AC 50 ms
27,008 KB
testcase_04 AC 48 ms
27,260 KB
testcase_05 AC 47 ms
27,136 KB
testcase_06 AC 47 ms
27,264 KB
testcase_07 AC 46 ms
26,620 KB
testcase_08 AC 46 ms
26,880 KB
testcase_09 AC 46 ms
27,008 KB
testcase_10 AC 47 ms
27,136 KB
testcase_11 AC 47 ms
26,752 KB
testcase_12 AC 47 ms
26,752 KB
testcase_13 AC 49 ms
26,624 KB
testcase_14 AC 49 ms
27,520 KB
testcase_15 AC 47 ms
27,136 KB
testcase_16 AC 48 ms
27,264 KB
testcase_17 AC 47 ms
27,008 KB
testcase_18 WA -
testcase_19 AC 48 ms
26,880 KB
testcase_20 AC 48 ms
27,008 KB
testcase_21 AC 47 ms
27,116 KB
testcase_22 AC 54 ms
27,008 KB
testcase_23 AC 47 ms
27,392 KB
testcase_24 AC 47 ms
27,244 KB
testcase_25 AC 47 ms
27,136 KB
testcase_26 AC 47 ms
27,136 KB
testcase_27 AC 47 ms
27,008 KB
testcase_28 AC 47 ms
26,752 KB
testcase_29 AC 47 ms
27,136 KB
testcase_30 AC 51 ms
27,244 KB
testcase_31 AC 46 ms
181,304 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (98 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
namespace yukicoder
{
    class Program
    {

        static void Main(string[] args)
        {

            var str = Console.ReadLine();
            string[] strings = new string[str.Length];
            int C = 0 , W = 0 ,  Ccnt = str.Length -3 , cc = 0 , Wcnt = 0 , anscount = 0 , temp = str.Length;


            for (int i = 0; i < str.Length; i++)
            {
                if(str.Substring(i,1) == "c" && C == 0)
                {        
                    C = 1;
                    Ccnt = i;
                    
                }
                else if (str.Substring(i, 1) == "c" && C == 1 && cc == 0)
                {
                    cc = i;
                }
                else if (str.Substring(i, 1) == "w" && C == 1)
                {
                    W++;
                    Wcnt = i;
                }
                
                if(C == 1 && W == 2 && Wcnt - Ccnt + 1 > anscount || C == 1 && W == 2 && Wcnt - Ccnt + 1 < anscount || C == 1 && W == 2 && Wcnt - Ccnt + 1 > temp || C == 1 && W == 2 && Wcnt - Ccnt + 1 < temp)//&& i == str.Length - 1
                {
                    if(anscount == 0 || cc == 0)
                    {
                        int sum = Wcnt - Ccnt + 1;
                        anscount = sum;
                        if(cc == 0)
                        {
                            break;
                        }
                        i = cc - 1;
                        C = 0;
                        Ccnt = 0;
                        cc = 0;
                        W = 0;
                        Wcnt = 0;
                    }
                    else
                    {
                        int sum2 = Wcnt - Ccnt + 1;
                        if(temp > sum2)
                        {
                            temp = sum2;
                        }
                        i = cc - 1;
                        C = 0;
                        Ccnt = 0;
                        W = 0;
                        Wcnt = 0;
                        cc = 0;
                    }
                    
                }
                
            }

            if(anscount == 0)
            {
                Console.WriteLine("-1");
            }
            else if (anscount > temp)
            {
                Console.WriteLine(temp);
            }
            else if (anscount < temp)
            {
                Console.WriteLine(anscount);
            }
            else if (anscount == temp)
            {
                Console.WriteLine(anscount);
            }
        }
    }
}
0