QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#343549#3058. Assignment AlgorithmPetroTarnavskyi#WA 0ms3728kbC++201.5kb2024-03-02 18:38:302024-03-02 18:38:30

Judging History

你现在查看的是最新测评结果

  • [2024-03-02 18:38:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3728kb
  • [2024-03-02 18:38:30]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

int mult(int a, int b, int mod)
{
	return (LL)a * b % mod;
}
int binpow(int a, int n, int mod)
{
	int res = 1;
	while(n)
	{
		if(n & 1)
			res = mult(res, a, mod);
		a = mult(a, a, mod);
		n /= 2;
	}
	return res;
}

PII solve()
{
	LL n, p, r;
	cin >> n >> p >> r;	
	if(n >= 2 * p)
	{
		if(r != 0)
			return {-1, -1};
		else
			return {p, p - 1};
	}
	if(n >= p)
	{
		if(r != 0)
		{
			LL ost = 1;
			FOR(i, 1, n + 1)
				if(i != p)
					ost = mult(ost, i, p);
			assert(ost != 0);
			ost = mult(r, binpow(ost, p - 2, p), p);
			
			return {p, ost};
		}
		else
		{
			if(n > p)
				return {p + 1, p};
			if(p == 2)
				return {-1, -1};
			return {2, 1};
		}
	}
	//n < p
	if(r == 0)
		return {-1, -1};
	int ifact = 1;
	FOR(i, 1, n + 1)
		ifact = mult(ifact, i, p);
	ifact = binpow(ifact, p - 2, p);
	
	FOR(i, 1, n + 1)
	{
		int nval = mult(i, ifact, p);
		nval = mult(nval, r, p);
		
		if(nval < i)
			return {i, nval};
	}
	return {-1, -1};
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	auto ans = solve();
	cout << ans.F << " " << ans.S << "\n";
	
	
	
	return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3728kb

input:

2 17
...........
---.#--.---
...........
---.---.---
...........

output:

-1 -1

result:

wrong answer 1st lines differ - expected: '...........', found: '-1 -1'