粉福

· · 休闲·娱乐

50粉 Upd:2026/3/17

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

代码:

#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;
}