QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#343549 | #3058. Assignment Algorithm | PetroTarnavskyi# | WA | 0ms | 3728kb | C++20 | 1.5kb | 2024-03-02 18:38:30 | 2024-03-02 18:38:30 |
Judging History
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;
}
詳細信息
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'