Submission #1857007


Source Code Expand

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
int H,W;
string S[105], cpS[105];
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>H>>W;
    REP(i,0,H){
        cin>>S[i];
        cpS[i] = S[i];
//        REP(j,0,W){
//            cpS[i][j] = S[i][j];
//        }
    }

    REP(i,0,H){
        REP(j,0,W){
            if(S[i][j] == '.') continue;
            REP(k,0,8){
                if(!CK(i+dy8[k],0,H) || !CK(j+dx8[k],0,W)) continue;
                if(S[i+dy8[k]][j+dx8[k]] == '.'){
                    cpS[i][j] = '.';
                    break;
                }
            }
        }
    }

    REP(i,0,H){
        REP(j,0,W){
            if(cpS[i][j] == '#') continue;
            REP(k,0,8){
                if(!CK(i+dy8[k],0,H) || !CK(j+dx8[k],0,W)) continue;
                if(cpS[i+dy8[k]][j+dx8[k]] == '#'){
                    cpS[i][j] = 'x';
                    break;
                }
            }
        }
    }

    REP(i,0,H){
        REP(j,0,W){
            if((S[i][j] == '#') && (cpS[i][j] == '.')){
                cout<<"impossible"<<endl;
                return 0;
            }
        }
    }

    cout<<"possible"<<endl;
    REP(i,0,H){
        REP(j,0,W){
            if(cpS[i][j] == 'x') cout<<".";
            else cout<<cpS[i][j];
        }
        cout<<endl;
    }


    return 0;
}

Submission Info

Submission Time
Task D - 画像処理高橋君
User prog470
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2163 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt
All example_0.txt, example_1.txt, example_2.txt, handmade_0.txt, handmade_1.txt, possible_0.txt, possible_1.txt, possible_2.txt, possible_3.txt, possible_4.txt, possible_5.txt, possible_6.txt, possible_7.txt, possible_8.txt, possible_9.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt
Case Name Status Exec Time Memory
example_0.txt AC 1 ms 256 KB
example_1.txt AC 1 ms 256 KB
example_2.txt AC 1 ms 256 KB
handmade_0.txt AC 1 ms 256 KB
handmade_1.txt AC 1 ms 256 KB
possible_0.txt AC 1 ms 256 KB
possible_1.txt AC 2 ms 256 KB
possible_2.txt AC 2 ms 256 KB
possible_3.txt AC 2 ms 256 KB
possible_4.txt AC 1 ms 256 KB
possible_5.txt AC 1 ms 256 KB
possible_6.txt AC 2 ms 256 KB
possible_7.txt AC 2 ms 256 KB
possible_8.txt AC 2 ms 256 KB
possible_9.txt AC 2 ms 256 KB
random_0.txt AC 1 ms 256 KB
random_1.txt AC 2 ms 256 KB
random_2.txt AC 1 ms 256 KB
random_3.txt AC 1 ms 256 KB
random_4.txt AC 1 ms 256 KB
random_5.txt AC 1 ms 256 KB
random_6.txt AC 2 ms 256 KB
random_7.txt AC 2 ms 256 KB
random_8.txt AC 1 ms 256 KB
random_9.txt AC 1 ms 256 KB