結果
問題 | No.3 ビットすごろく |
ユーザー | oreoreoresan |
提出日時 | 2018-06-28 13:54:41 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,844 bytes |
コンパイル時間 | 876 ms |
コンパイル使用メモリ | 109,984 KB |
実行使用メモリ | 26,068 KB |
最終ジャッジ日時 | 2024-06-30 23:24:57 |
合計ジャッジ時間 | 2,661 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
23,396 KB |
testcase_01 | AC | 24 ms
23,520 KB |
testcase_02 | AC | 23 ms
23,384 KB |
testcase_03 | AC | 23 ms
23,644 KB |
testcase_04 | WA | - |
testcase_05 | AC | 23 ms
23,812 KB |
testcase_06 | AC | 23 ms
23,512 KB |
testcase_07 | AC | 24 ms
23,984 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 24 ms
25,852 KB |
testcase_13 | AC | 23 ms
21,680 KB |
testcase_14 | AC | 24 ms
21,684 KB |
testcase_15 | AC | 23 ms
23,516 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 23 ms
25,684 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 24 ms
23,860 KB |
testcase_22 | AC | 24 ms
23,588 KB |
testcase_23 | AC | 24 ms
21,680 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
コンパイルメッセージ
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); } } } }