結果

問題 No.782 マイナス進数
ユーザー kuuso1kuuso1
提出日時 2019-01-11 22:10:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 3,823 ms
コンパイル使用メモリ 104,184 KB
実行使用メモリ 28,088 KB
最終ジャッジ日時 2023-08-20 06:52:04
合計ジャッジ時間 7,945 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
20,876 KB
testcase_01 AC 66 ms
20,784 KB
testcase_02 AC 110 ms
25,044 KB
testcase_03 AC 109 ms
26,944 KB
testcase_04 AC 111 ms
25,024 KB
testcase_05 AC 109 ms
27,064 KB
testcase_06 AC 109 ms
26,892 KB
testcase_07 AC 119 ms
27,472 KB
testcase_08 AC 113 ms
27,012 KB
testcase_09 AC 110 ms
26,940 KB
testcase_10 AC 108 ms
26,856 KB
testcase_11 AC 116 ms
25,260 KB
testcase_12 AC 116 ms
25,036 KB
testcase_13 AC 133 ms
25,904 KB
testcase_14 AC 116 ms
27,108 KB
testcase_15 AC 118 ms
27,304 KB
testcase_16 AC 114 ms
24,988 KB
testcase_17 AC 122 ms
23,488 KB
testcase_18 AC 116 ms
25,112 KB
testcase_19 AC 123 ms
25,528 KB
testcase_20 AC 115 ms
25,296 KB
testcase_21 AC 127 ms
25,400 KB
testcase_22 AC 122 ms
27,196 KB
testcase_23 AC 115 ms
27,040 KB
testcase_24 AC 136 ms
28,088 KB
testcase_25 AC 116 ms
25,108 KB
testcase_26 AC 124 ms
27,276 KB
testcase_27 AC 118 ms
27,140 KB
testcase_28 AC 116 ms
25,020 KB
testcase_29 AC 66 ms
22,760 KB
testcase_30 AC 64 ms
18,612 KB
testcase_31 AC 65 ms
20,820 KB
testcase_32 AC 67 ms
20,952 KB
testcase_33 AC 66 ms
20,784 KB
testcase_34 AC 65 ms
20,764 KB
testcase_35 AC 68 ms
22,816 KB
testcase_36 AC 67 ms
18,800 KB
testcase_37 AC 66 ms
22,872 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var sb = new StringBuilder();
		foreach(var n in Ns){
			if(n == 0){
				sb.AppendLine("0");
				continue;
			}
			int[] d = new int[60];
			long v = n;
			for(int i=0;i<60;i++){
				d[i] = (int)(v % B);
				v /= B;
			}
			for(int i=0;i<59;i++){
				if(i % 2 == 0){
					if(d[i] < B) continue;
					d[i + 1] += d[i] / B;
					d[i] %= B;
				} else {
					d[i + 1] += d[i] / B;
					d[i] %= B;
					if(d[i] > 0){
						d[i + 1] += 1;
						d[i] = B - d[i];
					}
				}
			}
			var l = new List<int>();
			for(int i=0;i<60;i++) l.Add(d[i]);
			while(l[l.Count - 1] == 0) l.RemoveAt(l.Count - 1);
			l.Reverse();
			sb.AppendLine(String.Join("",l));
		}
		
		Console.Write(sb.ToString());
	}
	int T, B;
	long[] Ns;
	public Sol(){
		var d = ria();
		T = d[0]; B = -d[1];
		Ns = new long[T];
		for(int i=0;i<T;i++) Ns[i] = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0