結果
| 問題 |
No.782 マイナス進数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-10 21:42:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,209 bytes |
| コンパイル時間 | 1,016 ms |
| コンパイル使用メモリ | 114,532 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-07 06:50:32 |
| 合計ジャッジ時間 | 3,619 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 WA * 9 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;
void solve(long long &n, int base, long long curr, long long minVal, long long maxVal, string& ans)
{
if(minVal <= n && n <= maxVal)
return;
long long curr2 = curr * base;
long long minVal2 = minVal + min(0LL, curr * (-base - 1));
long long maxVal2 = maxVal + max(0LL, curr * (-base - 1));
solve(n, base, curr2, minVal2, maxVal2, ans);
int x = 0;
while(!(minVal <= n && n <= maxVal)){
++ x;
n -= curr;
}
ans += (char)('0' + x);
}
int main()
{
int t, b;
cin >> t >> b;
while(--t >= 0){
long long n;
cin >> n;
string ans;
solve(n, b, 1, 0, 0, ans);
cout << ans << endl;
}
return 0;
}