結果

問題 No.345 最小チワワ問題
ユーザー fujitafujita
提出日時 2023-05-11 09:51:55
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 2,954 bytes
コンパイル時間 19,829 ms
コンパイル使用メモリ 144,684 KB
実行使用メモリ 158,032 KB
最終ジャッジ日時 2023-08-18 06:30:23
合計ジャッジ時間 13,276 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
26,568 KB
testcase_01 AC 47 ms
26,100 KB
testcase_02 AC 46 ms
26,348 KB
testcase_03 AC 46 ms
26,200 KB
testcase_04 AC 46 ms
26,464 KB
testcase_05 AC 45 ms
26,440 KB
testcase_06 AC 46 ms
26,180 KB
testcase_07 AC 44 ms
26,120 KB
testcase_08 AC 44 ms
26,020 KB
testcase_09 AC 44 ms
25,996 KB
testcase_10 AC 46 ms
26,588 KB
testcase_11 AC 44 ms
26,144 KB
testcase_12 AC 44 ms
25,932 KB
testcase_13 AC 44 ms
26,040 KB
testcase_14 AC 48 ms
26,628 KB
testcase_15 AC 46 ms
26,160 KB
testcase_16 AC 46 ms
26,508 KB
testcase_17 AC 46 ms
26,348 KB
testcase_18 AC 46 ms
26,516 KB
testcase_19 AC 46 ms
26,444 KB
testcase_20 AC 46 ms
26,412 KB
testcase_21 AC 44 ms
26,316 KB
testcase_22 AC 46 ms
26,452 KB
testcase_23 AC 46 ms
26,204 KB
testcase_24 AC 46 ms
26,136 KB
testcase_25 AC 46 ms
26,328 KB
testcase_26 AC 46 ms
26,148 KB
testcase_27 AC 46 ms
26,436 KB
testcase_28 AC 44 ms
26,340 KB
testcase_29 AC 46 ms
26,212 KB
testcase_30 AC 47 ms
26,432 KB
testcase_31 AC 45 ms
158,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 152 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.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;
                        if(anscount > sum || anscount == 0)
                        {
                            anscount = sum;
                        }
                        if(cc == 0 || !(anscount == 0))
                        {
                            i = Ccnt;
                            C = 0;
                            Ccnt = 0;
                            //cc = 0;
                            W = 0;
                            Wcnt = 0;
                            continue;
                        }
                        else if (cc == 0 || anscount == 0)
                        {
                            continue;
                        }
                        
                    }
                    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