跳到正文

休闲·娱乐

粉福

__ZKL__约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年3月11日
收录
2026年3月11日
更新
2026年10月20日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

50粉 Upd:2026/3/17

爆码风,题目:https://www.luogu.com.cn/problem/P1065

代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int m, n, a[400], ans, f[20], g[20], l;
bool vis[20][100000];
struct node{
	int h, time;
}p[20][20];
signed main(){
	cin >> m >> n;
	for(int i = 1; i <= m * n; i++)cin >> a[i];
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> p[i][j].h;
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> p[i][j].time;
		}
	}
	for(int i = 1; i <= m * n; i++){
		int tmp = a[i];
		f[tmp]++;
		int h = p[tmp][f[tmp]].h, k = p[tmp][f[tmp]].time, cnt = 0;
		for(l = g[tmp] + 1;; l++){
			if(vis[h][l] == 0)cnt++;
			else cnt = 0;
			if(cnt == k){
				if(l > ans)ans = l;
				for(int j = l - k + 1; j <= l; j++)vis[h][j] = 1;
				g[tmp] = l;
				break;
			}
		}
	}
	cout << ans;
	return 0;
}
原文