QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252299 | #4860. Longest Common Subsequence | JerryBlack_ZJNU | WA | 1433ms | 81112kb | C++20 | 1.3kb | 2023-11-15 17:50:10 | 2023-11-15 17:50:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define fi first
#define se second
#define lowbit(x) (x&(-x))
const int mod=998244353;
const double eps=1e-12;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
#define popcnt __builtin_popcount
int dcmp(double x){if(fabs(x)<eps)return 0;return x>0?1:-1;}
template<typename T>inline int tomax(T&a,T b){if(b>a){a=b;return 1;}return 0;}
template<typename T>inline int tomin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
// mt19937 rnd(random_device{}());
// uniform_int_distribution<int>dist(0,1000);
#define int ll
void solve()
{
int n,m,p,x,a,b,c;
cin>>n>>m>>p>>x>>a>>b>>c;
vector<int>A(n+1),B(m+1);
map<int,int>mp;
for(int i=1;i<=n;i++)
{
x=(a*x%p*x%p+b*x%p+c)%p;
A[i]=x;
if(!mp.count(A[i]))mp[A[i]]=i;
}
for(int i=1;i<=m;i++)
{
x=(a*x%p*x%p+b*x%p+c)%p;
B[i]=x;
if(mp.count(B[i]))
{
cout<<min(m-i+1,n-mp[B[i]]+1)<<endl;
return;
}
}
cout<<0<<endl;
}
/*
*/
#undef int
int main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
// cout<<fixed<<setprecision(15);
int _;cin>>_;while(_--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3376kb
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: 1433ms
memory: 81112kb
input:
1 1000000 1000000 999999937 0 0 11 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 926ms
memory: 81092kb
input:
1 1000000 1000000 1000000000 0 0 2 1
output:
437492
result:
ok 1 number(s): "437492"
Test #4:
score: 0
Accepted
time: 23ms
memory: 18572kb
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: 3492kb
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'