답안 #1016838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016838 2024-07-08T13:09:50 Z NValchanov 마술쇼 (APIO24_show) C++17
100 / 100
2 ms 1068 KB
#include <bits/stdc++.h>
#include "Alice.h"
 
using namespace std;
 
vector<pair<int,int>> Alice()
{
    int N=5000;
    long long x = setN(N);
    vector < pair < int, int > > edges;
  
    for (int i = 1; i < N; i++) 
      edges.push_back({x % i + 1, i + 1});
  
    return edges;
}
#include <bits/stdc++.h>
#include "Bob.h"
 
#define endl '\n'
 
using namespace std;
 
typedef __int128_t ll;
 
/// EXTENDED GCD :(
 
pair < ll, pair < ll, ll > > extgcd(ll a, ll b)
{
    ll x = 1;
    ll y = 0;
    
    while(b)
    {
        ll tmp = a / b;
        a -= (tmp * b);
        x -= (tmp * y);
        swap(a, b);
        swap(x, y);
    }
 
    return {a, {x, y}};
}
 
long long Bob(vector < pair < int, int > > edges)
{
 
    /// CRT
 
    ll l = 0;
    ll ans = 0;
 
    for(pair < int, int > e : edges)
    {
        if(l >= 1e18)
            break;
 
        ll u = e.first;
        ll v = e.second;
 
        if(u > v)
            swap(u, v);
 
        u--;
        v--;
 
        if(ans == 0)
        {
            ans = u;
            l = v;
            continue;
        }
 
        pair < ll, pair < ll , ll > > g = extgcd(l, v);
 
        ll d = g.first;
        ll x = g.second.first;
        ll y = g.second.second;
 
        ans = ans + (x * (u - ans) / d) % (v / d) * l;
        l = l * v / d;
        ans = (ans % l + l) % l;
    }
 
    return ans;
}

Compilation message

Bob.cpp: In function 'long long int Bob(std::vector<std::pair<int, int> >)':
Bob.cpp:62:12: warning: unused variable 'y' [-Wunused-variable]
   62 |         ll y = g.second.second;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 820 KB Correct.
2 Correct 1 ms 820 KB Correct.
3 Correct 2 ms 820 KB Correct.
4 Correct 1 ms 828 KB Correct.
5 Correct 2 ms 940 KB Correct.
6 Correct 2 ms 820 KB Correct.
7 Correct 2 ms 820 KB Correct.
8 Correct 2 ms 832 KB Correct.
9 Correct 1 ms 820 KB Correct.
10 Correct 1 ms 820 KB Correct.
11 Correct 2 ms 820 KB Correct.
12 Correct 2 ms 828 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 820 KB Correct.
2 Correct 1 ms 820 KB Correct.
3 Correct 2 ms 820 KB Correct.
4 Correct 1 ms 828 KB Correct.
5 Correct 2 ms 940 KB Correct.
6 Correct 2 ms 820 KB Correct.
7 Correct 2 ms 820 KB Correct.
8 Correct 2 ms 832 KB Correct.
9 Correct 1 ms 820 KB Correct.
10 Correct 1 ms 820 KB Correct.
11 Correct 2 ms 820 KB Correct.
12 Correct 2 ms 828 KB Correct.
13 Correct 2 ms 1068 KB Correct.
14 Correct 1 ms 836 KB Correct.
15 Correct 1 ms 820 KB Correct.
16 Correct 2 ms 832 KB Correct.
17 Correct 1 ms 820 KB Correct.
18 Correct 2 ms 832 KB Correct.
19 Correct 1 ms 816 KB Correct.
20 Correct 1 ms 820 KB Correct.
21 Correct 1 ms 832 KB Correct.
22 Correct 2 ms 820 KB Correct.
23 Correct 2 ms 820 KB Correct.
24 Correct 1 ms 832 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 820 KB Correct.
2 Correct 1 ms 820 KB Correct.
3 Correct 2 ms 820 KB Correct.
4 Correct 1 ms 828 KB Correct.
5 Correct 2 ms 940 KB Correct.
6 Correct 2 ms 820 KB Correct.
7 Correct 2 ms 820 KB Correct.
8 Correct 2 ms 832 KB Correct.
9 Correct 1 ms 820 KB Correct.
10 Correct 1 ms 820 KB Correct.
11 Correct 2 ms 820 KB Correct.
12 Correct 2 ms 828 KB Correct.
13 Correct 2 ms 1068 KB Correct.
14 Correct 1 ms 836 KB Correct.
15 Correct 1 ms 820 KB Correct.
16 Correct 2 ms 832 KB Correct.
17 Correct 1 ms 820 KB Correct.
18 Correct 2 ms 832 KB Correct.
19 Correct 1 ms 816 KB Correct.
20 Correct 1 ms 820 KB Correct.
21 Correct 1 ms 832 KB Correct.
22 Correct 2 ms 820 KB Correct.
23 Correct 2 ms 820 KB Correct.
24 Correct 1 ms 832 KB Correct.
25 Correct 1 ms 816 KB Correct.
26 Correct 2 ms 820 KB Correct.
27 Correct 2 ms 820 KB Correct.
28 Correct 2 ms 820 KB Correct.
29 Correct 2 ms 820 KB Correct.
30 Correct 1 ms 820 KB Correct.
31 Correct 2 ms 824 KB Correct.
32 Correct 1 ms 828 KB Correct.
33 Correct 1 ms 820 KB Correct.
34 Correct 1 ms 820 KB Correct.
35 Correct 1 ms 828 KB Correct.
36 Correct 2 ms 820 KB Correct.
37 Correct 1 ms 820 KB Correct.
38 Correct 2 ms 820 KB Correct.
39 Correct 1 ms 824 KB Correct.
40 Correct 1 ms 828 KB Correct.
41 Correct 1 ms 828 KB Correct.
42 Correct 1 ms 832 KB Correct.
43 Correct 1 ms 820 KB Correct.
44 Correct 2 ms 820 KB Correct.