結果
問題 | No.782 マイナス進数 |
ユーザー |
|
提出日時 | 2019-05-05 11:56:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 832 bytes |
コンパイル時間 | 1,699 ms |
コンパイル使用メモリ | 170,276 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 15:51:39 |
合計ジャッジ時間 | 3,273 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); long long T, B; cin >> T >> B; long long b = -B; vector<long long> Ns(T, 0); for (auto & n: Ns) cin >> n; for (auto n : Ns){ if (n == 0){ cout << "0\n"; continue; } vector<long long> ans; int sign = 1; while (n > 0){ if (sign == 1){ ans.push_back(n % b); n /= b; sign = -1; }else{ int tmp = (b - (n % b)) % b; ans.push_back(tmp); n = (n + tmp)/b; sign = 1; } } for (auto it = ans.rbegin(); it != ans.rend(); ++it) cout << *it; cout << '\n'; } return 0; }