제출 #105947

#제출 시각아이디문제언어결과실행 시간메모리
105947luciocf경찰관과 강도 (BOI14_coprobber)C++14
16 / 100
48 ms2808 KiB
#include <bits/stdc++.h> #include "coprobber.h" #define ff first #define ss second using namespace std; const int maxn = 510; typedef pair<int, int> pii; int n, U=0; // ------ TREE STUFF ------- int dist[maxn][maxn]; bool isTree; vector<int> grafo[maxn]; // ------------------------- // ------ GRID STUFF ------- int ind[maxn][maxn]; bool moveDown; pii pos[maxn]; // ------------------------- bool checkTree(void) { int deg = 0; for (int i = 0; i < n; i++) deg += (int)grafo[i].size(); return (deg == 2*(n-1)); } void bfs(int s) { queue<int> fila; dist[s][s] = 0; fila.push(s); while (!fila.empty()) { int u = fila.front(); fila.pop(); for (auto v: grafo[u]) { if (dist[s][v] != -1) continue; dist[s][v] = dist[s][u]+1; fila.push(v); } } } int moveTree(int R) { for (auto v: grafo[U]) { if (dist[v][R] == dist[U][R]-1) { U = v; return v; } } } int start(int N, bool A[MAX_N][MAX_N]) { n = N; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (A[i][j]) grafo[i].push_back(j); isTree = checkTree(); if (isTree) { memset(dist, -1, sizeof dist); for (int i = 0; i < n; i++) bfs(i); return 0; } int x = 0, y = 0; pos[0] = {x, y}, ind[x][y] = 0; for (int i = 1; i < n; i++) { if (!A[i][i-1]) y++, x = 0; else x++; pos[i] = {x, y}, ind[x][y] = i; } return 0; } int nextMove(int R) { if (isTree) return moveTree(R); if (abs(pos[U].ff-pos[R].ff)+abs(pos[U].ss-pos[R].ss) == 2) return U; if (pos[U].ff == pos[R].ff || moveDown) { moveDown = 0; if (pos[U].ss+1 == pos[R].ss) return ind[pos[U].ff][pos[U].ss+1]; return ind[pos[U].ff][pos[U].ss-1]; } if (pos[U].ff != pos[R].ff && !moveDown) { if (pos[U].ff+1 == pos[R].ff || pos[U].ff-1 == pos[R].ff) moveDown = 1; if (pos[U].ff < pos[R].ff) return ind[pos[U].ff+1][pos[U].ss]; return ind[pos[U].ff-1][pos[U].ss]; } }

컴파일 시 표준 에러 (stderr) 메시지

coprobber.cpp: In function 'int moveTree(int)':
coprobber.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
coprobber.cpp: In function 'int nextMove(int)':
coprobber.cpp:129:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...