답안 #141602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141602 2019-08-08T13:59:46 Z DrumpfTheGodEmperor Dango Maker (JOI18_dango_maker) C++14
13 / 100
3 ms 380 KB
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 3005;
int n, m, ans = 0;
char a[N][N];
bool check(int i, int j, string pattern) {
	if (i < 0 || i >= n || j + pattern.length() - 1 >= m || j < 0) return false;
	fw (k, 0, pattern.length()) {
		if (a[i][j + k] != pattern[k]) return false;
	}
	return true;
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	fw (i, 0, n) fw (j, 0, m) cin >> a[i][j];
	string defaultPattern = "RGW";
	fw (i, 0, n) {
		fw (j, 0, m) {
			//Find groups of RGW having a difference of 1.
			if (check(i, j, defaultPattern)) {
				if (check(i - 1, j + 1, defaultPattern)) continue;
				//New beginning of a group of RGW.
				int cntHorizontal = 0, mxLine = 0;
				fw (k, i, n) {
					if (check(k, j - (k - i), defaultPattern)) cntHorizontal++, mxLine = max(mxLine, k);
					else break;
				}
				int cntVertical = cntHorizontal - 2;
				if (check(i - 2, j + 2, "R") && check(i - 1, j + 2, "G")) cntVertical++;
				if (check(i - 1, j + 1, "R")) cntVertical++;
				int mxLineJ = j - (mxLine - i);
				if (check(mxLine + 1, mxLineJ + 1, "W")) cntVertical++;
				if (check(mxLine + 1, mxLineJ, "G") && check(mxLine + 2, mxLineJ, "W")) cntVertical++;
				ans += max(cntVertical, cntHorizontal);
		 	}
			if (check(i, j, "R") && check(i + 1, j, "G") && check(i + 2, j, "W") &&
				!check(i, j, defaultPattern) && !check(i + 1, j - 1, defaultPattern) &&
				!check(i + 2, j - 2, defaultPattern)) {
//					cout << "Test\n";
				ans++;	
			}
		}
	}
	cout << ans;
	return 0;
}

Compilation message

dango_maker.cpp: In function 'bool check(int, int, std::__cxx11::string)':
dango_maker.cpp:20:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i < 0 || i >= n || j + pattern.length() - 1 >= m || j < 0) return false;
                         ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
dango_maker.cpp:11:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fw(i, l, r) for (int i = l; i < r; i++)
dango_maker.cpp:21:6:
  fw (k, 0, pattern.length()) {
      ~~~~~~~~~~~~~~~~~~~~~~            
dango_maker.cpp:21:2: note: in expansion of macro 'fw'
  fw (k, 0, pattern.length()) {
  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 376 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 376 KB Output isn't correct
20 Halted 0 ms 0 KB -