제출 #1349091

#제출 시각아이디문제언어결과실행 시간메모리
1349091limits마술쇼 (APIO24_show)C++20
0 / 100
2 ms352 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define f0r(i, n) for (auto i = 0; i < (n); ++i)
#define fnr(i, n, k) for (auto i = (n); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second
#define ctn(x) cout << x << '\n'
#define forl(a, l) for (auto a : l)
#define ctl(l) for (auto &a : (l)) cout << a << ' '; cout << endl;
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define pq priority_queue

template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using Adj = V<vi>;
using vvi = V<vi>;

#include "Alice.h"

const int N = 615;

V<pi> Alice() {
	ll x = setN(N);
	V<pi> edl;
	fnr(m, 1, N) {
		int r = x % m;
		edl.pb({ m, r == 0 ? N : r });
	}

	return edl;
}
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define f0r(i, n) for (auto i = 0; i < (n); ++i)
#define fnr(i, n, k) for (auto i = (n); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second
#define ctn(x) cout << x << '\n'
#define forl(a, l) for (auto a : l)
#define ctl(l) for (auto &a : (l)) cout << a << ' '; cout << endl;
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define pq priority_queue

template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using Adj = V<vi>;
using vvi = V<vi>;

#include "Bob.h"

const int N = 615;
const ll M = 1e18;

ll egcd(ll a, ll b, ll &x, ll &y) {
	if (b == 0) {
		x = 1; y = 0;
		return a;
	}
	ll x1, y1;
	ll g = egcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - (a / b) * y1;
	return g;
}

pair<ll,ll> crt(ll a, ll b, ll c, ll d) {
	ll x, y;
	ll g = egcd(b, d, x, y);

	ll lcm = b / g * d;

	ll k = (c - a) / g;
	k = (k * x) % (d / g);

	if (k < 0) k += (d / g);

	ll res = a + b * k;
	res = (res % lcm + lcm) % lcm;

	return {res, lcm};
}

ll Bob(V<pi> V) {
	vi mod(N+1, -1);
	ll a = 0, l = 1;
	for (auto &[x, y]: V) {
		if (x == N) x = 0;
		if (y == N) y = 0;
		if (x > y) swap(x, y);
		mod[y] = x;
		auto [a2, l2] = crt(a, l, mod[y], y);
		a = a2, l = l2;
		if (l >= M) return a;
	}


	return a;

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...