Submission #1147414

#TimeUsernameProblemLanguageResultExecution timeMemory
1147414minggaDango Maker (JOI18_dango_maker)C++20
100 / 100
282 ms71084 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 3005;
int f[N][3], n, m;
int a[N][N];

bool check_hor(int x, int y) {
	if(y <= 2) return false;
	for(int i = 2; i >= 0; i--) {
		if(a[x][y - i] != 2 - i) return false;
	}
	return true;
}

bool check_ver(int x, int y) {
	if(x <= 2) return false;
	for(int i = 2; i >= 0; i--) {
		if(a[x - i][y] != 2 - i) return false;
	}
	return true;
}

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			char x; cin >> x;
			if(x == 'G') a[i][j] = 1;
			else if(x == 'W') a[i][j] = 2;
		}
	}
	int ans = 0;
	for(int x = 2; x <= m + n; x++) {
		int st = max(1ll, x - m), en = min(n, x - 1);
		memset(f, 0, sizeof f);
		for(int i = st; i <= en; i++) {
			int j = x - i;
			for(int t = 0; t < 3; t++) f[i][0] = max(f[i][0], f[i - 1][t]);
			if(check_hor(i,  j)) {
				for(int t = 0; t <= 3; t++) f[i][1] = max(f[i][1], f[i - 1][t] + 1);
			}
			if(check_ver(i, j)) {
				f[i][2] = max({f[i - 1][2], f[i - 2][2], f[i - 2][0]}) + 1;
			}
		}
		ans += max({f[en][0], f[en][1], f[en][2]});
	}
	cout << ans << ln;
  cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:38:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:39:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:57:94: warning: iteration 3 invokes undefined behavior [-Waggressive-loop-optimizations]
   57 |                                 for(int t = 0; t <= 3; t++) f[i][1] = max(f[i][1], f[i - 1][t] + 1);
      |                                                                                    ~~~~~~~~~~^
dango_maker.cpp:57:50: note: within this loop
   57 |                                 for(int t = 0; t <= 3; t++) f[i][1] = max(f[i][1], f[i - 1][t] + 1);
      |                                                ~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...