# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
788150 |
2023-07-19T20:24:05 Z |
Boas |
Stray Cat (JOI20_stray) |
C++17 |
|
2031 ms |
15768 KB |
#include "Anthony.h"
#include <bits/stdc++.h>
namespace
{
int a, m;
}
using namespace std;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V)
{
a = A;
m = M;
vector<int> X(M, -1);
vector<int> graad(N);
for (int i : U)
graad[i]++;
for (int i : V)
graad[i]++;
queue<tuple<int, int, vector<int>>> q;
q.push({0, A - 1, {}});
vector<vi> lijnen;
while (!q.empty())
{
auto [i, mark, lijn] = q.front();
q.pop();
for (int j = 0; j < m; j++)
{
if (X[j] != -1)
continue;
if (U[j] == i)
{
// cerr << "Road from " << i << " to " << V[j] << " gets mark " << mark << endl;
X[j] = mark;
if (graad[i] != 2)
lijn.clear();
if (A == 2 && i != 0 && graad[i] == 2)
{
vi newLijn(lijn);
newLijn.push_back(j);
if (graad[V[j]] != 2 && newLijn.size() > 3)
{
lijnen.push_back(newLijn);
}
q.push({V[j], (mark - 1 + a) % a, newLijn});
}
else
q.push({V[j], (mark - 1 + a) % a, lijn});
}
else if (V[j] == i)
{
// cerr << "Road from " << i << " to " << U[j] << " gets mark " << mark << endl;
X[j] = mark;
if (graad[i] != 2)
lijn.clear();
if (A == 2 && i != 0 && graad[i] == 2)
{
vi newLijn(lijn);
newLijn.push_back(j);
if (graad[U[j]] != 2 && newLijn.size() > 3)
{
lijnen.push_back(newLijn);
}
q.push({U[j], (mark - 1 + a) % a, newLijn});
}
else
q.push({U[j], (mark - 1 + a) % a, lijn});
}
}
}
vi pattern = {0, 0, 1, 0, 1, 1};
for (const auto &lijn : lijnen)
{
if (lijn.size() < 4)
continue;
for (uint32_t i = 0; i < lijn.size(); i++)
{
int mark = pattern[i % 6];
// cerr << "Lijn van " << U[lijn[i]] << " naar " << V[lijn[i]] << " krijgt mark " << mark << endl;
X[lijn[i]] = mark;
}
}
return X;
}
#include "Catherine.h"
#include <vector>
#include <map>
#include <iostream>
using namespace std;
typedef vector<int> vi;
namespace
{
vi prevMarks;
int A, B;
int prevMark = -1;
} // namespace
void Init(int A, int B)
{
::A = A;
::B = B;
prevMarks.clear();
prevMark = -1;
}
int calculateMove(vi &y)
{
vector<int> leastOccurences = {};
int least = (1 << 30);
map<int, int> occurences;
if (A == 2 && prevMark != -1)
{
y[prevMark]++;
}
for (int j = 0; j < A; ++j)
{
if (y[j] > 0)
{
if (y[j] < least)
{
least = y[j];
leastOccurences = {j};
}
else if (y[j] == least)
{
leastOccurences.push_back(j);
}
occurences[j] = y[j];
}
}
if (A > 2)
{
if (occurences.find(A - 1) != occurences.end() && occurences.find(0) != occurences.end())
{
return 0;
}
int max = 0;
for (const auto &[j, c] : occurences)
{
max = std::max(j, max);
}
return max;
}
if (leastOccurences.size() == 0)
{
throw;
return -1;
}
if (leastOccurences.size() == 1)
{
if (leastOccurences[0] == prevMark && y[leastOccurences[0]] == 1)
{
prevMarks.clear();
return -1;
}
return leastOccurences[0];
}
if (leastOccurences.size() == 2)
{
// extra code for long straight lines with A = 2
for (int i : leastOccurences)
{
if (i != prevMark) // when prevMark == -1, the 0 size is chosen
return i;
}
}
throw;
}
int Move(vi y)
{
int sum = 0;
for (int v : y)
sum += v;
int mark = calculateMove(y);
if (A == 2 && sum == 1)
{
prevMarks.push_back(mark);
int s = prevMarks.size();
if (s > 3)
{
const vector<vi> turnAroundMarks = {
{0, 0, 1, 0},
{0, 1, 0, 1},
{1, 0, 1, 1},
{1, 1, 0, 0}};
for (const auto &seq : turnAroundMarks)
{
for (int d = 0; d <= (int)turnAroundMarks.size() - 4; d++)
{
bool allEqual = true;
for (int i = 0; i < 4; i++)
{
if (seq[i] != prevMarks[i + d])
{
allEqual = false;
break;
}
}
if (allEqual)
{
prevMarks.clear();
return prevMark = -1;
}
}
}
}
}
else
prevMarks.clear();
return prevMark = mark;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1722 ms |
14696 KB |
Output is correct |
2 |
Correct |
1 ms |
520 KB |
Output is correct |
3 |
Correct |
1051 ms |
14188 KB |
Output is correct |
4 |
Correct |
1738 ms |
15768 KB |
Output is correct |
5 |
Correct |
1703 ms |
15720 KB |
Output is correct |
6 |
Correct |
1722 ms |
14472 KB |
Output is correct |
7 |
Correct |
1702 ms |
14324 KB |
Output is correct |
8 |
Correct |
1703 ms |
15092 KB |
Output is correct |
9 |
Correct |
1706 ms |
15096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1722 ms |
14696 KB |
Output is correct |
2 |
Correct |
1 ms |
520 KB |
Output is correct |
3 |
Correct |
1051 ms |
14188 KB |
Output is correct |
4 |
Correct |
1738 ms |
15768 KB |
Output is correct |
5 |
Correct |
1703 ms |
15720 KB |
Output is correct |
6 |
Correct |
1722 ms |
14472 KB |
Output is correct |
7 |
Correct |
1702 ms |
14324 KB |
Output is correct |
8 |
Correct |
1703 ms |
15092 KB |
Output is correct |
9 |
Correct |
1706 ms |
15096 KB |
Output is correct |
10 |
Correct |
1651 ms |
12716 KB |
Output is correct |
11 |
Correct |
1652 ms |
12620 KB |
Output is correct |
12 |
Correct |
1703 ms |
12504 KB |
Output is correct |
13 |
Correct |
1700 ms |
12508 KB |
Output is correct |
14 |
Correct |
1696 ms |
12740 KB |
Output is correct |
15 |
Correct |
1700 ms |
13136 KB |
Output is correct |
16 |
Correct |
1719 ms |
15208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1769 ms |
12124 KB |
Output is correct |
2 |
Correct |
1 ms |
520 KB |
Output is correct |
3 |
Correct |
1664 ms |
12032 KB |
Output is correct |
4 |
Correct |
1714 ms |
13448 KB |
Output is correct |
5 |
Correct |
1723 ms |
13436 KB |
Output is correct |
6 |
Correct |
1708 ms |
12260 KB |
Output is correct |
7 |
Correct |
1700 ms |
12160 KB |
Output is correct |
8 |
Correct |
1722 ms |
12768 KB |
Output is correct |
9 |
Correct |
1714 ms |
12760 KB |
Output is correct |
10 |
Correct |
1740 ms |
12572 KB |
Output is correct |
11 |
Correct |
1738 ms |
12504 KB |
Output is correct |
12 |
Correct |
1694 ms |
12560 KB |
Output is correct |
13 |
Correct |
1716 ms |
12508 KB |
Output is correct |
14 |
Correct |
1759 ms |
12876 KB |
Output is correct |
15 |
Correct |
1708 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1769 ms |
12124 KB |
Output is correct |
2 |
Correct |
1 ms |
520 KB |
Output is correct |
3 |
Correct |
1664 ms |
12032 KB |
Output is correct |
4 |
Correct |
1714 ms |
13448 KB |
Output is correct |
5 |
Correct |
1723 ms |
13436 KB |
Output is correct |
6 |
Correct |
1708 ms |
12260 KB |
Output is correct |
7 |
Correct |
1700 ms |
12160 KB |
Output is correct |
8 |
Correct |
1722 ms |
12768 KB |
Output is correct |
9 |
Correct |
1714 ms |
12760 KB |
Output is correct |
10 |
Correct |
1740 ms |
12572 KB |
Output is correct |
11 |
Correct |
1738 ms |
12504 KB |
Output is correct |
12 |
Correct |
1694 ms |
12560 KB |
Output is correct |
13 |
Correct |
1716 ms |
12508 KB |
Output is correct |
14 |
Correct |
1759 ms |
12876 KB |
Output is correct |
15 |
Correct |
1708 ms |
12892 KB |
Output is correct |
16 |
Correct |
1985 ms |
10912 KB |
Output is correct |
17 |
Correct |
2031 ms |
10840 KB |
Output is correct |
18 |
Correct |
1748 ms |
10584 KB |
Output is correct |
19 |
Correct |
1726 ms |
10584 KB |
Output is correct |
20 |
Correct |
1694 ms |
11216 KB |
Output is correct |
21 |
Correct |
1692 ms |
10912 KB |
Output is correct |
22 |
Correct |
1696 ms |
13020 KB |
Output is correct |
23 |
Correct |
1690 ms |
10720 KB |
Output is correct |
24 |
Correct |
1706 ms |
10728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
780 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
872 KB |
Output is correct |
4 |
Correct |
3 ms |
900 KB |
Output is correct |
5 |
Correct |
3 ms |
900 KB |
Output is correct |
6 |
Correct |
3 ms |
900 KB |
Output is correct |
7 |
Correct |
3 ms |
900 KB |
Output is correct |
8 |
Correct |
3 ms |
912 KB |
Output is correct |
9 |
Correct |
3 ms |
864 KB |
Output is correct |
10 |
Correct |
3 ms |
900 KB |
Output is correct |
11 |
Correct |
3 ms |
908 KB |
Output is correct |
12 |
Correct |
3 ms |
900 KB |
Output is correct |
13 |
Correct |
3 ms |
864 KB |
Output is correct |
14 |
Correct |
2 ms |
908 KB |
Output is correct |
15 |
Correct |
3 ms |
900 KB |
Output is correct |
16 |
Correct |
2 ms |
772 KB |
Output is correct |
17 |
Correct |
2 ms |
780 KB |
Output is correct |
18 |
Correct |
3 ms |
772 KB |
Output is correct |
19 |
Correct |
2 ms |
780 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
3 ms |
840 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
3 ms |
772 KB |
Output is correct |
24 |
Correct |
3 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
868 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
2 ms |
772 KB |
Output is correct |
28 |
Incorrect |
3 ms |
772 KB |
Wrong Answer [6] |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1704 ms |
10628 KB |
Output is correct |
2 |
Incorrect |
1689 ms |
10556 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1726 ms |
10440 KB |
Output is correct |
2 |
Incorrect |
1694 ms |
10512 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |