제출 #53005

#제출 시각아이디문제언어결과실행 시간메모리
53005KieranHorganPaint By Numbers (IOI16_paint)C++17
100 / 100
904 ms102816 KiB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;

int n, k;
string s;
vector<int> c;

int dp[200005][105];
int whitePre[200005];
int canWhite[200005];
int canBlack[200005];

bool solve(int idx, int sub) {
	if(idx > n) return sub==k;
	if(dp[idx][sub] != -1) return dp[idx][sub];
	if(sub == k) {
		if(s[idx] == 'X') return dp[idx][sub] = 0;
		if(solve(idx+1, sub))
			return dp[idx][sub] = canWhite[idx] = 1;
		return dp[idx][sub] = 0;
	}
	if(idx+c[sub]-1 > n || s[idx-1] == 'X' || s[idx+c[sub]] == 'X') {
		if(s[idx] == 'X') return dp[idx][sub] = 0;
		if(solve(idx+1, sub))
			return dp[idx][sub] = canWhite[idx] = 1;
		return dp[idx][sub] = 0;
	}
	if(whitePre[idx+c[sub]-1]-whitePre[idx-1] != 0) {
		if(s[idx] == 'X') return dp[idx][sub] = 0;
		if(solve(idx+1, sub))
			return dp[idx][sub] = canWhite[idx] = 1;
		return dp[idx][sub] = 0;
	}

	bool ok = 0;
	if(s[idx] != 'X' && solve(idx+1, sub)) {
		canWhite[idx] = ok = 1;
	}
	if(solve(idx+c[sub]+1, sub+1)) {
		canWhite[idx-1] = 1;
		canWhite[idx+c[sub]] = 1;
		canBlack[idx]++;
		canBlack[idx+c[sub]]--;
		ok = 1;
	}
	return dp[idx][sub] = ok;
}

string solve_puzzle(string S, vector<int> C) {
	s = "_" + S + "_"; c = C;
	n = S.size(); k = C.size();

	memset(dp, -1, sizeof(dp));
	for(int i = 1; i <= n; i++)
		whitePre[i] = whitePre[i-1]+(s[i]=='_');

	solve(1, 0);

	for(int i = 1; i <= n; i++)
		canBlack[i] += canBlack[i-1];

	string res;
	for(int i = 1; i <= n; i++)
		if(canBlack[i] && canWhite[i])
			res.push_back('?');
		else if(canBlack[i])
			res.push_back('X');
		else
			res.push_back('_');
    return res;
}

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

paint.cpp: In function 'bool solve(int, int)':
paint.cpp:18:41: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if(s[idx] == 'X') return dp[idx][sub] = 0;
                            ~~~~~~~~~~~~~^~~
paint.cpp:20:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    return dp[idx][sub] = canWhite[idx] = 1;
           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
paint.cpp:21:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   return dp[idx][sub] = 0;
          ~~~~~~~~~~~~~^~~
paint.cpp:24:41: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if(s[idx] == 'X') return dp[idx][sub] = 0;
                            ~~~~~~~~~~~~~^~~
paint.cpp:26:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    return dp[idx][sub] = canWhite[idx] = 1;
           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
paint.cpp:27:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   return dp[idx][sub] = 0;
          ~~~~~~~~~~~~~^~~
paint.cpp:30:41: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if(s[idx] == 'X') return dp[idx][sub] = 0;
                            ~~~~~~~~~~~~~^~~
paint.cpp:32:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    return dp[idx][sub] = canWhite[idx] = 1;
           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
paint.cpp:33:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   return dp[idx][sub] = 0;
          ~~~~~~~~~~~~~^~~
paint.cpp:47:22: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  return dp[idx][sub] = ok;
         ~~~~~~~~~~~~~^~~~
#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...