记录编号 570991 评测结果 AAAAAAAAAAAAAAAA
题目名称 [POI 1999] 位图 最终得分 100
用户昵称 GravatarTab↹ 是否通过 通过
代码语言 C++ 运行时间 0.011 s
提交时间 2022-04-29 21:52:09 内存使用 1.83 MiB
显示代码纯文本
#include <iostream>
#include <fstream>

using namespace std;

#ifdef INT_MAX
#undef INT_MAX
#endif
const int INT_MAX = 0x7FFFFFFF;

template<typename T>
void make2darray(T**& des, int x, int y){
    des = new T*[x];
    for(int i = 0; i < x; ++i)
        des[i] = new T[y];
}

template<typename T>
void delete2darray(T**& des, int x, int y){
    for(int i = 0; i < x; ++i)
        delete[] des[i];
    delete[] des;
}

int main(void){
    ifstream fin("bit.in");
    ofstream fout("bit.out");
    int** bitmap;
    int n, m;
    fin >> n >> m;
    make2darray(bitmap, n+2, m+2);
    char tmp;
    for(int x = 1; x <= n; ++x){
        for(int y = 1; y <= m; ++y){
            fin >> tmp;
            if(tmp == '1')
                bitmap[x][y] = 0;
            else
                bitmap[x][y] = INT_MAX;
        }
    }
    bool solved = false;
    int cur = 0;
    while(!solved){
        solved = true;
        for(int x = 1; x <= n; ++x){
            for(int y = 1; y <= m; ++y){
                if(bitmap[x][y] == cur){
                    if(bitmap[x-1][y] == INT_MAX){
                        bitmap[x-1][y] = cur+1;
                        solved = false;
                    }
                    if(bitmap[x+1][y] == INT_MAX){
                        bitmap[x+1][y] = cur+1;
                        solved = false;
                    }
                    if(bitmap[x][y+1] == INT_MAX){
                        bitmap[x][y+1] = cur+1;
                        solved = false;
                    }
                    if(bitmap[x][y-1] == INT_MAX){
                        bitmap[x][y-1] = cur+1;
                        solved = false;
                    }
                }
            }
        }
        ++cur;
    }
    for(int x = 1; x <= n; ++x){
        for(int y = 1; y <= m; ++y)
            fout << bitmap[x][y] << ' ';
        fout << endl;
    }
    delete2darray(bitmap, n+2, m+2);
    return 0;
}