이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#ifdef dremix
#define p(x) cerr<<#x<<" = "<<x<<endl;
#define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
#define pp(x) cerr<<#x<<" = "<<x.F<<"-"<<x.S<<endl;
#define pv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<v<<", ";cerr<<"}"<<endl;
#define ppv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<v.F<<"-"<<v.S<<", ";cerr<<"}"<<endl;
#else
#define p(x) {}
#define p2(x,y) {}
#define pp(x) {}
#define pv(x) {}
#define ppv(x) {}
#endif
const int N = 3e5+5;
const int MOD = 1e9+7;
const ll INF = 1e18+5;
vector<vector<bool> > v;
int rem;
vector<int> c,arr;
string s;
void solve(int i, int j){
p2(i,j)
if(i == arr.size())
return;
if(arr[i] != 2){
/// todo - fix when gaps will break flow
//v[i][arr[i]] = true;
//solve(i+1,j);
return;
}
/// can choose what to put (white = gap, black = consecutive block)
if(j < c.size()){
for(int k=0;k<c[j];k++)
v[i+k][1] = true;
bool add = j + 1 < c.size();
if(add)
v[i+c[j]][0] = true;
solve(i+c[j]+add,j+1);
}
if(rem > 0){
v[i][0] = true;
rem--;
solve(i+1,j);
rem++;
}
}
std::string solve_puzzle(std::string S, std::vector<int> C) {
s = S;
c = C;
int n = s.size();
int m = c.size();
arr.resize(n);
int i,j;
for(i=0;i<n;i++){
if(s[i] == '_')
arr[i] = 0;
else if(s[i] == 'X')
arr[i] = 1;
else{
assert(s[i] == '.');
arr[i] = 2;
}
}
pv(arr)
int sum = 0;
for(auto x : c)
sum += x;
int gaps = n - sum;
assert(gaps >= m-1);
gaps -= m-1;
// there are (gaps + m) choose (m) ways to put the gaps
rem = gaps;
v.assign(n,vector<bool>(2,false));
solve(0,0);
string ans = "";
for(i=0;i<n;i++){
p(i)
p2(v[i][0],v[i][1])
if(v[i][0] == v[i][1]){
assert(v[i][0] != false);
ans += '?';
}
else if(v[i][0]){
ans += '_';
}
else{
ans += 'X';
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
paint.cpp: In function 'void solve(int, int)':
paint.cpp:36:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(i == arr.size())
| ~~^~~~~~~~~~~~~
paint.cpp:45:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if(j < c.size()){
| ~~^~~~~~~~~~
paint.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | bool add = j + 1 < c.size();
| ~~~~~~^~~~~~~~~~
paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:70:11: warning: unused variable 'j' [-Wunused-variable]
70 | int i,j;
| ^
# | 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... |