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 <bits/stdc++.h>
using namespace std;
ifstream in("file.in");
void rewrite(int poz, int last, char c, string &s)
{
for (int i = poz - last + 1; i <= poz; i++)
s[i] = c;
}
string solve_puzzle(string s, vector<int> c)
{
int n = s.length(), k = c.size();
string ans;
vector<pair<int,int>> range(k);
ans.assign(n, '_');
int l = 0, poz = 0;
//left range (min range)
for (int i = 0; i < n && poz < k; i++)
{
if (s[i] == '_')
l = 0;
else
l++;
if (l == c[poz])
{
range[poz].first = i + 1 - l;
l = 0;
i++; poz++;
}
}
//right range (max range)
l = 0;
poz = k - 1;
for (int i = n - 1; i >= 0 && poz >= 0; i--)
{
if (s[i] == '_')
l = 0;
else
l++;
if (l == c[poz])
{
range[poz].second = i + l - 1;
l = 0;
i--; poz--;
}
}
for (int i = 0; i < k; i++)
{
l = 0;
for (int j = range[i].first; j <= range[i].second; j++)
{
if (s[j] == '_')
{
if (l < c[i])
rewrite(j, l, '_', ans);
l = 0;
continue;
}
l++;
if (l == c[i])
rewrite(j, l, '?', ans);
if (l > c[i])
ans[j] = '?';
}
int same = c[i] - (range[i].second - range[i].first + 1 - c[i]);
for (int j = range[i].first + c[i] - 1; j >= range[i].first; j--)
{
if (same <= 0)
break;
ans[j] = 'X';
same--;
}
}
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... |