Result: 0/10 xsxssssssx (why were there signals?)
I have given up on this one. As a result, I just submitted code that will return C, in hopes that no boxes are formed by the fences for as many test cases as possible.
C++ solutions, both training and real, are posted when possible; they are provided for reference purposes only.
Showing posts with label contest-2012. Show all posts
Showing posts with label contest-2012. Show all posts
Tuesday, December 18, 2012
December 2012 Bronze Problem 2: Scrambled Letters
Result: 1/10 *xxxxxtttt (5 wrong answers, 4 timeouts)
Wednesday, November 21, 2012
November 2012 Bronze Problem 3: Horseshoes
Result: 8/10 **x***x*** (2 wrong answers)
hshoe.cpp
hshoe.cpp
#include <iostream>
#include <fstream>
#include <string>
#define loopi(x) loopi_start(x,0)
#define loopi_start(x,s) for(int i = (s); i < (x); ++i)
#define loop_rev(a,x,stop) for(int a = (x); a >= (stop); --a)
using namespace std;
int N, first_max;
int maxlen(string str, int pos, int first = 0, int second = 0, bool starting = true){
if(starting && str[pos] != ')'){
if(str[pos] == '('){
if(++first > N * N / 2) return 0; // too long
}
else return 0; // fail (already there)
}
else{
if(str[pos] != ')') return 0; // fail
if(++second >= first) return first + second; // completed path
starting = false;
}
// keep going
str[pos] = ' ';
int best = 0;
// left
if(pos % N) best = max(best, maxlen(str, pos - 1, first, second, starting));
// right
if(pos % N < N - 1 && pos < N * N - 1) best = max(best, maxlen(str, pos + 1, first, second, starting));
// up
if(pos >= N) best = max(best, maxlen(str, pos - N, first, second, starting));
// down
if(pos < N * (N - 1) - 1) best = max(best, maxlen(str, pos + N, first, second, starting));
return best;
}
int main() {
ofstream fout ("hshoe.out");
ifstream fin("hshoe.in");
// get input
fin >> N;
first_max = N * N / 2; // and it is truncated down anyways
string str;
loopi(N){
string tmp;
fin >> tmp;
str += tmp;
}
// process
int max_length = maxlen(str, 0);
// output
fout << max_length << '\n';
// cleanup
fin.close();
fout.close();
return 0;
}
Tuesday, November 20, 2012
November 2012 Bronze Problem 1: Find the Cow!
The contest has ended! I have posted the first solution now.
Result: 9/10 *********t (timeout)
cowfind.cpp
Result: 9/10 *********t (timeout)
cowfind.cpp
Subscribe to:
Posts (Atom)