답안 #14268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14268 2015-05-09T13:25:12 Z tjdals1865 토마토 (KOI13_tomato) C
0 / 16
0 ms 8904 KB
#include <stdio.h>

#include <stdlib.h>

int n,m,i,j,tomato[1001][1001],day=0,tomatocnt=0,rec[1001][1001],empty;
void input(){
    FILE *fin=fopen("input.txt","r");
    fscanf(fin,"%d %d",&m,&n);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            fscanf(fin,"%d",&tomato[i][j]);
            if(tomato[i][j]==-1) empty++;
            if(tomato[i][j]==1) tomatocnt++;
        }
    }
    fclose(fin);
}
void process(){
    while(day<=(n*m-empty)){
        if(tomatocnt==n*m-empty) break;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                if(tomato[i][j]==1 && rec[i][j]!=(-1)*day-1){
                    if(tomato[i-1][j]==0 && i-1>=0){
                        tomatocnt++;
                        tomato[i-1][j]=1;
                        rec[i][j]=(-1)*day-1;
                    }
                     if(tomato[i][j-1]==0 && j-1>=0){
                        tomatocnt++;
                        tomato[i][j-1]=1;
                        rec[i][j]=(-1)*day-1;
                    }
                    if(tomato[i+1][j]==0 && i+1<n){
                        tomatocnt++;
                        tomato[i+1][j]=1;
                        rec[i][j]=(-1)*day-1;
                    }
                    if(tomato[i][j+1]==0 && j+1<m){
                        tomatocnt++;
                        tomato[i][j+1]=1;
                        rec[i][j]=(-1)*day-1;
                    }
                }
            }
        }
        day++;
    }
}
void output(){
    FILE *fout=fopen("output.txt","w");
    if(day==(n*m-empty+1)) fprintf(fout,"-1");
    else fprintf(fout,"%d",day);
    fclose(fout);
}
int main(void){
    input();
    process();
    output();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 8904 KB open (syscall #2) was called by the program (disallowed syscall)
2 Halted 0 ms 0 KB -