QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#345174 | #4791. Movies | Kevin5307 | WA | 1ms | 3948kb | C++20 | 1.4kb | 2024-03-06 12:44:31 | 2024-03-06 12:44:31 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
using i128=__int128;
void die(string S){puts(S.c_str());exit(0);}
int n,k;
int a[100100],b[200200];
int c[100100];
int psum[300300];
int pos[300300];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
pos[a[i]]=i;
memcpy(c,a,sizeof(c));
sort(c+1,c+n+1);
for(int i=1;i<=k;i++)
{
cin>>b[i];
psum[b[i]]++;
}
for(int i=1;i<=n+k;i++)
psum[i]+=psum[i-1];
int ans=n+n;
for(int l=1;l<=n;l++)
for(int r=l;r<=n;r++)
{
if(r>l&&pos[c[r]]<pos[c[r-1]]) break;
int lc=l-1,rc=n-r;
int mc=n-(r-l+1);
int x=min(lc,rc);
lc-=x;
rc-=x;
if(psum[c[l]]>=lc&&psum[n+k]-psum[c[r]]>=rc&&psum[c[r]]-psum[c[l]]>=mc)
ans=min(ans,lc+rc+mc);
}
if(ans>k) die("-1");
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3948kb
input:
5 5 3 1 5 2 4 6 8 7 9 10
output:
-1
result:
wrong answer 1st numbers differ - expected: '4', found: '-1'