結果
| 問題 | No.3015 右に寄せろ! | 
| コンテスト | |
| ユーザー |  aketijyuuzou | 
| 提出日時 | 2025-01-27 23:25:39 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 92 ms / 2,000 ms | 
| コード長 | 2,398 bytes | 
| コンパイル時間 | 5,071 ms | 
| コンパイル使用メモリ | 105,344 KB | 
| 実行使用メモリ | 37,760 KB | 
| 最終ジャッジ日時 | 2025-01-27 23:25:48 | 
| 合計ジャッジ時間 | 8,268 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 36 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
// https://yukicoder.me/problems/no/3015
class Program
{
    static string InputPattern = "InputX";
    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();
        if (InputPattern == "Input1") {
            WillReturn.Add("10110110");
            //3
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("0000000010000001111");
            //0
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }
    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];
        List<RunLen.RunLenInfo> RunLenList = RunLen.DeriveRunLenInfoList(S);
        long Answer = 0;
        long BCnt = 0;
        for (int I = RunLenList.Count - 1; 0 <= I; I--) {
            if (RunLenList[I].AppearChar == '0') {
                BCnt += RunLenList[I].RunLen;
            }
            if (RunLenList[I].AppearChar == '1') {
                long Div2 = RunLenList[I].RunLen / 2;
                Answer += Div2 * BCnt;
            }
        }
        Console.WriteLine(Answer);
    }
}
#region RunLen
// ランレングス圧縮(文字列)
internal class RunLen
{
    // ランレングス圧縮情報
    internal struct RunLenInfo
    {
        internal char AppearChar;
        internal int RunLen;
    }
    // ランレングス圧縮結果を返す
    internal static List<RunLenInfo> DeriveRunLenInfoList(string pBaseStr)
    {
        var WillReturn = new List<RunLenInfo>();
        int StrUB = pBaseStr.Length - 1;
        char PrevChar = pBaseStr[0];
        int StrLen = 0;
        for (int I = 0; I <= StrUB; I++) {
            if (pBaseStr[I] != PrevChar) {
                RunLenInfo WillAdd;
                WillAdd.AppearChar = PrevChar;
                WillAdd.RunLen = StrLen;
                WillReturn.Add(WillAdd);
                StrLen = 0;
                PrevChar = pBaseStr[I];
            }
            StrLen++;
            if (I == StrUB) {
                RunLenInfo WillAdd;
                WillAdd.AppearChar = pBaseStr[I];
                WillAdd.RunLen = StrLen;
                WillReturn.Add(WillAdd);
            }
        }
        return WillReturn;
    }
}
#endregion
            
            
            
        