답안 #1081607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081607 2024-08-30T08:03:44 Z dong_gas 마술쇼 (APIO24_show) C++17
0 / 100
2 ms 820 KB
#include <bits/extc++.h>
#include "Alice.h"
#include "Bob.h"
#define all(v) v.begin(), v.end()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
using namespace __gnu_pbds;
template<class T> using PBDS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using multiPBDS = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<pint> Alice(){
    ll x = setN(5000);
    vector<pint> edges;
    for(int i=2;i<=5000;i++) edges.push_back({x%(i-1)+1,i});
    return edges;
}
#include <bits/extc++.h>
#include "Alice.h"
#include "Bob.h"
#define all(v) v.begin(), v.end()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
using namespace __gnu_pbds;
template<class T> using PBDS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using multiPBDS = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd(ll a, ll b)
{
	if(a==0) return b;
	if(b==0) return a;
	return gcd(b, a%b);
}

ll minv(ll a, ll b)
{
	if(a==0 && b==1) return 0;
	if(a==1) return 1;
	return b - minv(b%a, a) * b / a;
}

// x == A.first (mod A.second)
// x == B.first (mod B.second)
// returns solution as X == ans.first (mod ans.second)
// if no solution, returns (-1, -1)
// always a good idea to keep 0 <= ?.first < ?.second (for ? : A, B, ans)
pair<ll, ll> solve(pair<ll, ll> A, pair<ll, ll> B)
{
	if(A.second == -1 || B.second == -1) return make_pair(-1, -1);
	if(A.second == 1) return B;
	if(B.second == 1) return A;
	ll g = gcd(A.second, B.second); // gcd
	ll l = A.second * (B.second / g); // lcm
	if((B.first-A.first)%g!=0) return make_pair(-1, -1); // no solution case

	ll a = A.second / g;
	ll b = B.second / g;
	ll mul = (B.first-A.first) / g;
	mul = (mul * minv(a%b, b)) % b; // this is now t
	ll ret = (mul * A.second + A.first); // n_1 t + a_1
	ret %= l; ret = (ret + l) % l; // take modulos
	return make_pair(ret, l);
}

ll Bob(vector<pint> edges){
    vector<pll> a;
	for(auto& [u, v]:edges) {
        //v로 나눈 나머지가 u-1..
        a.push_back({u-1,v});
	}
	pll dap=a[0];
	for(ll i=1;i<a.size();i++) {
        dap=solve(dap,a[i]);
        if(dap.second>1e18) return dap.first;
	}
  	return dap.first;
}

Compilation message

Bob.cpp: In function 'll Bob(std::vector<std::pair<int, int> >)':
Bob.cpp:59:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(ll i=1;i<a.size();i++) {
      |             ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 820 KB Incorrect answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 820 KB Incorrect answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 820 KB Incorrect answer.
2 Halted 0 ms 0 KB -