My program seems to work correctly on all tests I tried, including all the tests that could be found in topics of this problem's discussion. Nevertheless, I always have WA #1 when I submit it as a solution, so I guess something is wrong not with the algorithm, but with I/O code. Here it is (I know that the rules of the board deny posting code, but this is only input/output code, no part of algorithm is exposed):
int main(int argc, char **argv){
int n;
std::cin >> n;
Labyrinth lab(n);
for(int i = 0; i < n; i++){
std::string s;
std::getline(std::cin, s);
// strip the last linebreak, if any
if(s[s.length() - 1] == '\n') s.resize(s.length() - 1);
// if the string is empty
// (for example, after reading the
// number from the first line),
// reread it (modifying the current line index)
if(s.length() == 0) { i--; continue; }
for(int j = 0; j < n; j++){
if(s[j] == '#') lab.add_wall_block(j, i);
}
}
std::cout << 9 * lab.total_walls_visible() << std::endl;
return 0;
}
(if the formatting is broken, here is the alternative:
http://itpaste.ru/92461 )
Edited by author 01.10.2010 13:49