P1065 作业调度方案
一道傻逼模拟写了半个小时还wa了一次
我退役罢
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 20 + 5;
inline int read(){
char ch = getchar(); int x = 0;
while(!isdigit(ch)) ch = getchar();
while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x;
}
int N, M;
int a[MAXN * MAXN];
int idx[MAXN][MAXN], val[MAXN][MAXN];
int p[MAXN], ti[MAXN];
bool vis[MAXN][MAXN * MAXN];
inline bool ok(int &st, int &len, int &mac) {
for(int i = st; i <= st + len - 1; i++)
if(vis[mac][i]) return false;
for(int i = st; i <= st + len - 1; i++) vis[mac][i] = true;
return true;
}
int main(){
// freopen("p1065.in", "r", stdin);
cin>>M>>N;
for(int i = 1; i <= N * M; i++) a[i] = read();
for(int i = 1; i <= N; i++)
for(int j = 1; j <= M; j++) idx[i][j] = read();
for(int i = 1; i <= N; i++)
for(int j = 1; j <= M; j++) val[i][j] = read();
for(int i = 1; i <= N * M; i++) {
++p[a[i]]; int &t = ti[a[i]];
while(!ok(t, val[ a[i] ][ p[a[i]] ], idx[ a[i] ][ p[a[i]] ])) ++t;
t += val[ a[i] ][ p[a[i]] ];
}
int ans = 0;
for(int i = 1; i <= N; i++) ans = max(ans, ti[i]);
printf("%d\n", ans);
return 0;
}