이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
//#include "grader.cpp"
 
#include <cstdlib>
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 2e5 + 3;
 
int pf[3][N], n, m;
int dp[202][N], dp1[202][N], pref[N], f[202][N], pfX[N], sfX[N];
 
int get(int l, int r, int tp){
	if(l > r) return 0;
	return pf[tp][r] - pf[tp][l - 1];
}
int Get(int l, int r, int tp){
	if(l > r) return 0;
	return f[tp][r] - f[tp][l - 1];
}
 
string solve_puzzle(string s, vector<int> c) {
	n = (int)s.size();
	m = (int)c.size();
	s = ' ' + s;
	for(int i = 1; i <= n; i ++){
		if(s[i] == 'X')
			pf[0][i] ++, pfX[i] = i;
		if(s[i] == '_')
			pf[1][i] ++;
		if(s[i] == '.')
			pf[2][i] ++;
		pf[0][i] += pf[0][i - 1];
		pf[1][i] += pf[1][i - 1];
		pf[2][i] += pf[2][i - 1];
		pfX[i] = max(pfX[i], pfX[i - 1]);
	} 
	
	sfX[n + 1] = n;
	
	for(int i = n; i >= 1; i --){
		if(s[i] == 'X')
			sfX[i] = i;
		else 
			sfX[i] = sfX[i + 1];
	}
	
	for(int i = c[0]; i <= n; i ++){
		if(get(i - c[0] + 1, i, 1) == 0 && get(1, i - c[0], 0) == 0 && (m != 1 || get(i + 1, n, 0) == 0))
			dp[0][i] = 1;
	}
	
	for(int i = 1; i < m; i ++){
		vector <int> pf(n + 1, 0);
		for(int j = 1; j <= n; j ++){
			pf[j] = pf[j - 1] + dp[i - 1][j];
		}
		for(int j = c[i] + 1; j <= n; j ++){
			if(get(j - c[i] + 1, j, 1) == 0 && get(j - c[i], j - c[i], 0) == 0){
				int sum = pf[j - c[i] - 1] - pf[max(pfX[j - c[i] - 1] - 1, 0)];
				if(sum && (i != m - 1 || get(j + 1, n, 0) == 0)) dp[i][j] = 1;
			}
		}
	}
	
	for(int i = n; i >= c[m - 1]; i --){
		if(get(i - c[m - 1] + 1, i, 1) == 0 && get(i + 1, n, 0) == 0 && (m != 1 || get(1, i - c[m - 1], 0) == 0))
			dp1[m - 1][i] = 1;
	}
	
	for(int i = m - 2; i >= 0; i --){
		vector <int> sf(n + 2, 0);
		for(int j = n; j >= 1; j --){
			sf[j] = sf[j + 1] + dp1[i + 1][j];
		}
		for(int j = n; j >= c[i]; j --){
			if(get(j - c[i] + 1, j, 1) == 0 && get(j + 1, j + 1, 0) == 0){
				int sum = sf[j + c[i + 1] + 1] - sf[ min(n, sfX[j + 1] + c[i + 1]) + 1 ];
				if(sum && (i != 0 || get(1, j - c[i], 0) == 0))	dp1[i][j] = 1;
			}
		}
	}
	
	for(int i = 0; i < m; i ++)
		for(int j = 1; j <= n; j ++)
			if(dp[i][j] && !dp1[i][j])
				dp[i][j] = 0;
	for(int i = 0; i < m; i ++)
		for(int j = 1; j <= n; j ++)
			f[i][j] += f[i][j - 1] + dp[i][j];
	
	string ans;
	
	for(int i = 1; i <= n; i ++){
		if(s[i] == '.'){
			int canX = 0, can_ = 0;
			for(int j = 0; j < m; j ++){
				if(j == 0){
					if(Get(i + c[j], n, 0) && get(i, min(n, i + c[j] - 1), 0) == 0)
						can_ = 1;
				} else {
					if(Get(pfX[i - 1], i - 1, j - 1) && Get(i + c[j], sfX[min(i + c[j], n)], j) && get(i, min(i + c[j] - 1, n), 0) == 0)
						can_ = 1;
				}
				if(Get(i, min(i + c[j] - 1, n), j))
					canX = 1;
			}
			if(Get(1, i - 1, m - 1) && get(i, n, 0) == 0) 
				can_ = 1;
			if(canX && can_)
				ans += '?';
			else if(canX)
				ans += 'X';
			else 
				ans += '_';
		} else 
			ans += s[i];
	}
		
    return ans;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |