제출 #486778

#제출 시각아이디문제언어결과실행 시간메모리
486778sochoDango Maker (JOI18_dango_maker)C++14
100 / 100
422 ms79812 KiB
/*
	Going for full
*/
#include <bits/stdc++.h>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
	srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
	long long a = rand();
	long long b = rand();
	return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
	freopen("problem.in", "r", stdin); 
	freopen("problem.out", "w", stdout);
}
template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
#define endl '\n'
// #define double long double
// #define int long long
// const int MOD = 1000 * 1000 * 1000 + 7;
// const int MOD = 998244353;
// #define cerr if(0) cerr
#define debug(x) cerr << #x << ": " << x << endl;

const int MXN = 3005;
int n, m;
int grid[MXN][MXN];
int can[MXN][MXN];
int dp[MXN][3];
 
signed main() {
 
	cin >> n >> m;
	for (int i=1; i<=n; i++) {
		string s;
		cin >> s;
		for (int j=1; j<=m; j++) {
			if (s[j-1] == 'R') grid[i][j] = 1;
			if (s[j-1] == 'G') grid[i][j] = 2;
			if (s[j-1] == 'W') grid[i][j] = 3;
		}
	}
	
	
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			if (grid[i][j] == 2) {
				if (grid[i-1][j] == 1 && grid[i+1][j] == 3) {
					can[i][j] += 1;
				}
				if (grid[i][j-1] == 1 && grid[i][j+1] == 3) {
					can[i][j] += 2;
				}
			}
		}
	}
	
	int ans = 0;
	
	for (int diag=2; diag<=n+m; diag++) {
		dp[0][0] = dp[0][1] = dp[0][2] = 0;
		int here = 0;
		vector<int> vc;
		vc.push_back(-1);
		for (int i=1; i<=n; i++) {
			int j = diag - i;
			if (j >= 1 && j <= m) {
				vc.push_back(can[i][j]);
			}
		}
		for (int i=1; i<vc.size(); i++) {
			dp[i][0] = dp[i][1] = dp[i][2] = 0;
			dp[i][0] = max(max(dp[i-1][0], dp[i-1][1]), dp[i-1][2]);
			if (vc[i] & 1) {
				dp[i][1] = max(dp[i][1], 1 + max(dp[i-1][0], dp[i-1][1]));
			}
			if (vc[i] & 2) {
				dp[i][2] = max(dp[i][2], 1 + max(dp[i-1][0], dp[i-1][2]));
			}
			here = max(here, max(max(dp[i][0], dp[i][1]), dp[i][2]));
		}
		ans += here;
	}
	
	cout << ans << endl;
	
}

컴파일 시 표준 에러 (stderr) 메시지

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for (int i=1; i<vc.size(); i++) {
      |                 ~^~~~~~~~~~
dango_maker.cpp: In function 'void usaco()':
dango_maker.cpp:18:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  freopen("problem.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  freopen("problem.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...