답안 #758983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758983 2023-06-15T16:18:39 Z siewjh 길고양이 (JOI20_stray) C++17
20 / 100
38 ms 16432 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;
			steps++;
			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);
      |                                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 15456 KB Output is correct
2 Correct 2 ms 1032 KB Output is correct
3 Correct 23 ms 14828 KB Output is correct
4 Correct 34 ms 16432 KB Output is correct
5 Correct 34 ms 16364 KB Output is correct
6 Correct 27 ms 15280 KB Output is correct
7 Correct 27 ms 15260 KB Output is correct
8 Correct 32 ms 15876 KB Output is correct
9 Correct 32 ms 16060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 15456 KB Output is correct
2 Correct 2 ms 1032 KB Output is correct
3 Correct 23 ms 14828 KB Output is correct
4 Correct 34 ms 16432 KB Output is correct
5 Correct 34 ms 16364 KB Output is correct
6 Correct 27 ms 15280 KB Output is correct
7 Correct 27 ms 15260 KB Output is correct
8 Correct 32 ms 15876 KB Output is correct
9 Correct 32 ms 16060 KB Output is correct
10 Correct 25 ms 13456 KB Output is correct
11 Correct 27 ms 13532 KB Output is correct
12 Correct 26 ms 13436 KB Output is correct
13 Correct 25 ms 13420 KB Output is correct
14 Correct 26 ms 13664 KB Output is correct
15 Correct 27 ms 14036 KB Output is correct
16 Correct 30 ms 15952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13020 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 22 ms 12672 KB Output is correct
4 Correct 32 ms 14380 KB Output is correct
5 Correct 38 ms 14244 KB Output is correct
6 Correct 27 ms 12952 KB Output is correct
7 Correct 26 ms 13032 KB Output is correct
8 Correct 28 ms 13680 KB Output is correct
9 Correct 28 ms 13636 KB Output is correct
10 Correct 27 ms 13492 KB Output is correct
11 Correct 27 ms 13396 KB Output is correct
12 Correct 27 ms 13376 KB Output is correct
13 Correct 31 ms 13420 KB Output is correct
14 Correct 32 ms 13724 KB Output is correct
15 Correct 30 ms 13792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13020 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 22 ms 12672 KB Output is correct
4 Correct 32 ms 14380 KB Output is correct
5 Correct 38 ms 14244 KB Output is correct
6 Correct 27 ms 12952 KB Output is correct
7 Correct 26 ms 13032 KB Output is correct
8 Correct 28 ms 13680 KB Output is correct
9 Correct 28 ms 13636 KB Output is correct
10 Correct 27 ms 13492 KB Output is correct
11 Correct 27 ms 13396 KB Output is correct
12 Correct 27 ms 13376 KB Output is correct
13 Correct 31 ms 13420 KB Output is correct
14 Correct 32 ms 13724 KB Output is correct
15 Correct 30 ms 13792 KB Output is correct
16 Correct 23 ms 11564 KB Output is correct
17 Correct 23 ms 11584 KB Output is correct
18 Correct 25 ms 11560 KB Output is correct
19 Correct 24 ms 11568 KB Output is correct
20 Correct 26 ms 12196 KB Output is correct
21 Correct 28 ms 11876 KB Output is correct
22 Correct 32 ms 13744 KB Output is correct
23 Correct 25 ms 11616 KB Output is correct
24 Correct 24 ms 11564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1292 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 2 ms 1288 KB Output is correct
4 Correct 2 ms 1284 KB Output is correct
5 Correct 2 ms 1280 KB Output is correct
6 Correct 2 ms 1292 KB Output is correct
7 Correct 2 ms 1284 KB Output is correct
8 Correct 2 ms 1284 KB Output is correct
9 Correct 2 ms 1284 KB Output is correct
10 Correct 2 ms 1288 KB Output is correct
11 Correct 2 ms 1264 KB Output is correct
12 Correct 2 ms 1292 KB Output is correct
13 Correct 2 ms 1292 KB Output is correct
14 Correct 2 ms 1284 KB Output is correct
15 Correct 2 ms 1284 KB Output is correct
16 Correct 2 ms 1284 KB Output is correct
17 Correct 2 ms 1220 KB Output is correct
18 Correct 2 ms 1284 KB Output is correct
19 Correct 2 ms 1284 KB Output is correct
20 Correct 2 ms 1292 KB Output is correct
21 Correct 2 ms 1292 KB Output is correct
22 Correct 2 ms 1288 KB Output is correct
23 Correct 2 ms 1284 KB Output is correct
24 Correct 2 ms 1292 KB Output is correct
25 Correct 2 ms 1396 KB Output is correct
26 Correct 2 ms 1292 KB Output is correct
27 Correct 2 ms 1292 KB Output is correct
28 Correct 1 ms 1284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11036 KB Output is correct
2 Correct 26 ms 12252 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 22 ms 11116 KB Output is correct
5 Correct 28 ms 13540 KB Output is correct
6 Correct 31 ms 13540 KB Output is correct
7 Correct 27 ms 12632 KB Output is correct
8 Correct 26 ms 12692 KB Output is correct
9 Correct 30 ms 13544 KB Output is correct
10 Correct 32 ms 13420 KB Output is correct
11 Correct 32 ms 13652 KB Output is correct
12 Correct 31 ms 13580 KB Output is correct
13 Correct 35 ms 13512 KB Output is correct
14 Correct 30 ms 13548 KB Output is correct
15 Correct 28 ms 13540 KB Output is correct
16 Correct 28 ms 13580 KB Output is correct
17 Incorrect 26 ms 13192 KB Wrong Answer [6]
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11064 KB Output is correct
2 Correct 27 ms 12144 KB Output is correct
3 Correct 1 ms 1032 KB Output is correct
4 Correct 23 ms 11136 KB Output is correct
5 Correct 31 ms 13456 KB Output is correct
6 Correct 33 ms 13524 KB Output is correct
7 Incorrect 24 ms 12608 KB Wrong Answer [6]
8 Halted 0 ms 0 KB -