이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <fstream>
using namespace std;
int tomato[1000][1000];
int Temp_tomato[1000][1000];
int main()
{
int M = 2,N = 2;
int Riped = 0;
int notRiped = 0;
ifstream inputs("input.txt");
ofstream outputs("output.txt");
inputs>>M;
inputs>>N;
for (int i = 0 ; i < N; i++){
for (int j = 0 ; j < M; j++){
tomato[i][j] = 0;
Temp_tomato[i][j] = 0;
}
}
for (int i = 0 ; i < N; i++){
for (int j = 0 ; j < M; j++){
inputs>>tomato[i][j];
if (tomato[i][j] == 1)Riped++;
if (tomato[i][j] == -1)notRiped++;
}
}
inputs.close();
if (Riped == M * N - notRiped){
outputs<<0;
outputs.close();
return 0;
}
if (Riped == 0){
outputs<<-1;
outputs.close();
return 0;
}
int Delta = 0;
int Date = -1;
while (Riped != Delta){
Delta = Riped;
Date++;
for (int i = 0; i < N; i++){
for (int j = 0 ;j < M; j++){
if (tomato[i][j] == 1){
if (i-1 >= 0)if(tomato[i-1][j] == 0)Temp_tomato[i-1][j] = 1;
if (i+1 < N )if( tomato[i+1][j] == 0)Temp_tomato[i+1][j] = 1;
if (j-1 >= 0 )if( tomato[i][j-1] == 0)Temp_tomato[i][j-1] = 1;
if (j+1 < M )if( tomato[i][j+1] == 0)Temp_tomato[i][j+1] = 1;
}
}
}
for (int i = 0; i < N; i++){
for (int j = 0 ;j < M; j++){
if (Temp_tomato[i][j] == 1){
tomato[i][j] = 1;
Riped++;
Temp_tomato[i][j] = 0;
}
}
}
}
if (Riped == M * N - notRiped){
outputs<<Date;
outputs.close();
return 0;
}else{
outputs<<-1;
outputs.close();
return 0;
}
outputs.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |