# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
988 | testtest | 파일 삭제 (GA3_delete) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <algorithm>
using namespace std;
const int SZ = 1005;
const int INF = 987654321;
vector<int> Gph[SZ];
vector<int> Que;
int Table[SZ][SZ], Tmp[SZ];
int Parent[SZ], Size[SZ];
int DeletePlan( int N, int M, int K, int *A, int *B) {
int i, j, k;
for(i = 0; i < N; i++) Gph[ A[i] ].push_back(i + M);
for(i = 1; i < M; i++) Gph[ B[i] ].push_back(i);
int fr = 0, i; Que.push_back(0);
while(fr < Que.size()){
int n = Que[fr++];
for(i = 0; i < Gph[n].size(); i++) {
int g = Gph[n][i];
Que.push_back(g); Parent[g] = n;
}
}
for(i = 0; i < N + M; i++) {
Table[i][1] = 1; if(i >= M) Size[i] = 1;
for(j = 2; j <= N; j++) Table[i][j] = INF;
}
for(i = (int)Que.size() - 1; i > 0; i--){
int n = Que[i], p = Parent[n];
Size[p] += Size[n]; Table[n][Size[n]] = 1;
for(j = 1; j <= Size[p]; j++) Tmp[j] = Table[p][j];
for(j = 1; j <= Size[p]; j++){
for(k = j; k <= Size[p]; k++) Table[p][k] = min(Table[p][k], Tmp[k - j] + Table[n][j]);
}
}
int ret = INF;
for(i = 0; i < N + M; i++) ret = min(ret, Table[i][K]);
return ret;
}