# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
829748 | Blagoj | Stray Cat (JOI20_stray) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
#include "Catherine.h"
using namespace std;
namespace {
int A, B;
int went;
string path;
bool wrong;
set<string> valid, invalid;
vector<string> vl, ivl;
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
vl = {"11010", "10100", "01001", "10011", "00110", "01101"};
ivl = {"00101", "10010", "11001", "01100", "10110", "01011"};
for (auto x : vl) valid.insert(x);
for (auto x : ivl) invalid.insert(x);
path = "";
went = 0;
wrong = 0;
}
int Move(vector<int> y) {
// cout << path << " " << went << endl;
if (went && wrong) {
went--;
path.pop_back();
return -1;
}
if (path.size() == 5) {
path = path.substr(1);
}
wrong = 0;
vector<pair<int, int>> total;
for (int i = 0; i < y.size(); i++) {
if (y[i]) total.push_back({y[i], i});
}
if (total.size() == 0) cout << "NIGA";
sort(total.begin(), total.end());
went++;
if (total.size() == 1 || total[0] < total[1]) {
path += to_string(total[0].second);
return total[0].second;
}
if (path.size() + 1 == 5) {
for (int i = 0; i < y.size(); i++) {
if (y[i]) {
string cur = path + to_string(i);
if (invalid.count(cur)) {
wrong = 1;
went -= 2;
return -1;
}
if (valid.count(cur)) {
path += to_string(i);
return i;
}
}
}
}
path += to_string(total[0].second);
return total[0].second;
}