結果

問題 No.3003 多項式の割り算 〜hard〜
ユーザー t98slider
提出日時 2025-02-09 20:05:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 195,672 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-09 20:05:32
合計ジャッジ時間 3,033 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T> std::vector<T> zako_division(std::vector<T> &lhs, const std::vector<T> &rhs){
    std::vector<T> res(lhs.size() - rhs.size() + 1);
    int stop = rhs.size() - 1;
    for(int i = lhs.size() - 1; i >= stop; i--){
        res[i - stop] = lhs[i] / rhs.back();
        T cur = res[i - stop];
        for(int j = 0; j < rhs.size(); j++){
            lhs[i - j] -= rhs.rbegin()[j] * cur;
        }
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a, b;
    cin >> a >> b;
    b = b % 3 + 3;
    vector<long long> A(b + 1), B(3, 1);
    A[b] = a;
    zako_division(A, B);
    cout << A[1] << " " << A[0] << '\n';
}
0