Submission #1292384


Source Code Expand

#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 = 500000003;
    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 == 2);

    int h1, h2; scanf("%d%d", &h1, &h2);
    printf("%d\n", h1 - h2);
    return 0;
}

Submission Info

Submission Time
Task A - 積雪深差
User kimiyuki
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2422 Byte
Status AC
Exec Time 1230 ms
Memory 2304 KB

Compile Error

./Main.cpp: In function ‘void pthread_exit(void*)’:
./Main.cpp:38:1: warning: ‘noreturn’ function does return
 }
 ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:76:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     int h1, h2; scanf("%d%d", &h1, &h2);
                                        ^

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 20
Set Name Test Cases
all 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1221 ms 476 KB
00_sample_02.txt AC 1222 ms 352 KB
00_sample_03.txt AC 1228 ms 352 KB
test_01.txt AC 1219 ms 352 KB
test_02.txt AC 1228 ms 256 KB
test_03.txt AC 1227 ms 352 KB
test_04.txt AC 1229 ms 352 KB
test_05.txt AC 1225 ms 256 KB
test_06.txt AC 1225 ms 256 KB
test_07.txt AC 1218 ms 352 KB
test_08.txt AC 1228 ms 256 KB
test_09.txt AC 1225 ms 256 KB
test_10.txt AC 1227 ms 2304 KB
test_11.txt AC 1219 ms 256 KB
test_12.txt AC 1230 ms 352 KB
test_13.txt AC 1228 ms 352 KB
test_14.txt AC 1228 ms 352 KB
test_15.txt AC 1225 ms 256 KB
test_16.txt AC 1225 ms 256 KB
test_17.txt AC 1220 ms 352 KB