結果
| 問題 | 
                            No.782 マイナス進数
                             | 
                    
| コンテスト | |
| ユーザー | 
                             iicafiaxus
                         | 
                    
| 提出日時 | 2019-01-11 22:51:42 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,165 bytes | 
| コンパイル時間 | 921 ms | 
| コンパイル使用メモリ | 127,216 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-13 02:40:10 | 
| 合計ジャッジ時間 | 3,538 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 27 WA * 9 | 
ソースコード
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
void main(){
	int t = read.to!int;
	int b = read.to!int;
	
	long[] ns;
	foreach(i; 0 .. t) ns ~= read.to!long;
	
	foreach(n; ns){
		int[] xs = f(n, -b);
		for(int i = 0; i < xs.length; i ++){
			debug writeln("xs:", xs);
			if(i % 2 == 0) continue;
			else{
				// [..., x, ...] を [..., (-b - x), 1, ...] に変換
				int x = xs[i];
				if(x == 0) continue;
				xs[i] = -b - x;
				for(int j = i + 1; j <= n; j ++){
					if(j == xs.length){
						xs ~= 1;
						break;
					}
					else if(xs[j] < -b - 1){
						xs[j] += 1;
						break;
					}
					else{
						xs[j] = 0;
						continue;
					}
				}
			}
		}
		string ans = "";
		foreach_reverse(x; xs) ans ~= x.to!string;
		ans.writeln;
	}
}
// nを通常のb進で表したもの(1のけたから順に)
int[] f(long n, int b){
	int[] res;
	long x = n;
	while(x > 0){
		res ~= x % b;
		x /= b;
	}
	return res;
}
            
            
            
        
            
iicafiaxus