# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132020 | Vardanyan | Matching (CEOI11_mat) | C++14 | 2040 ms | 31440 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000*1000+5;
int a[N];
int b[N];
int pos[N];
int main(){
ios_base::sync_with_stdio(false);
int n,m;
cin>>n>>m;
for(int i = 1;i<=n;i++){
cin>>a[i];
pos[i] = a[i];
}
for(int i = 1;i<=m;i++) cin>>b[i];
vector<int> ans;
set<int> ms;
for(int i = 1;i<=n;i++) ms.insert(b[i]);
for(int i = 1;i<=m;i++){
if(i+n-1>m) break;
int nax = 0;
bool f = true;
if(*(ms.begin()) == b[pos[1]+i-1] && *(++ms.begin()) == b[pos[2]+i-1] && *(--ms.end()) == b[pos[n]+i-1]){
for(int j = 1;j<=n;j++){
int x = pos[j];
if(b[x+i-1]<nax){
f = false;
break;
}
nax = b[x+i-1];
}
}
else f = false;
if(f) ans.push_back(i);
ms.erase(ms.find(b[i]));
ms.insert(b[i+n]);
}
cout<<ans.size()<<endl;
for(int i = 0;i<ans.size();i++) cout<<ans[i]<<" ";
cout<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |