結果
| 問題 |
No.2759 Take Pictures, Elements?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-17 21:30:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 687 bytes |
| コンパイル時間 | 428 ms |
| コンパイル使用メモリ | 65,044 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:16:31 |
| 合計ジャッジ時間 | 1,213 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include<iostream>
#include<cassert>
using namespace std;
int N,Q;
int A[1010];
int dist[1010];
int tmp[1010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>Q;
for(int i=0;i<N;i++)
{
cin>>A[i];
dist[i]=1e9;
}
dist[0]=0;
for(int i=0;i<Q;i++)
{
int b;cin>>b;
for(int i=0;i<N;i++)
{
tmp[i]=dist[i];
dist[i]=1e9;
}
{
int L=1e9;
for(int i=0;i<N;i++)
{
L++;
L=min(L,tmp[i]);
if(A[i]==b)dist[i]=min(dist[i],L);
}
}
{
int R=1e9;
for(int i=N;i--;)
{
R++;
R=min(R,tmp[i]);
if(A[i]==b)dist[i]=min(dist[i],R);
}
}
}
int ans=1e9;
for(int i=0;i<N;i++)ans=min(ans,dist[i]);
cout<<ans<<endl;
}