結果

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

ソースコード

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);
    int a, b;
    cin >> a >> b;
    vector<int> A(b + 1), B(3, 1);
    A[b] = a;
    if(b >= 2) zako_division(A, B);
    cout << A[1] << " " << A[0] << '\n';
}
0