結果

問題 No.9000 Hello World! (テスト用)
ユーザー Min_25Min_25
提出日時 2016-06-21 09:09:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 484 ms / 5,000 ms
コード長 1,126 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 73,376 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 23:34:21
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 476 ms
5,248 KB
testcase_01 AC 484 ms
5,376 KB
testcase_02 AC 481 ms
5,376 KB
testcase_03 AC 479 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <thread>
#include <mutex>
#include <vector>

using namespace std;

void parallel() {
  using ll = long long;

  const int nthread = thread::hardware_concurrency();
  vector<thread> threads;

  mutex mtx;
  const ll MOD = 1e8 + 7;
  const ll A = 1, B = MOD;

  ll prod = 1;
  for (int i = 0; i < nthread; ++i) {
    ll beg = A + (B - A) * i / nthread;
    ll end = A + (B - A) * (i + 1) / nthread;
    auto product = [&prod, &mtx, beg, end] {
      ll q = 1;
      for (ll i = beg; i < end; ++i) q = q * i % MOD;
      mtx.lock();
      prod = prod * q % MOD;
      mtx.unlock();
    };
    threads.push_back(thread(product));
  }
  for (auto& thread : threads) thread.join();
  fprintf(stderr, "%llu\n", prod);
  puts("Hello World!");
}

int main() {
  auto beg = chrono::system_clock::now();
  auto ubeg = clock();
  parallel();
  auto end = chrono::system_clock::now();
  auto uend = clock();
  auto elapsed = chrono::duration_cast<chrono::milliseconds>(end - beg).count();
  fprintf(stderr, "elapsed: %.3f (%.3f) sec.\n", 
    elapsed / 1000.0, 
    double(uend - ubeg) / CLOCKS_PER_SEC
  );
}
0