当前位置:首页 > 编程笔记 > 正文
已解决

Codeforces Round 848 (Div. 2)C

来自网友在路上 143843提问 提问时间:2023-09-24 16:53:52阅读次数: 43

最佳答案 问答题库438位专家为你答疑解惑

B. The Forbidden Permutation

一定要注意题目中说的是对于all i满足才算不好的,我们做的时候只要破坏一个i这个a就不算好的了,被这一点坑了,没注意到all。

#include <bits/stdc++.h>using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int p[N], a[N]; void run()
{	memset(p, 0, sizeof p);int n, m, d;	scanf("%d%d%d", &n, &m, &d);for(int i = 1; i <= n; ++ i){int x;	scanf("%d", &x);p[x] = i;}for(int i = 1; i <= m; ++ i)	scanf("%d", &a[i]);int ans = 1e9;for(int i = 1; i + 1 <= m; ++ i){if(p[a[i + 1]] < p[a[i]] || p[a[i + 1]] > p[a[i]] + d){cout << 0 << endl;return;}if(p[a[i + 1]] > p[a[i]])	ans = min(ans, p[a[i + 1]] - p[a[i]]);if(p[a[i + 1]] <= p[a[i]] + d)if(d + 2 <= n)	ans = min(ans, p[a[i]] + d + 1 - p[a[i + 1]]);}printf("%d\n", ans);
}int main()
{
//	freopen("1.in", "r", stdin);int t;cin >> t;while(t --)	run();	return 0;  
}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Codeforces Round 848 (Div. 2)C":http://eshow365.cn/6-12886-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!