結果

問題 No.754 畳み込みの和
ユーザー TAISA_TAISA_
提出日時 2018-12-23 20:08:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 843 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 187,316 KB
実行使用メモリ 19,936 KB
最終ジャッジ日時 2023-10-26 02:36:13
合計ジャッジ時間 4,361 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int n;cin>>n;
    vector<ll> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    vector<thread> t(n);
    vector<promise<int>> p(n);
    vector<future<int>> f(n);
    for(int i=0;i<n;i++)f[i]=p[i].get_future();
    auto calc=[&p,&a,&b,&n](int id){
        ll res=0;
        for(int j=0;j<n;j++){
            res+=a[id]*b[j];
        }
        p[id].set_value(res);
    };
    for(int i=0;i<n;i++){
        t[i]=thread(calc,i);
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=f[i].get();
    }
    cout<<ans<<endl;
    for(int i=0;i<n;i++){
        t[i].join();
    }
}
0