QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#427872 | #8771. Dihedral Group | ucup-team135# | TL | 1ms | 3800kb | C++20 | 1.6kb | 2024-06-01 16:16:43 | 2024-06-01 16:16:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#define debugv(v) do {cout<< #v <<" : {"; for(int i=0;i<v.size();++i) {cout << v[i];if(i+1!=v.size()) cout << ","; }cout <<"}"<< endl;} while(0)
#else
#define debug(...)
#define debugv(v)
#endif
#ifdef LOCAL
#define __int128 long long
#endif // LOCAL
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*1LL*u)%p;} else {int u=po(a,b-1);return (a*1LL*u)%p;}}
int inv(int x) {return po(x,p-2);}
mt19937 rnd;
int n,m;
map<int,int> pos;
bool check(vector<int> &a,int id)
{
int val=a[id];
for(int i=id;i<id+m;++i)
{
if(a[i]!=(val+i-id)%n)
{
return false;
}
}
return true;
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;++i) {int x;cin>>x;pos[x]=i;}
vector<int> a(m);for(int i=0;i<m;++i) {cin>>a[i];a[i]=pos[a[i]];}
set<int> a1;for(int x:a) a1.insert(x);
if(a1.size()!=a.size())
{
cout<<0;return 0;
}
bool ok=0;
if(m<n)
{
ok=check(a,0);
reverse(all(a));
ok=(ok || check(a,0));
}
else
{
for(int i=0;i<n;++i) a.app(a[a.size()-n]);
for(int i=0;i<n;++i) if(check(a,i)) ok=true;
reverse(all(a));
for(int i=0;i<n;++i) if(check(a,i)) ok=true;
}
cout<<ok;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
3 3 1 2 3 1 3 2
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
3 1 1 2 3 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 2 1 2 3 4 1 3
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
4 4 1 2 3 4 2 3 4 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
4 4 1 2 3 4 3 2 1 4
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
5 3 1 3 5 4 2 2 1 3
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
5 4 1 3 5 4 2 2 1 5 3
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
1 1 1 1
output:
1
result:
ok single line: '1'
Test #9:
score: -100
Time Limit Exceeded
input:
50000 50000 22577 42400 21546 3302 14673 38530 22117 34658 9767 8284 18979 21312 30964 13861 9502 17302 9772 23092 18502 26861 33431 46434 42862 33662 16736 26383 42119 18487 6112 34272 40503 9340 36859 22828 35809 1442 37730 28378 12422 12305 26736 32865 691 29405 7395 24658 20995 40821 23979 15723...