Submission #4666

# Submission time Handle Problem Language Result Execution time Memory
4666 2013-12-02T14:55:47 Z tncks0121 파일 삭제 (GA3_delete) C++
Compilation error
0 ms 0 KB
#include <vector> 
#include <algorithm> 
  
using namespace std; 
const int SZ = 3005; 
const int INF = 987654321; 
  
namespace sttic { 
    int N, M, K; 
}; 
  
struct Intv { 
    int l, r; 
    Intv(): l(0), r(0) { } 
    Intv(int l, int r): l(l), r(r) { } 
}; 
  
using namespace sttic; 
  
vector<int> Gph[SZ]; 
vector<int> I[SZ]; 
int Table[SZ][SZ]; 
  
int file; 
  
void getInterval (int node){ 
    int i; 
    if(node >= M) { 
        ++file; 
        I[file].push_back(file);
    }else { 
        int st = file + 1; 
        for(i = 0; i < Gph[node].size(); i++){ 
            int g = Gph[node][i]; 
            getInterval(g); 
        } 
        if(st <= file) I[file].push_back(st);
    } 
} 
  
int DeletePlan( int N, int M, int K, int *A, int *B) { 
    int i, j; 
    sttic::N = N; sttic::M = M; sttic::K = 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); 
  
    getInterval(0); 
  
    for(i = 0; i <= N; i++){ 
        for(j = 1; j <= K; j++) Table[i][j] = INF; 
    } 

	/*
  
    for(i = 0; i < I.size(); i++){ 
        Intv &d = I[i]; int len = d.r - d.l + 1; 
        for(j = 1; j <= K && j <= d.r; j++){ 
            int &t = Table[d.r][j]; 
            t = min(t, Table[d.r - 1][j]); 
            if(j >= len) t = min(t, Table[d.l - 1][j - len] + 1); 
        } 
    }*/

	/*for(j = 1; j <= K; j++) {
		for(i = 0; i < I.size(); i++) {
			Intv &d = I[i]; int len = d.r - d.l + 1;
			int &t = Table[d.r][j];
			t = min(t, Table[d.l - 1][j]);
            if(j >= len) t = min(t, Table[d.l - 1][j - len] + 1); 
		}
	}*/

	for(j = 1; j <= K; j++) {
		for(i = 1; i <= N; i++) {
			for(int k = 0; k < I[i].size(); k++) {
				int l = I[i][k];
				int len = i - l + 1;
				int &t = Table[i][j];
				t = min(t, Table[l - 1][j]);
				if(j >= len) t = min(t, Table[l - 1][j - len] + 1);
			}
		}
	}
  
    return Table[N][K]; 
}
#include <stdio.h> 
#include <assert.h> 
#include <malloc.h> 
    
    
int DeletePlan( int N, int M, int K, int *A, int *B); 
    
int main(){ 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

int N, M, K; 
int *A, *B; 
    int i, tmp; 
        
    tmp = scanf("%d%d%d", &N, &M, &K); 
    assert(tmp == 3); 
    
    A = (int*) malloc( sizeof(int) * N ); 
    for(i = 0; i < N; i++) { 
        tmp = scanf("%d", &A[i]); 
        assert(tmp == 1); 
    } 
        
    B = (int*) malloc( sizeof(int) * M ); 
    for(i = 0; i < M; i++) { 
        tmp = scanf("%d", &B[i]); 
        assert(tmp == 1); 
    } 
    
    printf("%d", DeletePlan(N, M, K, A, B) ); 
    return 0; 
}

Compilation message

delete.cpp: In function 'void getInterval(int)':
delete.cpp:33:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
delete.cpp: In function 'int DeletePlan(int, int, int, int*, int*)':
delete.cpp:76:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
delete.cpp: In function 'int main()':
delete.cpp:96:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
delete.cpp:97:36: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
/tmp/cc10cJ9s.o: In function `main':
delete.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cccHXHDo.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: ld returned 1 exit status