제출 #961240

#제출 시각아이디문제언어결과실행 시간메모리
961240MinaRagy06Paint By Numbers (IOI16_paint)C++17
100 / 100
641 ms122484 KiB
#include <bits/stdc++.h>
#include "paint.h"
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
#define ll long long
 
const int N = 200'005, K = 105;
bool prfdp[N][K], sufdp[N][K];
string solve_puzzle(string s, vector<int> c) {
	int n = s.size(), k = c.size();
	int prf[n + 1]{};
	for (int i = 0; i < n; i++) {
		prf[i + 1] = prf[i] + (s[i] == '_');
	}
	prfdp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			if (j - 1 >= 0) {
				if (i - c[j - 1] >= 0 && prf[i] - prf[i - c[j - 1]] == 0) {
					if (j - 1 == 0) {
						prfdp[i][j] = prfdp[i - c[j - 1]][j - 1];
					} else if (s[i - c[j - 1] - 1] != 'X' && i - c[j - 1] - 1 >= 0) {
						prfdp[i][j] = prfdp[i - c[j - 1] - 1][j - 1];
					}
				}
			}
			if (s[i - 1] != 'X') {
				prfdp[i][j] |= prfdp[i - 1][j];
			}
		}
	}
	sufdp[n][k] = 1;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= k; j++) {
			if (j + 1 <= k) {
				if (i + c[j] <= n && prf[i + c[j]] - prf[i] == 0) {
					if (j + 1 == k) {
						sufdp[i][j] = sufdp[i + c[j]][j + 1];
					} else if (i + c[j] + 1 <= n && s[i + c[j]] != 'X') {
						sufdp[i][j] = sufdp[i + c[j] + 1][j + 1];
					}
				}
			}
			if (s[i] != 'X') {
				sufdp[i][j] |= sufdp[i + 1][j];
			}
		}
	}
	string ans;
	ans.resize(n);
	vector<int> gud[k];
	for (int j = 0; j < k; j++) {
		for (int l = 0; l < n; l++) {
			if (l + c[j] <= n && prf[l + c[j]] - prf[l] == 0) {
				bool vl = 0, vr = 0;
				if (j == 0) {
					vl = prfdp[l][j];
				} else if (l - 1 >= 0 && s[l - 1] != 'X') {
					vl = prfdp[l - 1][j];
				}
				if (j + 1 == k) {
					vr = sufdp[l + c[j]][j + 1];
				} else if (l + c[j] + 1 <= n && s[l + c[j]] != 'X') {
					vr = sufdp[l + c[j] + 1][j + 1];
				}
				if (vl && vr) {
					gud[j].push_back(l);
				}
			}
		}
	}
	int ptr[k]{};
	for (int i = 0; i < n; i++) {
		if (s[i] != '.') {
			ans[i] = s[i];
			continue;
		}
		bool ok[2]{};
		for (int j = 0; j < k; j++) {
			while (ptr[j] < gud[j].size() && gud[j][ptr[j]] < max(0, i - c[j] + 1)) {
				ptr[j]++;
			}
			if (ptr[j] < gud[j].size() && gud[j][ptr[j]] <= i) {
				ok[1] = 1;
			}
		}
//		for (int j = 0; j < k; j++) {
//			for (int l = i; l >= max(0, i - c[j] + 1); l--) {
//				if (l + c[j] <= n && prf[l + c[j]] - prf[l] == 0) {
//					bool vl = 0, vr = 0;
//					if (j == 0) {
//						vl = prfdp[l][j];
//					} else if (l - 1 >= 0 && s[l - 1] != 'X') {
//						vl = prfdp[l - 1][j];
//					}
//					if (j + 1 == k) {
//						vr = sufdp[l + c[j]][j + 1];
//					} else if (l + c[j] + 1 <= n && s[l + c[j]] != 'X') {
//						vr = sufdp[l + c[j] + 1][j + 1];
//					}
//					ok[1] |= vl && vr;
//				}
//			}
//		}
		for (int j = 0; j <= k; j++) {
			ok[0] |= prfdp[i][j] && sufdp[i + 1][j];
		}
		if (ok[0] && ok[1]) {
			ans[i] = '?';
		} else if (ok[0]) {
			ans[i] = '_';
		} else if (ok[1]) {
			ans[i] = 'X';
		} else {
			assert(0);
		}
	}
	return ans;
}

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

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |    while (ptr[j] < gud[j].size() && gud[j][ptr[j]] < max(0, i - c[j] + 1)) {
      |           ~~~~~~~^~~~~~~~~~~~~~~
paint.cpp:85:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    if (ptr[j] < gud[j].size() && gud[j][ptr[j]] <= i) {
      |        ~~~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...