QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323304 | #4860. Longest Common Subsequence | alreadysolved | WA | 1064ms | 66604kb | C++17 | 831b | 2024-02-09 08:00:18 | 2024-02-09 08:00:19 |
Judging History
answer
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
ll modmul(vector<ll> v, ll mod) {
ll res = 1;
for (auto i : v)
res = (res * i) % mod;
return res;
}
ll f(ll x, ll a, ll b, ll c, ll p) {
return (modmul({ a, x, x }, p) + modmul({ b, x }, p) + c) % p;
}
int main() {
int T; scanf("%d", &T);
while (T--) {
ll n, m, p, x, a, b, c;
scanf("%lld %lld %lld %lld %lld %lld %lld", &n, &m, &p, &x, &a, &b, &c);
map<ll,int> mp;
for (int i = 1; i <= n; i++) {
x = f(x, a, b, c, p);
if (mp.count(x) == 0) mp[x] = i;
}
ll as = n + 1, at = m + 1;
for (int i = 1; i <= m; i++) {
x = f(x, a, b, c, p);
if (mp.count(x) == 1) {
as = mp[x]; at = i;
break;
}
}
as = min(n - as + 1, m - at + 1);
printf("%lld\n", as);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
2 4 3 1024 1 1 1 1 3 4 1024 0 0 0 0
output:
0 3
result:
ok 2 number(s): "0 3"
Test #2:
score: 0
Accepted
time: 1064ms
memory: 66604kb
input:
1 1000000 1000000 999999937 0 0 11 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 760ms
memory: 66368kb
input:
1 1000000 1000000 1000000000 0 0 2 1
output:
437492
result:
ok 1 number(s): "437492"
Test #4:
score: 0
Accepted
time: 30ms
memory: 3884kb
input:
1 1000000 1000000 1000000000 0 0 0 0
output:
1000000
result:
ok 1 number(s): "1000000"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 4104kb
input:
1000 3 1 6 0 5 3 4 12 1 3 2 0 2 2 2 10 1 0 0 0 0 8 1 1 0 0 0 0 5 10 1 0 0 0 0 3 3 9 0 8 2 7 7 2 5 0 4 2 4 2 2 3 1 2 2 1 13 17 4 3 3 3 3 6 9 6 0 4 5 3 5 21 9 1 6 2 0 5 2 8 6 0 4 1 21 7 10 5 3 6 7 23 11 2 1 0 0 1 14 3 10 5 4 6 3 3 33 8 0 7 3 0 2 4 5 4 0 2 0 43 3 9 2 6 8 4 10 10 4 3 2 0 1 16 32 2 1 1 1...
output:
1 1 2 1 5 2 2 2 13 6 5 2 7 11 3 3 2 3 10 16 2 15 3 1 1 12 12 11 2 1 15 4 2 7 1 7 2 15 2 6 3 1 1 16 1 2 9 9 0 0 1 1 2 0 5 1 6 6 1 5 3 1 6 2 7 16 13 4 4 4 3 5 12 2 8 7 1 8 6 11 4 1 5 4 6 5 2 3 3 7 3 6 4 2 8 4 14 8 6 1 15 1 2 4 3 5 7 3 1 2 3 1 4 1 2 2 2 10 0 2 3 12 4 2 1 25 9 12 1 1 1 2 6 1 7 1 3 1 7 1...
result:
wrong answer 21st numbers differ - expected: '3', found: '2'