結果

問題 No.782 マイナス進数
ユーザー kuuso1kuuso1
提出日時 2019-01-11 22:10:14
言語 C#
(csc 3.9.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 2,314 ms
使用メモリ 29,368 KB
最終ジャッジ日時 2023-01-06 12:35:31
合計ジャッジ時間 7,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 63 ms
20,824 KB
testcase_01 AC 62 ms
20,936 KB
testcase_02 AC 103 ms
22,816 KB
testcase_03 AC 107 ms
24,920 KB
testcase_04 AC 108 ms
29,148 KB
testcase_05 AC 106 ms
28,992 KB
testcase_06 AC 104 ms
29,108 KB
testcase_07 AC 111 ms
25,304 KB
testcase_08 AC 104 ms
24,996 KB
testcase_09 AC 103 ms
27,112 KB
testcase_10 AC 102 ms
27,040 KB
testcase_11 AC 111 ms
29,368 KB
testcase_12 AC 108 ms
29,200 KB
testcase_13 AC 126 ms
27,992 KB
testcase_14 AC 107 ms
27,128 KB
testcase_15 AC 109 ms
27,256 KB
testcase_16 AC 107 ms
25,128 KB
testcase_17 AC 118 ms
27,564 KB
testcase_18 AC 107 ms
29,212 KB
testcase_19 AC 115 ms
27,516 KB
testcase_20 AC 109 ms
27,264 KB
testcase_21 AC 116 ms
27,528 KB
testcase_22 AC 110 ms
27,160 KB
testcase_23 AC 107 ms
29,104 KB
testcase_24 AC 128 ms
28,004 KB
testcase_25 AC 108 ms
27,208 KB
testcase_26 AC 113 ms
29,304 KB
testcase_27 AC 111 ms
27,272 KB
testcase_28 AC 107 ms
25,252 KB
testcase_29 AC 61 ms
23,032 KB
testcase_30 AC 61 ms
22,980 KB
testcase_31 AC 62 ms
21,044 KB
testcase_32 AC 61 ms
20,832 KB
testcase_33 AC 62 ms
22,836 KB
testcase_34 AC 61 ms
20,924 KB
testcase_35 AC 61 ms
18,812 KB
testcase_36 AC 62 ms
20,704 KB
testcase_37 AC 61 ms
20,896 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