Submission #1155431
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
int N, K, Q; string S[1010];
//-----------------------------------------------------------------
int B[1010][1010], BB[1010][1010];
void pre() {
rep(y, 1, N + 1) rep(x, 1, N + 1) {
if (S[y][x] == '.') B[y][x] = 0;
else B[y][x] = 1;
}
rep(y, 1, N + 1) rep(x, 1, N + 1) BB[y][x] = B[y][x] + BB[y - 1][x] + BB[y][x - 1] - BB[y - 1][x - 1];
}
bool chk(int ax, int ay) {
int bx = ax + K - 1, by = ay + K - 1;
int sm = BB[by][bx] - BB[ay - 1][bx] - BB[by][ax - 1] + BB[ay - 1][ax - 1];
return sm == 0;
}
//-----------------------------------------------------------------
int C[1010][1010];
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { -1, 0, 1, 0 };
void coloring() {
int c = 1;
rep(y, 1, N - K + 2) rep(x, 1, N - K + 2) if (chk(x, y) && C[y][x] == 0) {
queue<pair<int,int>> que;
que.push({ x, y });
while (!que.empty()) {
auto q = que.front(); que.pop();
int xx = q.first;
int yy = q.second;
if (C[yy][xx]) continue;
C[yy][xx] = c;
rep(i, 0, 4) {
int xxx = xx + dx[i];
int yyy = yy + dy[i];
if (xxx < 1 || N < xxx) continue;
if (yyy < 1 || N < yyy) continue;
if (!chk(xxx, yyy)) continue;
if (C[yyy][xxx]) continue;
que.push({ xxx, yyy });
}
}
c++;
}
}
//-----------------------------------------------------------------
int main() {
cin >> N >> K >> Q;
rep(y, 1, N + 1) cin >> S[y], S[y] = " " + S[y];
pre();
coloring();
rep(i, 0, Q) {
int ay, ax, by, bx;
scanf("%d%d%d%d", &ay, &ax, &by, &bx);
if (C[ay][ax] == 0 || C[ay][ax] != C[by][bx]) printf("No\n");
else printf("Yes\n");
}
}
Submission Info
Submission Time |
|
Task |
E - スライドパズル |
User |
hamayanhamayan |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
1733 Byte |
Status |
AC |
Exec Time |
118 ms |
Memory |
13568 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:67:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &ay, &ax, &by, &bx);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
sample_01.txt, sample_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, sample_01.txt, sample_02.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
29 ms |
4736 KB |
02.txt |
AC |
28 ms |
4736 KB |
03.txt |
AC |
95 ms |
13440 KB |
04.txt |
AC |
106 ms |
13440 KB |
05.txt |
AC |
118 ms |
13568 KB |
06.txt |
AC |
116 ms |
13568 KB |
07.txt |
AC |
74 ms |
13312 KB |
08.txt |
AC |
98 ms |
13440 KB |
09.txt |
AC |
97 ms |
13440 KB |
10.txt |
AC |
109 ms |
13568 KB |
11.txt |
AC |
78 ms |
13440 KB |
12.txt |
AC |
94 ms |
13440 KB |
13.txt |
AC |
75 ms |
12800 KB |
14.txt |
AC |
108 ms |
13568 KB |
15.txt |
AC |
73 ms |
13568 KB |
16.txt |
AC |
111 ms |
13568 KB |
17.txt |
AC |
111 ms |
13568 KB |
18.txt |
AC |
75 ms |
13440 KB |
19.txt |
AC |
115 ms |
13568 KB |
20.txt |
AC |
111 ms |
13568 KB |
21.txt |
AC |
101 ms |
13568 KB |
22.txt |
AC |
80 ms |
13440 KB |
23.txt |
AC |
112 ms |
13568 KB |
24.txt |
AC |
87 ms |
13568 KB |
25.txt |
AC |
91 ms |
13568 KB |
26.txt |
AC |
78 ms |
13440 KB |
27.txt |
AC |
111 ms |
13568 KB |
28.txt |
AC |
109 ms |
13568 KB |
29.txt |
AC |
72 ms |
11520 KB |
30.txt |
AC |
71 ms |
11648 KB |
31.txt |
AC |
111 ms |
13568 KB |
32.txt |
AC |
89 ms |
13568 KB |
33.txt |
AC |
65 ms |
11520 KB |
34.txt |
AC |
107 ms |
13568 KB |
sample_01.txt |
AC |
2 ms |
4352 KB |
sample_02.txt |
AC |
2 ms |
4352 KB |