結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2018-06-28 13:52:31 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,844 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 110,312 KB |
実行使用メモリ | 27,968 KB |
最終ジャッジ日時 | 2024-06-30 23:25:00 |
合計ジャッジ時間 | 2,530 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 18 |
コンパイルメッセージ
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; using System.Text; using System.Threading.Tasks; namespace bitscreen { class Program { static int modoru(int cur, int goal, ref int step_counter, ref int modoru_counter) { int modoru_num = bitCounter(cur); modoru_num = cur - modoru_num; int ret = 0; if (modoru_num < 0) { modoru_counter++; return -2; } else if (modoru_num == goal) { step_counter++; return 0; } else { step_counter++; modoru_counter++; ret = susumu(modoru_num, goal, ref step_counter, ref modoru_counter); if(ret != 0) { return -2; } return ret; } } static int susumu(int cur, int goal, ref int step_counter, ref int modoru_counter) { int susumu_num = bitCounter(cur); susumu_num += cur; if(susumu_num > goal) { return -1; } else if (susumu_num == goal) { step_counter++; return 0; } else { step_counter++; int ret; if (susumu_num == 0) susumu_num++; ret = susumu(susumu_num, goal, ref step_counter, ref modoru_counter); if (ret == -1) { if(modoru_counter == 1) { return -1; } ret = modoru(susumu_num, goal, ref step_counter, ref modoru_counter); if (ret == -2) { return -3; } } return ret; } } static int bitCounter(int n) { int bitmask = 0x00000001; int data = n; int count = 0; for (int j = 0; j < 32; j++) { if ((data & bitmask) == 1) count++; data = data >> 1; } return count; } static void Main(string[] args) { string s = Console.ReadLine(); int step_counter = 0; int ret = 0; int modoru_counter = 0; ret = susumu(0,int.Parse(s), ref step_counter, ref modoru_counter); if (ret == 0) { Console.WriteLine(step_counter); } else { Console.WriteLine(-1); } } } }