Submission #1843325


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int h, w;
string s[100];

int main() {
	cin >> h >> w;
	rep(i,h) cin >> s[i];
	
	// まず.を頼りに復元してみる s[i][j]が.ならそのマスと周囲8マスも確実に.
	string mp[h] = {};
	rep(i,h) rep(j,w) mp[i] += '#';
	rep(i,h) {
		rep(j,w) {
			if (s[i][j]=='.') {
				mp[i][j] = '.';
				rep(d,8) {
					int ii = i + ddy[d], jj = j + ddx[d];
					if (0<=ii && ii<h && 0<=jj && jj<w) {
						mp[ii][jj] = '.';
					}
				}
			}
		}
	}
	
	// 復元したデータを実際に収縮してみて元に戻ったらpossible 戻らないならむり
	rep(i,h) {
		rep(j,w) {
			// mp[i][j]自身かその周囲8マスが#ならそのマスは#になる
			char t = '.';
			if (mp[i][j]=='#') t = '#';
			else {
				rep(d,8) {
					int ii = i + ddy[d], jj = j + ddx[d];
					if (0<=ii && ii<h && 0<=jj && jj<w && mp[ii][jj]=='#') {
						t = '#';
						break;
					}
				}
			}
			if (t!=s[i][j]) {
				cout << "impossible" << ln;
				return 0;
			}
		}
	}
	cout << "possible" << ln;
	rep(i,h) {
		rep(j,w) cout << mp[i][j];
		cout << ln;
	}
}

Submission Info

Submission Time
Task D - 画像処理高橋君
User creep04
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2804 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 1 ms 256 KB
possible_2.txt AC 1 ms 256 KB
possible_3.txt AC 1 ms 256 KB
possible_4.txt AC 1 ms 256 KB
possible_5.txt AC 1 ms 256 KB
possible_6.txt AC 1 ms 256 KB
possible_7.txt AC 2 ms 256 KB
possible_8.txt AC 2 ms 256 KB
possible_9.txt AC 1 ms 256 KB
random_0.txt AC 1 ms 256 KB
random_1.txt AC 1 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 1 ms 256 KB
random_7.txt AC 1 ms 256 KB
random_8.txt AC 1 ms 256 KB
random_9.txt AC 1 ms 256 KB