답안 #48945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48945 2018-05-20T06:50:14 Z leehosu01 토마토 (KOI13_tomato) C++17
16 / 16
100 ms 13288 KB
#include<bits/stdc++.h>
using namespace std;
#define able(Y,X) if(0<=X&&X<N&&0<=Y&&Y<M&&D[Y].test(X)==0)Qs.push({Y,X}),D[Y].set(X);
bitset<1000>D[1001];
int N,M,to;
struct A{int y,x;
void mov(queue<A>&Qs)
{
    able(y,x-1);
    able(y,x+1);
    able(y-1,x);
    able(y+1,x);
}};
queue<A>Q;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N>>M;
    int a;
    D[0].reset();
    for(int i=0;i<M;D[++i].reset())
        for(int j=0;j<N;j++)
        {
            cin>>a;
            if(a==1)D[i].set(j),Q.push({i,j}),++to;
            if(a==-1)D[i].set(j),++to;
        }
    if(to==0)printf("-1");
    else if(to==N*M)printf("0");
    else
    {
        int pl=0;
        while(to<N*M&&Q.size())
        {
            pl++;
            for(int i=Q.size();i;--i)
            {
                Q.front().mov(Q);
                Q.pop();
            }
            to+=Q.size();
        }
        printf("%d",to==N*M?pl:-1);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 636 KB Output is correct
2 Correct 2 ms 672 KB Output is correct
3 Correct 3 ms 672 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 736 KB Output is correct
2 Correct 2 ms 736 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
4 Correct 3 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 788 KB Output is correct
2 Correct 6 ms 1028 KB Output is correct
3 Correct 3 ms 1028 KB Output is correct
4 Correct 3 ms 1028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1028 KB Output is correct
2 Correct 2 ms 1028 KB Output is correct
3 Correct 5 ms 1056 KB Output is correct
4 Correct 7 ms 1056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1056 KB Output is correct
2 Correct 9 ms 1164 KB Output is correct
3 Correct 4 ms 1164 KB Output is correct
4 Correct 8 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1320 KB Output is correct
2 Correct 21 ms 1884 KB Output is correct
3 Correct 13 ms 2028 KB Output is correct
4 Correct 10 ms 2128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 2308 KB Output is correct
2 Correct 35 ms 3076 KB Output is correct
3 Correct 7 ms 3076 KB Output is correct
4 Correct 10 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 3324 KB Output is correct
2 Correct 88 ms 5404 KB Output is correct
3 Correct 11 ms 5540 KB Output is correct
4 Correct 55 ms 6908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 7108 KB Output is correct
2 Correct 93 ms 9096 KB Output is correct
3 Correct 90 ms 11356 KB Output is correct
4 Correct 87 ms 13288 KB Output is correct