結果
| 問題 |
No.2759 Take Pictures, Elements?
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2024-05-17 21:27:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 141 ms / 2,000 ms |
| コード長 | 1,210 bytes |
| コンパイル時間 | 1,960 ms |
| コンパイル使用メモリ | 202,068 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-20 13:16:30 |
| 合計ジャッジ時間 | 3,147 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=1005,INF=15<<26;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
int dp[MAX][MAX];
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N,Q;cin>>N>>Q;
vector<int> A(N),B(Q);
for(int i=0;i<N;i++) cin>>A[i];
for(int i=0;i<Q;i++) cin>>B[i];
for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) dp[i][j]=INF;
dp[0][0]=0;
for(int i=0;i<Q;i++){
for(int j=0;j<N;j++){
if(dp[i][j]==INF) continue;
for(int k=0;k<N;k++){
if(A[k]==B[i]) chmin(dp[i+1][k],dp[i][j]+abs(j-k));
}
}
}
int ans=INF;
for(int j=0;j<N;j++) chmin(ans,dp[Q][j]);
cout<<ans<<endl;
}
Rubikun