QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#651525 | #8771. Dihedral Group | yzkkai# | WA | 1ms | 3876kb | C++20 | 1.2kb | 2024-10-18 17:47:21 | 2024-10-18 17:47:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using LL = long long;
using pii = pair<int, int>;
#define sz(x) (signed)size(x)
vector<int> kmp(vector<int>& s) {
int n = sz(s);
vector<int> pi(n);
for (int i = 1, j = 0; i < n; ++i) {
while (j && s[i] != s[j]) j = pi[j - 1];
if (s[i] == s[j]) ++j;
pi[i] = j;
}
return pi;
}
void solve () {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int& i : a)
cin >> i;
for (int& i : b)
cin >> i;
vector<int> c = a;
for (int i = 0; i < n; ++i)
c.push_back(a[i]);
c.push_back(-1);
for (int i = 0; i < m; ++i)
c.push_back(b[i]);
bool f = 0;
vector<int> pi = kmp(c);
f |= *max_element(pi.begin(), pi.end()) == m;
reverse(a.begin(), a.end());
c.clear();
for (int t = 0; t <= 1; ++t)
for (int i = 0; i < n; ++i)
c.push_back(a[i]);
c.push_back(-1);
for (int i = 0; i < m; ++i)
c.push_back(b[i]);
f |= *max_element(pi.begin(), pi.end()) == m;
cout << f << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3876kb
input:
3 3 1 2 3 1 3 2
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
3 1 1 2 3 1
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'