Search found 14 matches

by alexiago
Fri Oct 02, 2015 9:00 pm
Forum: Volume 1 (100-199)
Topic: 153 - Permalex
Replies: 32
Views: 12956

Re: 153 - Permalex

I have tested every input I found for this problem but I'm still getting WA. Anyone has any idea what's wrong?

Code: Select all

Removed after ACC
I was computing a straight factorial and I figured the problem requires a little tuning to avoid an overflow.
by alexiago
Tue Oct 08, 2013 10:45 pm
Forum: Volume 117 (11700-11799)
Topic: 11716 - Digital Fortress
Replies: 39
Views: 11115

Re: 11716 - Digital Fortress

Using BufferedReader/BufferedWriter made a difference. Thank you brianfry713
by alexiago
Tue Oct 08, 2013 7:23 pm
Forum: Volume 117 (11700-11799)
Topic: 11716 - Digital Fortress
Replies: 39
Views: 11115

Re: 11716 - Digital Fortress

I passed the algorithm below in C++ but I'm getting TLE in Java, everyone knows that Java can be slower but I was wondering what's causing this. Maybe reading lines as strings and using charAt? Maybe the Math.sqrt function? Any ideas?

Code: Select all

Removed after AC, used BufferedReader/BufferedWriter
by alexiago
Wed Oct 02, 2013 11:04 pm
Forum: Volume 114 (11400-11499)
Topic: 11475 - Extend to Palindrome
Replies: 32
Views: 13896

Re: 11475 - Extend to Palindromes

I got it, my approach can add characters to the middle of the string (even though my algorithm could result in a smaller palindrome string, for your input my code returns ababa instead of abaaba). Thank you.
by alexiago
Mon Sep 30, 2013 11:17 pm
Forum: Volume 114 (11400-11499)
Topic: 11475 - Extend to Palindrome
Replies: 32
Views: 13896

Re: 11475 - Extend to Palindromes

Here's my complete code, it's basically what I posted before. Thanks in advance. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #define MAX 100005 using namespace std; main(){ char s[MAX], aux[MAX]; int len, index, i, j; while(scanf("%s",s) != EOF){ len = strlen(s); int ...
by alexiago
Sat Sep 28, 2013 3:23 am
Forum: Volume 114 (11400-11499)
Topic: 11475 - Extend to Palindrome
Replies: 32
Views: 13896

Re: 11475 - Extend to Palindromes

I tried to solve this problem using this heuristic: an index i is at the start of the string and another index j is at the end, the string s is stored in an aux array, index i keeps incrementing until it's smaller than j, and j decrements when s == s[j]. The idea behind this approach is that the sta...
by alexiago
Wed Sep 04, 2013 11:37 pm
Forum: Volume 124 (12400-12499)
Topic: 12442 - Forwarding Emails
Replies: 31
Views: 14025

Re: 12442 - Forwarding Emails

My solution was accepted using this algorithm: Find cycles using DFS and store the cycle length for every node on the cycle, for the graph below their distances would be {3, 3, 3} 1 2 2 3 3 1 If a larger path starts before a cycle, the starting distance should be reversed and include the cycle lengt...
by alexiago
Sat Aug 17, 2013 12:44 am
Forum: Volume 124 (12400-12499)
Topic: 12442 - Forwarding Emails
Replies: 31
Views: 14025

Re: 12442 - Forwarding Emails

I tried to solve this problem using DFS, starting a new iteration at each vertex and counting the max distance, I thought it would be enough as it completes within 1 sec on my laptop but I'm getting TLE. I tried another approach, starting at a vertex that hasn't been calculated its distance, I visit...
by alexiago
Wed Aug 14, 2013 7:05 pm
Forum: Volume 110 (11000-11099)
Topic: 11080 - Place the Guards
Replies: 40
Views: 11362

Re: 11080 : algorithm

One more tip, the input may not contain edges for all vertexes, so vertexes with grade = 0 should be counted to the answer.
by alexiago
Wed Aug 14, 2013 5:43 pm
Forum: Volume 9 (900-999)
Topic: 929 - Number Maze
Replies: 92
Views: 40209

Re: 929 - Number Maze

I guess nobody else will pass this problem again due to the Submission Error
by alexiago
Fri Aug 09, 2013 12:25 am
Forum: Volume 1 (100-199)
Topic: 193 - Graph Coloring
Replies: 93
Views: 21243

Re: 193 Graph Coloring

I first tried to solve this problem based on DFS, trying all initial possibilities as black, visiting all nodes and verifying if any neighbour was black before painting. But this approach was not covering all possibilities, for example, we can have a scenario where two white nodes in a row could lea...
by alexiago
Thu Aug 01, 2013 10:38 pm
Forum: Volume 109 (10900-10999)
Topic: 10948 - The primary problem
Replies: 27
Views: 18063

Re: 10948 - The primary problem

I solved this problem by creating an array and a SET with all primes up to 1 million. I looped thru the array getting the difference between the number N that we are looking for and the prime (i.e. N - primes), if we have that difference in the SET we found our sum and print it.
by alexiago
Fri Jul 15, 2011 1:30 am
Forum: Volume 2 (200-299)
Topic: 200 - Rare Order
Replies: 25
Views: 12752

Re: 200 - Rare Order

I'm getting Runtime error with my code below. I'm not sure if I should increase any array but I believe their sizes are enough for this problem. Any ideas? Thanks in advance. My algorithm: 1) For all rows for the same column I'm looking for undiscovered characters and store them in the ans array - t...
by alexiago
Thu Jan 24, 2008 6:57 pm
Forum: Volume 2 (200-299)
Topic: 240 - Variable Radix Huffman Encoding
Replies: 6
Views: 5687

240 Variable Radix Huffman Encoding

the priority queue in this problem has a little trick, if there's a tie between a letter node and a "combination letter" (this node is the sum between two other nodes) then the "combination letter" node wins. if there's a tie between two combination letters then the first added node wins. try the I/...

Go to advanced search