# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395011 | idk321 | Paint By Numbers (IOI16_paint) | C++11 | 1 ms | 300 KiB |
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 <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
std::string solve_puzzle(std::string s, std::vector<int> c) {
string res = s;
if (s.size() == 1)
{
if (s != ".") return s;
return "?";
}
vector<int> type;
type.push_back(0);
for (int i = 0; i< c.size(); i++)
{
for (int j = 0; j < c[i]; j++)
{
if (j == c[i] - 1) type.push_back(2);
else if (j == 0) type.push_back(3);
else type.push_back(1);
}
type.push_back(0);
}
int n = s.size();
vector<vector<bool>> right(n, vector<bool>(type.size()));
if (s[0] == 'X')
{
right[0][1] = true;
} else if (s[0] == '_')
{
right[0][0] = true;
} else
{
right[0][0] = true;
right[0][1] = true;
}
for (int i = 1; i < n; i++)
{
for (int j = 0; j < right[i - 1].size(); j++)
{
if (right[i - 1][j])
{
if (type[j] == 0)
{
if (s[i] == 'X')
{
if (j + 1 != type.size()) right[i][j + 1] = true;
} else if (s[i] == '_')
{
right[i][j] = true;
} else
{
if (j + 1 != type.size()) right[i][j + 1] = true;
right[i][j] = true;
}
} else if (type[j] == 2)
{
if (s[i] == 'X')
{
} else if (s[i] == '_')
{
right[i][j + 1] = true;
} else
{
right[i][j + 1] = true;
}
} else
{
if (s[i] == 'X')
{
right[i][j + 1] = true;
} else if (s[i] == '_')
{
} else
{
right[i][j + 1] = true;
}
}
}
}
}
vector<vector<bool>> left(n, vector<bool>(type.size()));
if (s[n - 1] == 'X')
{
left[n - 1][type.size() - 2] = true;
} else if (s[0] == '_')
{
left[n - 1][type.size() - 1] = true;
} else
{
left[n - 1][type.size() - 1] = true;
left[n - 1][type.size() - 2] = true;
}
for (int i = n - 2; i >= 0; i--)
{
for (int j = 0; j < right[i + 1].size(); j++)
{
if (left[i + 1][j])
{
if (type[j] == 0)
{
if (s[i] == 'X')
{
if (j - 1 >= 0) left[i][j - 1] = true;
} else if (s[i] == '_')
{
left[i][j] = true;
} else
{
if (j - 1 >= 0) left[i][j - 1] = true;
left[i][j] = true;
}
} else if (type[j] == 3)
{
if (s[i] == 'X')
{
} else if (s[i] == '_')
{
left[i][j - 1] = true;
} else
{
left[i][j - 1] = true;
}
} else
{
if (s[i] == 'X')
{
left[i][j - 1] = true;
} else if (s[i] == '_')
{
} else
{
left[i][j - 1] = true;
}
}
}
}
}
vector<bool> poss1(n);
vector<bool> poss2(n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < type.size(); j++)
{
if (left[i][j] && right[i][j])
{
if (type[j] == 0) poss1[i] = true;
else poss2[i] = true;
}
}
}
for (int i = 0; i < n; i++)
{
if (poss2[i] && poss1[i])
{
res[i] = '?';
} else if (poss2[i]) res[i] = 'X';
else res[i] = '_';
}
return res;
}
Compilation message (stderr)
# | 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... |