# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395030 | idk321 | Paint By Numbers (IOI16_paint) | C++11 | 294 ms | 524292 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 "X";
}
vector<int> type;
type.push_back(0);
for (int i = 0; i< c.size(); i++)
{
for (int j = 0; j < c[i]; j++)
{
int cur = 1;
if (j == c[i] - 1) cur *= 2;
if (j == 0) cur *= 3;
type.push_back(cur);
}
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 == 0)
{
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[n - 1] == '_')
{
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 == 0)
{
if (s[i] == 'X')
{
} else if (s[i] == '_')
{
left[i][j - 1] = true;
} else
{
left[i][j - 1] = true;
}
} else
{
if (s[i] == 'X')
{
//if (i == 2) cout << "Oj " << " "<< type[j]<< " " << type[j - 1]<< " " <<j <<endl;
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] = '_';
}
/*
for (int i = 0; i < n; i++)
{
for (int j = 0; j < type.size(); j++)
{
if (right[i][j]) cout << i << " "<< j << endl;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < type.size(); j++)
{
if (left[i][j]) cout << i << " "<< j << " " << type[j] << endl;
}
} */
return res;
}
/*
..X._..X.
3 2 1 2
*/
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... |