結果
| 問題 |
No.2759 Take Pictures, Elements?
|
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2024-05-18 06:50:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 801 bytes |
| コンパイル時間 | 1,897 ms |
| コンパイル使用メモリ | 193,440 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:19:44 |
| 合計ジャッジ時間 | 2,360 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
void chmin(int&a, int b){if(a>b)a=b;}
int N,Q,A[1010],B[1010];
int dp[1010][1010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>Q;
for(int i=0;i<N;i++)cin>>A[i];
for(int i=0;i<=Q;i++)for(int j=0;j<=N;j++)dp[i][j]=1<<30;
dp[0][0]=0;
for(int i=0;i<Q;i++)
{
cin>>B[i];
int Lmin=1<<30;
for(int j=0;j<N;j++)
{
if(A[j]==B[i])chmin(dp[i+1][j],Lmin+j);
chmin(Lmin,dp[i][j]-j);
}
int Rmin=1<<30;
for(int j=N;j--;)
{
chmin(Rmin,dp[i][j]+j);
if(A[j]==B[i])chmin(dp[i+1][j],Rmin-j);
}
}
int ans=1<<30;
for(int i=0;i<N;i++)if(A[i]==B[Q-1])chmin(ans,dp[Q][i]);
cout<<ans<<endl;
}
nonon