# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
758979 |
2023-06-15T16:10:34 Z |
siewjh |
Stray Cat (JOI20_stray) |
C++17 |
|
35 ms |
16968 KB |
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
const int MAXN = 20005;
vector<pair<int, int>> adj[MAXN];
vector<int> marking;
int cyc[6] = {0, 0, 1, 0, 1, 1};
void dfs(int x, int par, int cind){
if (par != -1 && adj[x].size() >= 3){
int prv = cyc[(cind + 5) % 6];
if (prv == 0) cind = 5;
else cind = 0;
}
for (auto nxt : adj[x]){
int nn = nxt.first, edge = nxt.second;
if (nn == par) continue;
marking[edge] = cyc[cind];
dfs(nn, x, (cind + 1) % 6);
}
}
}
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) {
for (int i = 0; i < M; i++){
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
marking.resize(M);
if (A >= 3){
vector<int> dist(N, -1);
dist[0] = 0;
queue<int> q;
q.push(0);
while (!q.empty()){
int x = q.front(); q.pop();
for (auto nxt : adj[x]){
int nn = nxt.first, edge = nxt.second;
if (dist[nn] != -1){
if (dist[nn] == dist[x] - 1) continue; // already marked
else marking[edge] = dist[x] % 3;
}
else{
marking[edge] = dist[x] % 3;
dist[nn] = dist[x] + 1;
q.push(nn);
}
}
}
}
else{
dfs(0, -1, 0);
}
return marking;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int A, B;
int steps = 0; // 0 to 3 -> first steps, -1 -> straight up
int prv = -1; // previous edge
int seq = 0; // 5 digit sequence
set<int> ok;
}
void Init(int A, int B) {
::A = A;
::B = B;
// up: 11010, 10100, 01001, 10011, 00110, 01101
ok = {26, 20, 9, 19, 6, 13};
}
int Move(vector<int> y){
if (A >= 3){
int types = 0;
for (int i = 0; i < 3; i++)
if (y[i])
types++;
if (types == 1){
for (int i = 0; i < 3; i++)
if (y[i])
return i;
}
else{ // types == 2
for (int i = 0; i < 3; i++)
if (!y[i])
return (i + 1) % 3;
}
return -1; // will never happen
}
else{
if (y[0] == 0 && y[1] == 0){ // dead end
steps = -1; // prv unchanged
return -1;
}
else if (y[0] + y[1] + (prv != -1) >= 3){ // deg >= 3
steps = -1;
int y0 = y[0] + (prv == 0), y1 = y[1] + (prv == 1);
if (y0 == 1){
int ret = ((prv == 0) ? -1 : 0);
prv = 0;
return ret;
}
else{
int ret = ((prv == 1) ? -1 : 1);
prv = 1;
return ret;
}
}
else if (steps == -1){ // go up
if (y[0]) return prv = 0;
else return prv = 1;
}
else if (steps == 0){
int go, other;
if (y[0]){
go = 0;
if (y[1]) other = 1; else other = 0;
}
else go = other = 1;
prv = go;
seq = (other << 1) + go;
return go;
}
else if (steps < 3){
int go;
if (y[0]) go = 0; else go = 1;
prv = go;
seq = (seq << 1) + go;
return go;
}
else{ // see if we are going correct direction
int nxt;
if (y[0]) nxt = 0; else nxt = 1;
seq = (seq << 1) + nxt;
steps = -1;
if (ok.count(seq)){ // continue
return prv = nxt;
}
else return -1;
}
}
}
Compilation message
Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:45:32: warning: unused variable 'y1' [-Wunused-variable]
45 | int y0 = y[0] + (prv == 0), y1 = y[1] + (prv == 1);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
15948 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
24 ms |
15252 KB |
Output is correct |
4 |
Correct |
35 ms |
16968 KB |
Output is correct |
5 |
Correct |
34 ms |
16920 KB |
Output is correct |
6 |
Correct |
28 ms |
15612 KB |
Output is correct |
7 |
Correct |
27 ms |
15668 KB |
Output is correct |
8 |
Correct |
35 ms |
16288 KB |
Output is correct |
9 |
Correct |
32 ms |
16332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
15948 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
24 ms |
15252 KB |
Output is correct |
4 |
Correct |
35 ms |
16968 KB |
Output is correct |
5 |
Correct |
34 ms |
16920 KB |
Output is correct |
6 |
Correct |
28 ms |
15612 KB |
Output is correct |
7 |
Correct |
27 ms |
15668 KB |
Output is correct |
8 |
Correct |
35 ms |
16288 KB |
Output is correct |
9 |
Correct |
32 ms |
16332 KB |
Output is correct |
10 |
Correct |
26 ms |
13808 KB |
Output is correct |
11 |
Correct |
25 ms |
13808 KB |
Output is correct |
12 |
Correct |
26 ms |
13872 KB |
Output is correct |
13 |
Correct |
26 ms |
13904 KB |
Output is correct |
14 |
Correct |
26 ms |
14140 KB |
Output is correct |
15 |
Correct |
27 ms |
14460 KB |
Output is correct |
16 |
Correct |
31 ms |
16452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
13424 KB |
Output is correct |
2 |
Correct |
1 ms |
1088 KB |
Output is correct |
3 |
Correct |
22 ms |
12992 KB |
Output is correct |
4 |
Correct |
32 ms |
14764 KB |
Output is correct |
5 |
Correct |
32 ms |
14700 KB |
Output is correct |
6 |
Correct |
26 ms |
13496 KB |
Output is correct |
7 |
Correct |
26 ms |
13364 KB |
Output is correct |
8 |
Correct |
32 ms |
14152 KB |
Output is correct |
9 |
Correct |
31 ms |
14016 KB |
Output is correct |
10 |
Correct |
27 ms |
13828 KB |
Output is correct |
11 |
Correct |
27 ms |
13764 KB |
Output is correct |
12 |
Correct |
27 ms |
13816 KB |
Output is correct |
13 |
Correct |
33 ms |
13796 KB |
Output is correct |
14 |
Correct |
30 ms |
14072 KB |
Output is correct |
15 |
Correct |
34 ms |
14208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
13424 KB |
Output is correct |
2 |
Correct |
1 ms |
1088 KB |
Output is correct |
3 |
Correct |
22 ms |
12992 KB |
Output is correct |
4 |
Correct |
32 ms |
14764 KB |
Output is correct |
5 |
Correct |
32 ms |
14700 KB |
Output is correct |
6 |
Correct |
26 ms |
13496 KB |
Output is correct |
7 |
Correct |
26 ms |
13364 KB |
Output is correct |
8 |
Correct |
32 ms |
14152 KB |
Output is correct |
9 |
Correct |
31 ms |
14016 KB |
Output is correct |
10 |
Correct |
27 ms |
13828 KB |
Output is correct |
11 |
Correct |
27 ms |
13764 KB |
Output is correct |
12 |
Correct |
27 ms |
13816 KB |
Output is correct |
13 |
Correct |
33 ms |
13796 KB |
Output is correct |
14 |
Correct |
30 ms |
14072 KB |
Output is correct |
15 |
Correct |
34 ms |
14208 KB |
Output is correct |
16 |
Correct |
25 ms |
12040 KB |
Output is correct |
17 |
Correct |
23 ms |
11980 KB |
Output is correct |
18 |
Correct |
25 ms |
11900 KB |
Output is correct |
19 |
Correct |
24 ms |
11932 KB |
Output is correct |
20 |
Correct |
27 ms |
12560 KB |
Output is correct |
21 |
Correct |
25 ms |
12336 KB |
Output is correct |
22 |
Correct |
28 ms |
14284 KB |
Output is correct |
23 |
Correct |
31 ms |
12120 KB |
Output is correct |
24 |
Correct |
26 ms |
12116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1336 KB |
Output is correct |
2 |
Correct |
1 ms |
1028 KB |
Output is correct |
3 |
Correct |
1 ms |
1288 KB |
Output is correct |
4 |
Correct |
2 ms |
1416 KB |
Output is correct |
5 |
Correct |
2 ms |
1292 KB |
Output is correct |
6 |
Correct |
2 ms |
1336 KB |
Output is correct |
7 |
Correct |
2 ms |
1296 KB |
Output is correct |
8 |
Correct |
2 ms |
1288 KB |
Output is correct |
9 |
Correct |
2 ms |
1296 KB |
Output is correct |
10 |
Correct |
2 ms |
1292 KB |
Output is correct |
11 |
Correct |
2 ms |
1396 KB |
Output is correct |
12 |
Correct |
2 ms |
1288 KB |
Output is correct |
13 |
Correct |
2 ms |
1336 KB |
Output is correct |
14 |
Correct |
2 ms |
1288 KB |
Output is correct |
15 |
Correct |
2 ms |
1300 KB |
Output is correct |
16 |
Correct |
2 ms |
1296 KB |
Output is correct |
17 |
Correct |
2 ms |
1340 KB |
Output is correct |
18 |
Correct |
1 ms |
1288 KB |
Output is correct |
19 |
Correct |
2 ms |
1296 KB |
Output is correct |
20 |
Correct |
2 ms |
1292 KB |
Output is correct |
21 |
Correct |
2 ms |
1336 KB |
Output is correct |
22 |
Correct |
2 ms |
1288 KB |
Output is correct |
23 |
Correct |
2 ms |
1292 KB |
Output is correct |
24 |
Correct |
2 ms |
1284 KB |
Output is correct |
25 |
Correct |
2 ms |
1288 KB |
Output is correct |
26 |
Correct |
2 ms |
1372 KB |
Output is correct |
27 |
Correct |
2 ms |
1288 KB |
Output is correct |
28 |
Correct |
2 ms |
1288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
11524 KB |
Output is correct |
2 |
Correct |
27 ms |
12672 KB |
Output is correct |
3 |
Correct |
1 ms |
1036 KB |
Output is correct |
4 |
Correct |
20 ms |
11312 KB |
Output is correct |
5 |
Correct |
31 ms |
14000 KB |
Output is correct |
6 |
Correct |
31 ms |
14008 KB |
Output is correct |
7 |
Correct |
26 ms |
13120 KB |
Output is correct |
8 |
Correct |
27 ms |
13044 KB |
Output is correct |
9 |
Correct |
30 ms |
13984 KB |
Output is correct |
10 |
Correct |
31 ms |
14008 KB |
Output is correct |
11 |
Correct |
30 ms |
13944 KB |
Output is correct |
12 |
Correct |
30 ms |
14024 KB |
Output is correct |
13 |
Correct |
30 ms |
13940 KB |
Output is correct |
14 |
Correct |
30 ms |
13992 KB |
Output is correct |
15 |
Correct |
30 ms |
13976 KB |
Output is correct |
16 |
Correct |
30 ms |
14020 KB |
Output is correct |
17 |
Incorrect |
27 ms |
13664 KB |
Wrong Answer [6] |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
11524 KB |
Output is correct |
2 |
Correct |
26 ms |
12428 KB |
Output is correct |
3 |
Correct |
1 ms |
976 KB |
Output is correct |
4 |
Correct |
20 ms |
11480 KB |
Output is correct |
5 |
Correct |
30 ms |
14016 KB |
Output is correct |
6 |
Correct |
32 ms |
13888 KB |
Output is correct |
7 |
Incorrect |
24 ms |
13120 KB |
Wrong Answer [6] |
8 |
Halted |
0 ms |
0 KB |
- |