結果

問題 No.782 マイナス進数
ユーザー rickytheta
提出日時 2019-01-11 22:03:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 600 bytes
コンパイル時間 1,376 ms
コンパイル使用メモリ 160,636 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 06:57:30
合計ジャッジ時間 7,838 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 RE * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     scanf("%d%d",&t,&b);
      |     ~~~~~^~~~~~~~~~~~~~
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int t,b;
string rev[12525];

int main(){
    scanf("%d%d",&t,&b);
    b = -b;
    REP(v,125252){
        int ev = 0;
        string s;
        int bb = 1;
        int x = v;
        while(x>0){
            int c = x % b;
            x /= b;
            ev += bb * c;
            bb *= -b;
            s = string(1,c+'0') + s;
        }
        if(ev<0 || ev>=12525)continue;
        rev[ev] = s;
    }
    while(t--){
        int n;
        scanf("%d",&n);
        puts(rev[n].c_str());
    }
    return 0;
}
0