This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
string constr(string aux){
int t=0;
for(int i=0;i<aux.size()-1;i++){
if(aux[i]=='_'){
t++;
}
}
string ans;
ans.resize(aux.size());
for(int i=0;i<aux.size();i++){
if(aux[i]=='_' and ans[i]!='?'){
ans[i]=aux[i];
}
if(aux[i+t]=='X' and aux[i]=='X'){
ans[i+t]='X';
if(ans[i]!='X'){
ans[i]='?';
}
}
if(aux[i]=='X' and aux[i+t]!='X' and i+t<aux.size()-1){
ans[i]='?';
for(int j=i;j<=i+t;j++)
ans[j]='?';
}
}
return ans;
}
std::string solve_puzzle(std::string s, std::vector<int> c) {
string rp;
rp.resize(s.size());
vector<int>id;
vector<int> p,b;
for(int i=0;i<s.size();i++){
if(s[i]=='_'){
b.push_back(i);
}
}
b.push_back(s.size());
int k=0,l=0,r=0,bl=0;
bl=0;
while(true){
// printf("b[bl]: %d k: %d c[r]: %d l: %d\n", b[bl],k,c[r],l);
if(k>=b[bl]){
bl++;
k++;
}
if(k>=s.size()){
break;
}
if(b[bl]-l>=c[r]){
for(int i=0;i<c[r];i++){
rp[k]='X';
k++;
}
r++;
if(b[bl]-k>=c[r]){
rp[k]='_';
k++;
}
l=k;
}
else{
rp[k]='_';
k++;
l=k;
}
}
for(int i=0;i<rp.size();i++){
if(rp[i]!='X' and rp[i]!='_'){
rp[i]='_';
}
}
// cout<<rp<<endl;
bool sw=0;
b.clear();
int sw1=0;
vector<pair<int,int> >vii;
l=-1;
for(int i=0;i<rp.size();i++){
if(s[i]=='_'){
vii.push_back(pair<int,int>(l+1,i));
l=i;
}
}
rp+='_';
vii.push_back(pair<int,int> (l+1,rp.size()-1));
string ans="";
for(int i=0;i<vii.size();i++){
string aux;
for(int j=vii[i].first;j<=vii[i].second;j++){
aux+=rp[j];
}
ans+=constr(aux);
}
ans.resize(rp.size()-1);
// cout<<ans<<endl;
return ans;
}
Compilation message (stderr)
paint.cpp: In function 'std::__cxx11::string constr(std::__cxx11::string)':
paint.cpp:6:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<aux.size()-1;i++){
~^~~~~~~~~~~~~
paint.cpp:13:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<aux.size();i++){
~^~~~~~~~~~~
paint.cpp:23:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(aux[i]=='X' and aux[i+t]!='X' and i+t<aux.size()-1){
~~~^~~~~~~~~~~~~
paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:36:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();i++){
~^~~~~~~~~
paint.cpp:50:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(k>=s.size()){
~^~~~~~~~~~
paint.cpp:72:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<rp.size();i++){
~^~~~~~~~~~
paint.cpp:83:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<rp.size();i++){
~^~~~~~~~~~
paint.cpp:92:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vii.size();i++){
~^~~~~~~~~~~
paint.cpp:78:10: warning: unused variable 'sw' [-Wunused-variable]
bool sw=0;
^~
paint.cpp:80:9: warning: unused variable 'sw1' [-Wunused-variable]
int sw1=0;
^~~
# | 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... |