답안 #1010597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010597 2024-06-29T08:24:56 Z sleepntsheep 마술쇼 (APIO24_show) C++17
100 / 100
1 ms 792 KB
#include <vector>
#include "Alice.h"

std::vector<std::pair<int,int>> Alice(){
    long long x = setN(1000);
    std::vector<std::pair<int, int > > T = {};
    for (int i = 2; i <= 1000; ++i)
        T.emplace_back( (x % (i - 1) + 1), i);
    return T;
}
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include "Bob.h"

using ii = __int128;

template <typename T>
std::array<T, 3> exgcd(T x, T y) {
    if (y == 0)
        return {1, 0, x};
    auto [s1, t1, d] = exgcd(y, x % y);
    T s, t;
    s = t1;
    t = s1 - t1 * (x / y);
    return {s, t, d};
}
ii lcm(long long x, long long y) {
    auto [_, __, d] = exgcd(x, y);
    return (x / d) * y;
}

/*
 *
 * CRT
 *
 *
 * x = a1 (mod n1)
 * x = a2 (mod n2)
 *
 * x = a1 + k1n1
 *   = a2 + k2n2
 *
 * k2n2 - k1n1 = a1 - a2
 *
 * d = gcd(n1, n2)
 * let e = (a1 - a2) / d
 *
 * find s, t
 * such that
 *
 * n1s + n2t = d
 *
 * then x = a1 + n1 (se)
 *        = a2 + n2 (te)
 *
 * and new equation x = (sth) (mod lcm(n1, n2))
 *
 */

inline ii normalize(ii x, ii mod) { x %= mod; if (x < 0) x += mod; return x; }

long long Bob(std::vector<std::pair<int,int>> T) {
    ii n1 = 1, a1 = 0;

    for (auto [u, v] : T) {
        if (u > v) std::swap(u, v);

        --u;
        --v;
        /* x = u (mod v) */

        ii n2 = v, a2 = u;

        auto [s1, _, d] = exgcd(n1, n2);

        a1 = normalize(a1 + s1 * (a2 - a1) / d % (n2 / d) * n1, n1 * n2 / d);

        n1 = lcm(n1, n2);

        if (n1 > 1e18)
            return a1;
    }

    return (long long)a1;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 780 KB Correct.
2 Correct 0 ms 788 KB Correct.
3 Correct 1 ms 788 KB Correct.
4 Correct 1 ms 780 KB Correct.
5 Correct 1 ms 780 KB Correct.
6 Correct 0 ms 780 KB Correct.
7 Correct 0 ms 780 KB Correct.
8 Correct 1 ms 776 KB Correct.
9 Correct 0 ms 780 KB Correct.
10 Correct 0 ms 780 KB Correct.
11 Correct 1 ms 788 KB Correct.
12 Correct 0 ms 788 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 780 KB Correct.
2 Correct 0 ms 788 KB Correct.
3 Correct 1 ms 788 KB Correct.
4 Correct 1 ms 780 KB Correct.
5 Correct 1 ms 780 KB Correct.
6 Correct 0 ms 780 KB Correct.
7 Correct 0 ms 780 KB Correct.
8 Correct 1 ms 776 KB Correct.
9 Correct 0 ms 780 KB Correct.
10 Correct 0 ms 780 KB Correct.
11 Correct 1 ms 788 KB Correct.
12 Correct 0 ms 788 KB Correct.
13 Correct 0 ms 780 KB Correct.
14 Correct 0 ms 780 KB Correct.
15 Correct 1 ms 780 KB Correct.
16 Correct 0 ms 788 KB Correct.
17 Correct 1 ms 780 KB Correct.
18 Correct 0 ms 780 KB Correct.
19 Correct 1 ms 780 KB Correct.
20 Correct 0 ms 788 KB Correct.
21 Correct 1 ms 780 KB Correct.
22 Correct 1 ms 780 KB Correct.
23 Correct 0 ms 780 KB Correct.
24 Correct 0 ms 780 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 780 KB Correct.
2 Correct 0 ms 788 KB Correct.
3 Correct 1 ms 788 KB Correct.
4 Correct 1 ms 780 KB Correct.
5 Correct 1 ms 780 KB Correct.
6 Correct 0 ms 780 KB Correct.
7 Correct 0 ms 780 KB Correct.
8 Correct 1 ms 776 KB Correct.
9 Correct 0 ms 780 KB Correct.
10 Correct 0 ms 780 KB Correct.
11 Correct 1 ms 788 KB Correct.
12 Correct 0 ms 788 KB Correct.
13 Correct 0 ms 780 KB Correct.
14 Correct 0 ms 780 KB Correct.
15 Correct 1 ms 780 KB Correct.
16 Correct 0 ms 788 KB Correct.
17 Correct 1 ms 780 KB Correct.
18 Correct 0 ms 780 KB Correct.
19 Correct 1 ms 780 KB Correct.
20 Correct 0 ms 788 KB Correct.
21 Correct 1 ms 780 KB Correct.
22 Correct 1 ms 780 KB Correct.
23 Correct 0 ms 780 KB Correct.
24 Correct 0 ms 780 KB Correct.
25 Correct 0 ms 780 KB Correct.
26 Correct 0 ms 780 KB Correct.
27 Correct 0 ms 780 KB Correct.
28 Correct 0 ms 780 KB Correct.
29 Correct 0 ms 780 KB Correct.
30 Correct 1 ms 780 KB Correct.
31 Correct 0 ms 780 KB Correct.
32 Correct 0 ms 780 KB Correct.
33 Correct 1 ms 780 KB Correct.
34 Correct 1 ms 780 KB Correct.
35 Correct 0 ms 780 KB Correct.
36 Correct 0 ms 788 KB Correct.
37 Correct 0 ms 792 KB Correct.
38 Correct 0 ms 780 KB Correct.
39 Correct 0 ms 780 KB Correct.
40 Correct 0 ms 780 KB Correct.
41 Correct 0 ms 784 KB Correct.
42 Correct 0 ms 780 KB Correct.
43 Correct 1 ms 780 KB Correct.
44 Correct 1 ms 792 KB Correct.