Submission #126036

# Submission time Handle Problem Language Result Execution time Memory
126036 2019-07-06T20:02:09 Z tinder None (JOI16_dungeon2) C++14
95 / 100
32 ms 1532 KB
#include "dungeon2.h"
#include <bits/stdc++.h>
using namespace std;

struct edge {
	int id, l, r;
	edge() {}
	edge(int id, int l, int r) {
		this -> id = id, this -> l = l, this -> r = r;
	}
	bool operator < (const edge &o) const {
		id < o.id;
	}
};

const int maxn = 2e2 + 5;
const int inf = 1e5;

int deg[maxn], pe[maxn];
int dad[maxn], lvl[maxn];
int N, M;
int ptr = 0;
map<int, int> t[maxn];
vector<edge> back[maxn];
int wot[maxn];
int g[maxn][maxn];

int AncAtLvl(int u, int l) {
	assert(lvl[u] > l);
	while(lvl[u] != l) {
		u = dad[u];
	} return u;
}

void add_edge(int u, int v) {
	g[u][v] = g[v][u] = 1;
}

bool allblack(int l, int r) {
	if(l > r) return true;
	return wot[l] and allblack(l + 1, r);
}
bool allwhite(int l, int r) {
	if(l > r) return true;
	return (!wot[l]) and (!allwhite(l + 1, r));
}

void discover(int u, int par) {
	pe[u] = LastRoad();
	dad[u] = par;
	deg[u] = NumberOfRoads();
	lvl[u] = u == 1 ? 0 : lvl[par] + 1;
	for(int i = 1; i <= deg[u]; i++) if(i != pe[u]) {
		Move(i, 2);
		if(Color() == 1) {
			int v = ++ptr;
			add_edge(u, v);
			t[u][v] = i;
			discover(v, u);
		} else {
			if(Color() == 2) {
				back[u].emplace_back(i, 69, 69);
			}
			Move(LastRoad(), Color());
		}
	}
	if(u != 1) {
		Move(pe[u], 3);
	}
}

void dfs(int u) {
	int col = wot[lvl[u]] ? 1 : 2;
	for(edge &e : back[u]) {
		if(e.l == e.r) continue;
		if(allblack(e.l, min(e.r, lvl[u] - 2))) { // left
			e.r = e.l + e.r >> 1;
		} else if(allwhite(e.l, min(e.r, lvl[u] - 2))) { // right
			e.l = (e.l + e.r >> 1) + 1;
		} else {
			Move(e.id, col);
			if(Color() == 1) { // left
				e.r = e.l + e.r >> 1;
			} else { // right
				e.l = (e.l + e.r >> 1) + 1;
			}
			Move(LastRoad(), Color());
		}
	}
	for(auto x : t[u]) {
		Move(x.second, col);
		dfs(x.first);
	}
	if(u != 1) {
		Move(pe[u], 3);
	}
}

void Inspect(int R) {
	for(int i = 1; i <= 200; i++) {
		for(int j = 1; j <= 200; j++) if(i != j) {
			g[i][j] = inf;
		}
	}

	discover(++ptr, -1);

	N = ptr;
	for(int i = 1; i <= N; i++) {
		M += deg[i];
	}
	M >>= 1;

	int mxlvl = 0;
	for(int i = 1; i <= N; i++) {
		mxlvl = max(mxlvl, lvl[i]);
	}

	if(mxlvl == 1) { // predictable graph
		goto solution;
	}

	for(int i = 1; i <= N; i++) {
		for(edge &e : back[i]) {
			e.l = 0, e.r = mxlvl - 2;
		}
	}

	while(true) {
		memset(wot, 0, sizeof wot);
		int cnt = 0;
		for(int i = 1; i <= N; i++) {
			for(edge &e : back[i]) {
				if(e.l == e.r) {
					add_edge(i, AncAtLvl(i, e.l));
				} else {
					int m = e.l + e.r >> 1;
					wot[e.l]++, wot[m + 1]--;
					cnt++;
				}
			}
		}
		if(!cnt) break;
		for(int i = 1; i <= mxlvl; i++) {
			wot[i] += wot[i - 1];
		}
		dfs(1);
	}

#ifdef LOCAL_JUDGE
	for(int i = 1; i <= N; i++) {
		cout << i << " ---> ";
		for(int j = 1; j <= N; j++) {
			if(g[i][j] == 1) {
				cout << j << ' ';
			}
		} cout << endl;
	}
#endif

	solution : ;

	for(int k = 1; k <= N; k++) {
		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= N; j++) {
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
			}
		}
	}

	int ans[maxn];
	memset(ans, 0, sizeof ans);
	for(int i = 1; i <= N; i++) {
		for(int j = i + 1; j <= N; j++) {
			ans[g[i][j]]++;
		}
	}

	for(int i = 1; i <= R; i++) {
		Answer(i, ans[i]);
	}
}

Compilation message

dungeon2.cpp: In member function 'bool edge::operator<(const edge&) const':
dungeon2.cpp:12:6: warning: statement has no effect [-Wunused-value]
   id < o.id;
   ~~~^~~~~~
dungeon2.cpp:13:2: warning: no return statement in function returning non-void [-Wreturn-type]
  }
  ^
dungeon2.cpp: In function 'void dfs(int)':
dungeon2.cpp:77:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    e.r = e.l + e.r >> 1;
          ~~~~^~~~~
dungeon2.cpp:79:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    e.l = (e.l + e.r >> 1) + 1;
           ~~~~^~~~~
dungeon2.cpp:83:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     e.r = e.l + e.r >> 1;
           ~~~~^~~~~
dungeon2.cpp:85:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     e.l = (e.l + e.r >> 1) + 1;
            ~~~~^~~~~
dungeon2.cpp: In function 'void Inspect(int)':
dungeon2.cpp:137:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
      int m = e.l + e.r >> 1;
              ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 888 KB Output is correct
2 Partially correct 12 ms 888 KB Partially correct
3 Partially correct 13 ms 888 KB Partially correct
4 Partially correct 32 ms 1528 KB Partially correct
5 Partially correct 3 ms 632 KB Partially correct
6 Partially correct 5 ms 760 KB Partially correct
7 Partially correct 12 ms 888 KB Partially correct
8 Correct 12 ms 888 KB Output is correct
9 Correct 12 ms 1016 KB Output is correct
10 Partially correct 12 ms 888 KB Partially correct
11 Partially correct 12 ms 888 KB Partially correct
12 Partially correct 12 ms 1020 KB Partially correct
13 Partially correct 15 ms 1016 KB Partially correct
14 Correct 12 ms 892 KB Output is correct
15 Partially correct 12 ms 888 KB Partially correct
16 Partially correct 7 ms 888 KB Partially correct
17 Partially correct 31 ms 1528 KB Partially correct
18 Partially correct 30 ms 1532 KB Partially correct
19 Partially correct 30 ms 1528 KB Partially correct