結果
問題 | No.78 クジ付きアイスバー |
ユーザー |
![]() |
提出日時 | 2014-11-26 00:19:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,635 bytes |
コンパイル時間 | 1,579 ms |
コンパイル使用メモリ | 115,496 KB |
実行使用メモリ | 27,104 KB |
最終ジャッジ日時 | 2024-10-06 16:49:02 |
合計ジャッジ時間 | 3,183 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 WA * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Linq; public class MyClass { public static void Main() { var array = Array.ConvertAll<string, int>(Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries), int.Parse); int N = array[0]; int K = array[1]; var str = Console.ReadLine(); var strNew = str; int cnt = 0; for (int i = 0; i < str.Length; i++) { cnt--; cnt = Math.Max(cnt, 0); cnt += str[i] - '0'; }//for i for (int i = 0; i < strNew.Length; i++) { if (cnt > 0 && strNew[i] == '0' || strNew[i] == '2') { if (strNew[i] == '0') { cnt--; }//if else { cnt++; }//else strNew = strNew.Substring(0, i) + "1" + strNew.Substring(i + 1); }//if }//for i long res = Count(str, Math.Min(str.Length, K)); res += (K - str.Length) / str.Length * strNew.Count(x => x == '0'); res += Count(strNew, (K - str.Length > 0 ? K % str.Length : 0)); Console.WriteLine(res); } private static long Count(string str, int need) { int res = 0; int cnt = 0; for (int i = 0; i < need; i++) { cnt--; if (cnt < 0) { res++; cnt++; }//if cnt += str[i] - '0'; }//for i return res; } }