이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> greedy(string s, vector<int> c){
int n = s.size();
vector<int> ans(n,-1);
int ptr=0;
for(int i=0;i<n&&ptr<c.size();){
int j=i;
for(;j<i+c[ptr];j++){
if(s[j]=='_')break;
}
// cout << j << '\n';
if(j==i+c[ptr]){
while(s[j]=='x')j++;
for(int k=j-c[ptr];k<j;k++)ans[k]=ptr;
// cout << j-c[ptr] << ' ' << j-1 << '\n';
i=j+1;
ptr++;
}else{
i=j+1;
}
}
return ans;
}
string solve_puzzle(string s, vector<int> c) {
vector<int> ans = greedy(s,c);
int n = s.size();
// for(int i : ans)cout << i << ' ';
// cout << '\n';
reverse(s.begin(),s.end());
reverse(c.begin(),c.end());
// cout << s << '\n';
// for(int i : ans)cout << i << ' ';
// cout << '\n';
vector<int> ans2 = greedy(s,c);
reverse(ans2.begin(),ans2.end());
reverse(s.begin(),s.end());
reverse(c.begin(),c.end());
int prev=-1,prev2=-1;
string output="";
for(int i=0;i<n;i++){
if(ans2[i]!=-1)ans2[i]=c.size()-1-ans2[i];
prev=max(ans[i],prev);
prev2=max(ans2[i],prev2);
if(s[i]!='.'){
output+=s[i];
continue;
}
if(ans[i]==ans2[i]&&prev==prev2){
if(ans[i]==-1)output += "_";
else output += "X";
}else{
output += "?";
}
}
//cout << output;
// cout << '\n';
// for(int i : ans2)cout << i << ' ';
// cout << '\n';
return output;
}
컴파일 시 표준 에러 (stderr) 메시지
paint.cpp: In function 'std::vector<int> greedy(std::string, std::vector<int>)':
paint.cpp:12:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=0;i<n&&ptr<c.size();){
| ~~~^~~~~~~~~
# | 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... |