結果
問題 | No.9000 Hello World! (テスト用) |
ユーザー | kimiyuki |
提出日時 | 2017-05-18 03:00:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,311 bytes |
コンパイル時間 | 724 ms |
コンパイル使用メモリ | 46,080 KB |
最終ジャッジ日時 | 2024-11-14 20:00:54 |
合計ジャッジ時間 | 1,103 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In constructor 'dynamic_library::dynamic_library(const std::string&)': main.cpp:15:37: error: invalid use of incomplete type 'const std::string' {aka 'const class std::__cxx11::basic_string<char>'} 15 | handle = __libc_dlopen_mode(path.c_str(), rtld_now); | ^~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iosfwd:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/std_thread.h:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/thread:43, from main.cpp:2: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stringfwd.h:72:11: note: declaration of 'std::string' {aka 'class std::__cxx11::basic_string<char>'} 72 | class basic_string; | ^~~~~~~~~~~~ main.cpp: In member function 'void* dynamic_library::operator()(const std::string&)': main.cpp:18:37: error: invalid use of incomplete type 'const std::string' {aka 'const class std::__cxx11::basic_string<char>'} 18 | return __libc_dlsym(handle, symbol.c_str()); | ^~~~~~ /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stringfwd.h:72:11: note: declaration of 'std::string' {aka 'class std::__cxx11::basic_string<char>'} 72 | class basic_string; | ^~~~~~~~~~~~ main.cpp: At global scope: main.cpp:24:44: error: no matching function for call to 'dynamic_library::dynamic_library(const char*&)' 24 | dynamic_library pthread_handle(pthread_path); | ^ main.cpp:13:5: note: candidate: 'dynamic_library::dynamic_library(const std::string&)' 13 | dynamic_library(string const & path) { | ^~~~~~~~~~~~~~~ main.cpp:13:36: note: no known conversion for argument 1 from 'const char*' to 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&
ソースコード
#include <cstdio> #include <thread> #include <cassert> using ll = long long; using namespace std; extern "C" { void *__libc_dlopen_mode(const char *x, int y); void *__libc_dlsym(void *x, const char *y); } struct dynamic_library { void *handle; dynamic_library(string const & path) { int rtld_now = 2; handle = __libc_dlopen_mode(path.c_str(), rtld_now); } void *operator () (string const & symbol) { return __libc_dlsym(handle, symbol.c_str()); } }; const char *pthread_path = "/usr/lib64/libpthread.so.0"; // yukicoder // const char *pthread_path = "/lib/x86_64-linux-gnu/libpthread.so.0"; // atcoder dynamic_library pthread_handle(pthread_path); extern "C" { int pthread_create (pthread_t *__restrict __newthread, const pthread_attr_t *__restrict __attr, void *(*__start_routine) (void *), void *__restrict __arg) { typedef decltype(pthread_create) (*type); static type ptr = (type)(pthread_handle("pthread_create")); return ptr(__newthread, __attr, __start_routine, __arg); } void pthread_exit (void *__retval) { typedef decltype(pthread_exit) (*type); static type ptr = (type)(pthread_handle("pthread_exit")); ptr(__retval); } int pthread_join (pthread_t __th, void **__thread_return) { typedef decltype(pthread_join) (*type); static type ptr = (type)(pthread_handle("pthread_join")); return ptr(__th, __thread_return); } int pthread_detach (pthread_t __th) { typedef decltype(pthread_detach) (*type); static type ptr = (type)(pthread_handle("pthread_detach")); return ptr(__th); } } constexpr int mod = 1e9+7; void func(int l, int r, int *result) { ll acc = 1; for (int i = l; i < r; ++ i) { acc = acc * i % mod; } *result = acc; } int main() { int n = 1000000005; int result[4]; constexpr int num_threads = 4; thread th[num_threads]; for (int i = 0; i < num_threads; ++ i) { int l = (n - 1) *(ll) i / num_threads + 1; int r = (n - 1) *(ll) (i+1) / num_threads + 1; th[i] = thread(func, l, r, &result[i]); } ll acc = 1; for (int i = 0; i < num_threads; ++ i) { th[i].join(); acc = acc * result[i] % mod; } assert (acc == 500000003); printf("Hello World!\n"); return 0; }